灰度转换.docx
- 文档编号:763849
- 上传时间:2023-04-30
- 格式:DOCX
- 页数:11
- 大小:914.43KB
灰度转换.docx
《灰度转换.docx》由会员分享,可在线阅读,更多相关《灰度转换.docx(11页珍藏版)》请在冰点文库上搜索。
灰度转换
ExperimentReport
CoursenameFundamentalsofMultimedia
ExperimentprojectGrayscaleimageconversion
Department_Mathematicsandcomputerdepartment_
Specialty___Computerscienceandtechnology
Class/ID_2011020741040_
NameDongdong_________
ExperimentalDate_November122013
Score_____________________
Instructor__Zhaoyanming______________
Experimentname:
Grayscaleimageconversion
一、Thepurposeoftheexperiment
1.Useimadjustandstretchlimcontrolfunctiontoachievegrayimage
2.WriteaMfunctionrealizationlogarithmstretchingimages
3.Histogramequalizationmethodofimagestretchingtransformation
4.Thehistogrammatchingmethod
二、TheExperimentalProcedure
1.Useimadjustandstretchlimcontrolfunctiontoachievegrayimage
functionimadjustisthebasicimageprocessingtoolboxfunctionforintensitytransformationsofgray-scaleimages.ithasthegeneralsyntax
G=imadjust(f,[low_inhigh_in],[low_outhigh_out],gamma)
LOW_IN,HIGH_IN,LOW_OUT,HIGH_OUTallmustbeintherange[0,1];
Theexperimentsareasfollows
Wealsousethefunctionimcomplement(f)toachieveintensitytransformationsofgray-scaleimages
2.WriteaMfunctionrealizationlogarithmstretchingimages
TheMfunctionislogpic.masfollow:
functionnewpic=logpic(oldpic)
if~isempty(size(oldpic,3))
oldpic=rgb2gray(oldpic);
end
subplot(121);
imshow(oldpic);
title('原始图片灰度图像');
oldpic=double(oldpic);
newpic=log(1+oldpic);
subplot(122);
imshow(newpic,[]);
title('对数变换后灰度图像')
Thetransformedimageasshownbelow
3.Histogramequalizationmethodofimagestretchingtransformation
Histogramequalizationstep:
ReadtheoriginalRGBimageandgrayimage
f=imread('3.jpg');f=rgb2gray(f);
f=mat2gray(f,[0255]);
[M,N]=size(f);
g=zeros(M,N);
②Originalgrayimagehistogram
r=imhist(f)/(M*N);%(500*500issizeofimage)
s=zeros(256,1);
③Originalgrayimageequalization
fork=1:
1:
256
forj=1:
1:
k
s(k,1)=s(k,1)+r(j);
end
end
forx=1:
1:
M%(500*500issizeofimage)
fory=1:
1:
N
g(x,y)=s(uint8(f(x,y)*255)+1,1);
end
end
④Showstheoriginalgrayscaleimage
figure();
subplot(2,2,1);
imshow(f);
xlabel('a).OriginalImage');
⑤Thehistogramshowstheoriginalgrayscaleimage
subplot(2,2,2);
h=imhist(f)/(M*N);
bar(0:
1/255:
1,h);
axis([0100.1]),grid;
%axissquare;
xlabel('b).TheHistogramofa');
ylabel('Numberofpixels');
⑥Imageoftheoriginalgrayscaleimageafterequalization
subplot(2,2,3);
imshow(g);
xlabel('c).HistogramEqualization');
⑦Theoriginalgrayimageafterhistogramequalization
subplot(2,2,4);
h=imhist(g)/(M*N);
bar(0:
1/255:
1,h);
axis([0100.1]),grid;
%axissquare;
xlabel('d).TheHistogramofc');
ylabel('Numberofpixels');
Showresults
4.Thehistogrammatchingmethod
Histogramequalizationproducesatransformationfunctionthatisadaptive,inthesensethatitisbasedonthehistogramofagivenimage.However,oncethetransformationfunctionforanimagehasbeencomputed,itdoesnotchangeunlessthehistogramoftheimagechange.
Histogrammatchingprocessontheoriginalgrayimagetransformasfollows
closeall;
clearall;
f=imread('3.jpg');
f=rgb2gray(f);
f=mat2gray(f);
[M,N]=size(f);
g=zeros(M,N);
r=imhist(f)/(M*N);
s=zeros(256,1);
fork=1:
1:
256
forj=1:
1:
k
s(k,1)=s(k,1)+r(j);
end
end
forx=1:
1:
M
fory=1:
1:
N
g(x,y)=s(uint8(f(x,y)*255)+1,1);
end
end
figure();
subplot(2,2,1);
imshow(f);
xlabel('a).OriginalImage');
subplot(2,2,2);
h=imhist(f)/(M*N);
bar(0:
1/255:
1,h);
axis([0100.1]),grid;
xlabel('b).TheHistogramofa');
subplot(2,2,3);
imshow(g);
xlabel('c).HistogramEqualization');
subplot(2,2,4);
h=imhist(g)/(M*N);
bar(0:
1/255:
1,h);
axis([0100.1]),grid;
xlabel('d).TheHistogramofc');
r=r';
p=[0:
r(1,1)/15:
r(1,1)17*r(1,2:
241)];
%p=[0:
r(1,1)/15:
r(1,1)r(1,2:
241)];
%p=[0:
55:
255,255:
-25:
24,24:
-0.14:
0,0:
1:
15,15:
-0.285:
0];
p=(p/sum(p));
p=p';
r=r';
G=zeros(256,1);
fork=1:
1:
256
forj=1:
1:
k
G(k,1)=G(k,1)+p(j);
end
end
G_Negatives=zeros(256,1);
Flag=0;
fork=1:
1:
256
forj=1:
1:
256
if(uint8(G(j,1)*255)==k)
G_Negatives(k,1)=(j-1)/255;
Flag=1;
end
end
if(Flag==0)
if(k==1)G_Negatives(k,1)=0;
elseG_Negatives(k,1)=G_Negatives(k-1,1);end
end
Flag=0;
end
z=zeros(M,N);
forx=1:
1:
M
fory=1:
1:
N
z(x,y)=G_Negatives(uint8(g(x,y)*255)+1,1);
end
end
figure();
subplot(2,2,1);
imshow(z);
xlabel('a).HistogramMatching');
subplot(2,2,2);
h=imhist(z)/(M*N);
bar(0:
1/255:
1,h);
axis([010.1]),grid;
xlabel('b).TheHistogramofa');
subplot(2,2,3);
x=0:
1/255:
1;
plot(x,p);
axis([0,1,0,.1]),grid;
xlabel('c).SpecifiedsHistogram(Normalized)');
subplot(2,2,4);
x=0:
1/255:
1;
plot(x,G,x,G_Negatives);
axis([0,1,0,1]),grid;
axissquare;
xlabel('Inputintensitylevel');
ylabel('Onputintensitylevel');
三、Experimentalsummary
Accordingtothehistogrammatchingresults,wecansee,theresultsandweexpectdistributionisveryclosetothe.Theresultisthesamewithouroriginalintention,theoriginalhistogramslightlyleftsome.Theobtainedresultsaremuchbetterthanhistogramequalization.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 灰度 转换