对创建的二值图像进行膨胀处理(matlab编程实现)

来源:互联网 发布:人工智能简史 pdf 编辑:程序博客网 时间:2024/05/22 10:57

膨胀会增长或粗化二值图像中的物体,下面是一个用matlab编程实现二值化的例子

clear all;close all;

imagein=zeros(10,10);
imagein(5:6,5:6)=1;
[m,n]=size(imagein);
imageout=zeros(m,n);
for i=2:m-1
    for j=2:n-1
        t=sum(sum(imagein(i-1:i+1,j-1:j+1)));
       if t>0
         imageout(i,j)=1;
       else
         imageout(i,j)=0;
       end
    end
end
figure;
subplot(121);imshow(imagein);
subplot(122);imshow(imageout);