clc;
close all;
A1=imread('noise.png');
%膨胀的结构元素
B=[0 1 0
1 1 1
0 1 0];
subplot(4,5,1);
imshow(A1);
A2=imdilate(A1,B);%图像A1被结构元素B膨胀
subplot(4,5,2);
imshow(A2);
A3=imdilate(A2,B);
subplot(4,5,3);
imshow(A3);
A4=imdilate(A3,B);
subplot(4,5,4);
imshow(A4);
A5=imdilate(A4,B);
subplot(4,5,5);
imshow(A5);
A6=imdilate(A5,B);
subplot(4,5,6);
imshow(A6);
A7=imdilate(A6,B);
subplot(4,5,7);
imshow(A7);
A8=imdilate(A7,B);
subplot(4,5,8);
imshow(A8);
%腐蚀的结构元素
C=[ 0 1 0
1 1 1
0 1 0];
A9=imerode(A8,C); %腐蚀
subplot(4,5,9);
imshow(A9);
A10=imerode(A9,C);
subplot(4,5,10);
imshow(A10);
A11=imerode(A10,C);
subplot(4,5,11);
imshow(A11);
A12=imerode(A11,C);
subplot(4,5,12);
imshow(A12);
A13=imerode(A12,C);
subplot(4,5,13);
imshow(A13);
A14=imerode(A13,C);
subplot(4,5,14);
imshow(A14);
A15=imerode(A14,C);
subplot(4,5,15);
imshow(A15);
A16=imerode(A15,C);
subplot(4,5,16);
imshow(A16);
A17=imerode(A16,C);
subplot(4,5,17);
imshow(A17);
A18=imerode(A17,C);
subplot(4,5,18);
imshow(A18);
A19=imerode(A18,C);
subplot(4,5,19);
imshow(A19);
A20=imerode(A19,C);
subplot(4,5,20);
imshow(A20);