欢迎来到天天文库
浏览记录
ID:51845349
大小:28.50 KB
页数:4页
时间:2020-03-16
《数字图像处理腐蚀与膨胀小程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、%%%%%%%%%%%%%%%%下面为用于处理的样本‘圆’%%%%%%%%%%%%%%%%%%%%%%%%%R=8;%%半径RS=zeros(2*R);forx1=-R:R-1;fory1=-R:R-1;ifround(sqrt(x1^2+y1^2))<=R%%圆心在原点的圆的表达函数%%对圆心在原点的圆进行平移,使x,y都为非负数x=R+x1+1;y=R+y1+1;S(x,y)=1;endendendfigure(1),imshow(S);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2、%%%%%%%%%%%%%%%%%%%%%下面为要处理的图形%%%%%%%%%%%%%%%%%%%%%%%%%W=256;L=512;%%定义边界X=zeros(W,L);fori=1:128forj=1:256ifi<=15
3、i>=114ifj<103
4、j>153X(i+W/4,j+L/4)=1;endelseif(i>15&i<=56)
5、(i>=72&i<114)if(j>50&j<103)
6、j>153X(i+W/4,j+L/4)=1;endelseifi>56&i<72ifj>50&j<206X(i+W/4,j+L/4)=1;endendendendendendfig
7、ure(2),imshow(X);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%下面用S对X进行腐蚀操作%%%%%%%%%%%%%%%%%%%%%%%%X1=zeros(W,L);%X1用于存放处理后的图像M=zeros(2*R);form=0:W-2*Rforn=0:L-2*R%%下面用S对X区域进行‘与’操作%%fori=1:2*Rforj=1:2*RM(i,j)=X(i+m,j+n)&S(i,j);endendifM==S%%判断S是否处于X
8、中,等则在S中X1(m+R,n+R)=1;endM=zeros(2*R);endendfigure(3),imshow(X1);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%下面用S对X1进行膨胀操作%%%%%%%%%%%%%%%%%%%%%%%%%%X2=zeros(W,L);%X2用于存放处理后的图像cnt=0;form=0:W-2*Rforn=0:L-2*R%%下面用S对X区域进行‘与’操作%%fori=1:2*Rforj=1:2*RifX1(i+m,
9、j+n)&S(i,j)==1%%判断S是否与X相交cnt=1;break;endendifcnt==1%%判断是否是由于cnt=1而跳出循环break;endendifcnt==1%%判断是否是由于cnt=1而跳出循环X2(m+R,n+R)=1;cnt=0;%%将cnt的值置0endendendfigure(4),imshow(X2);(S)(X)(X1)(X2)
此文档下载收益归作者所有