matlab练习程序(开操作)

  • Post author:
  • Post category:其他


cl;
img=imread('1.bmp');
[m n]=size(img);
imshow(img)
imgn=img;
temp=[];
%开操作
for i=2:m-1 %腐蚀
for j=2:n-1
temp=img(i-1:i+1,j-1:j+1);
imgn(i,j)=min(temp(:));
end
end

for i=2:m-1 %膨胀
for j=2:n-1
temp=img(i-1:i+1,j-1:j+1);
imgn(i,j)=max(temp(:));
end
end

figure,imshow(imgn);
img=double(img);
imgn=double(imgn);
imgn=img-imgn;
figure,imshow(mat2gray(imgn));

转载于:https://www.cnblogs.com/tiandsp/archive/2012/02/05/2339215.html