实例72:图像分析(1)
h0=figure('toolbar','none',...
'position',[198 56 350 468],...
'name','实例72');
h1=axes('parent',h0,...
'position',[0.25 0.45 0.5 0.5],...
'visible','off');
I=imread('rice.tif');
imshow(I)
k=0;
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','图像轮廓图',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 100 60 20],...
'callback',[...
'cla,',...
'k=1;,',...
'I=imread(''rice.tif'');,',...
'imcontour(I)']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','SOBEL边界图',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[100 100 60 20],...
'callback',[...
'cla,',...
'k=2;,',...
'I=imread(''rice.tif'');,',...
'BW=edge(I,''sobel'');,',...
'imshow(BW)']);
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'style','pushbutton',...
'string','CANNY边界图',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[180 100 60 20],...
'callback',[...
'cla,',...
'k=3;,',...
'I=imread(''rice.tif'');,',...
'BW=edge(I,''canny'');,',...
'imshow(BW)']);
b4=uicontrol('parent',h0,...
'units','points',...
'tag','b4',...
'style','pushbutton',...
'string','灰度调整',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 50 60 20],...
'callback',[...
'cla,',...
'k=4;,',...
'I=imread(''rice.tif'');,',...
'J=imadjust(I,[0.15 0.9],[0 1]);,',...
'imshow(J,64)']);
b5=uicontrol('parent',h0,...
'units','points',...
'tag','b5',...
'style','pushbutton',...
'string','图像柱状图',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[180 50 60 20],...
'callback',[...
'if k==0,',...
'figure,',...
'imhist(I,64),',...
'end,',...
'if k==1,',...
'imhist(I,64),',...
'end,',...
'if k==2,',...
'imhist(BW,64),',...
'end,',...
'if k==3,',...
'imhist(BW,64),',...
'end,',...
'if k==4,',...
'imhist(J),',...
'end']);
b6=uicontrol('parent',h0,...
'units','points',...
'tag','b6',...
'style','pushbutton',...
'string','关闭',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[100 50 60 20],...
'callback','close');
实例73:过滤图像
h0=figure('toolbar','none',...
'position',[198 56 350 468],...
'name','实例73');
h1=axes('parent',h0,...
'position',[0.25 0.45 0.5 0.5],...
'visible','off');
I=imread('eight.tif');
imshow(I)
u1=uimenu('parent',h0,...
'tag','u1',...
'label','添加噪声',...
'backgroundcolor',[0.75 0.75 0.75]);
u11=uimenu('parent',u1,...
'tag','u11',...
'label','SALT&PEPPER噪声',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'set(u11,''checked'',''on'');,',...
'set(u12,''checked'',''off'');,',...
'cla,',...
'I=imnoise(I,''salt & pepper'',0.02);,',...
'imshow(I)']);
u12=uimenu('parent',u1,...
'tag','u12',...
'label','GAUSSIAN噪声',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'set(u12,''checked'',''on'');,',...
'set(u11,''checked'',''off'');,',...
'cla,',...
'I=imnoise(I,''gaussian'',0,0.005);,',...
'imshow(I)']);
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','均平过滤',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[30 100 50 20],...
'callback',[...
'cla,',...
'J=filter2(fspecial(''average'',3),I)/255;,',...
'imshow(J)']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','中值过滤',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[100 100 50 20],...
'callback',[...
'cla,',...
'J=medfilt2(I,[3 3]);,',...
'imshow(J)']);
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'style','pushbutton',...
'string','自适应过滤',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[170 100 50 20],...
'callback',[...
'cla,',...
'J=wiener2(I,[5 5]);,',...
'imshow(J)']);
b4=uicontrol('parent',h0,...
'units','points',...
'tag','b4',...
'style','pushbutton',...
'string','关闭',...
'fontsize',15,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[90 50 70 30],...
'callback','close');
实例74:图像的区域处理
h0=figure('toolbar','none',...
'position',[198 56 350 468],...
'name','实例74');
h1=axes('parent',h0,...
'position',[0.25 0.45 0.5 0.5],...
'visible','off');
I=imread('trees.tif');
imshow(I)
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','区域过滤一',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[30 100 50 20],...
'callback',[...
'cla,',...
'I=imread(''trees.tif'');,',...
'imshow(I),',...
'BW=roipoly;,',...
'h=fspecial(''unsharp'');,',...
'I2=roifilt2(h,I,BW);,',...
'imshow(I2)']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','区域过滤二',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[100 100 50 20],...
'callback',[...
'cla,',...
'BW=imread(''text.tif'');,',...
'f=inline(''imadjust(x,[],[],0.01)'');,',...
'I2=roifilt2(I,BW,f);,',...
'imshow(I2)']);
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'style','pushbutton',...
'string','区域填充',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[170 100 50 20],...
'callback',[...
'cla,',...
'load trees,',...
'I=ind2gray(X,map);,',...
'imshow(I),',...
'I2=roifill;,',...
'imshow(I2)']);
b4=uicontrol('parent',h0,...
'units','points',...
'tag','b4',...
'style','pushbutton',...
'string','关闭',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[90 50 70 30],...
'callback','close');
实例75:图像的颜色处置
h0=figure('toolbar','none',...
'position',[198 56 350 468],...
'name','实例75');
h1=axes('parent',h0,...
'position',[0.12 0.45 0.75 0.5],...
'visible','off');
I=imread('flowers.tif');
imshow(I)
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','减少颜色',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[30 100 50 20],...
'callback',[...
'cla,',...
'[X,map]=imread(''flowers.tif'');,',...
'[Y,map2]=imapprox(X,map,64);,',...
'image(Y),',...
'colormap(map2)']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','颜色抖动',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[100 100 50 20],...
'callback',[...
'cla,',...
'I=imread(''flowers.tif'');,',...
'[X,map]=rgb2ind(I,128,''nodither'');,',...
'imshow(X)']);
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'style','pushbutton',...
'string','颜色转换一',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[170 100 50 20],...
'callback',[...
'cla,',...
'I=imread(''flowers.tif'');,',...
'Y=rgb2ntsc(I);,',...
'J=Y(:,:,1);,',...
'imshow(J)'])
评论0