MATLAB膨胀腐蚀(开-闭运算)源代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

clear,clc;h=imread('ceshi2.bmp');i=im2bw(h);i1i=187;i1j=192;forai=181:193foraj=186:198if(sqrt(double(ai-i1i)^2+double(aj-i1j)^2)=5)i(ai,aj)=1;%定义圆形结构元素endendendfigure,imshow(i);i1=i;fori1i=6:205%用B腐蚀Afori1j=6:205flag=0;if(i1i=181&&i1i=193&&i1j=186&&i1j=198)continue;elseif(i(i1i,i1j)==1)forai=i1i-5:i1i+5foraj=i1j-5:i1j+5if(i1(ai,aj)==0&&sqrt(double((ai-i1i)^2+(aj-i1j)^2))=5)i(i1i,i1j)=0;flag=1;break;endendif(flag==1)break;endendendendendendfigure,imshow(i);%在上面C的图像上用B进行膨胀i2=i;fori1i=6:205%用B膨胀Cfori1j=6:205flag=0;if(i1i=175&&i1i=199&&i1j=180&&i1j=204)continue;elseforai=i1i-5:i1i+5foraj=i1j-5:i1j+5if(i2(ai,aj)==1&&sqrt(double((ai-i1i)^2+(aj-i1j)^2))=5)i(i1i,i1j)=1;flag=1;break;endendif(flag==1)break;endendendendendfigure,imshow(i);%在上面D的图像上用B进行膨胀i2=i;fori1i=6:205%用B膨胀Dfori1j=6:205flag=0;if(i1i=175&&i1i=199&&i1j=180&&i1j=204)continue;elseforai=i1i-5:i1i+5foraj=i1j-5:i1j+5if(i2(ai,aj)==1&&sqrt(double((ai-i1i)^2+(aj-i1j)^2))=5)i(i1i,i1j)=1;flag=1;break;endendif(flag==1)break;endendendendendfigure,imshow(i);%在上面E的图像上用B进行腐蚀i1=i;fori1i=6:205%用B腐蚀Efori1j=6:205flag=0;if(i1i=181&&i1i=193&&i1j=186&&i1j=198)continue;elseif(i(i1i,i1j)==1)forai=i1i-5:i1i+5foraj=i1j-5:i1j+5if(i1(ai,aj)==0&&sqrt(double((ai-i1i)^2+(aj-i1j)^2))=5)i(i1i,i1j)=0;flag=1;break;endendif(flag==1)break;endendendendendendfigure,imshow(i);

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功