%%%%%%%%%%%%%%%%% 1 2016.1.27 %%%%%%%%%%%%%%% 腐蚀 打印腐蚀模板形状 背景0黑色 % 可以单独在 command window 下查看SE* % 参看 help 中 strel I = input('input the picture path:\n'); figure(1); I = imread(I); imshow(I),title('原图RGB'); figure(2); % strel 的第一个参数 arbitrary 或者为空,则第二个参数是人为指定一个形状,矩阵表示,0黑色背景,1白色前景 HAHA = [0 0 0;1 1 1;0 0 0]; SE1 = strel('arbitrary',HAHA); Ierode = imerode(I,SE1); subplot(2,4,1),imshow(Ierode),title('arbitrary HAHA'); % Neighborhood: % 0 0 0 % 1 1 1 % 0 0 0 % 2 disk 半径为10的圆 SE2 = strel('disk',10); Ierode = imerode(I,SE2); subplot(2,4,2),imshow(Ierode),title('disk ,10'); % 3 square 边长是4的正方形 SE3 = strel('square',4); Ierode = imerode(I,SE3); subplot(2,4,3),imshow(Ierode),title('square,4'); % Neighborhood: % 1 1 1 1 % 1 1 1 1 % 1 1 1 1 % 1 1 1 1 % 4 rectangle M行3 N列4 SE4 = strel('rectangle',[3 4]); Ierode = imerode(I,SE4); subplot(2,4,4),imshow(Ierode),title('rectangle [3 4]'); % Neighborhood: % 1 1 1 1 % 1 1 1 1 % 1 1 1 1 % 5 line 线性元素 SE = strel('line',线的长度,以线的中点为中心逆时针转过的角度); 见注解 SE5 = strel('line',5,45); Ierode = imerode(I,SE5); subplot(2,4,5),imshow(Ierode),title('line,5,45'); % Neighborhood: % 0 0 1 % 0 1 0 % 1 0 0 % 6 pair 包含两个点的元素 SE6 = strel('pair',[1 2]); Ierode = imerode(I,SE6); subplot(2,4,6),imshow(Ierode),title('pair [1 2]'); % 0 0 0 0 0 % 0 0 1 0 0 % 0 0 0 0 1 % 7 diamond 菱形 一半对角线的长度为3 SE7 = strel('diamond',3); Ierode = imerode(I,SE7); subplot(2,4,7),imshow(Ierode),title('diamond 3'); % Neighborhood: % 0 0 0 1 0 0 0 % 0 0 1 1 1 0 0 % 0 1 1 1 1 1 0 % 1 1 1 1 1 1 1 % 0 1 1 1 1 1 0 % 0 0 1 1 1 0 0 % 0 0 0 1 0 0 0 % 8 octagon 八角形结构元素 中点到边的距离 SE8 = strel('octagon',3); Ierode = imerode(I,SE8); subplot(2,4,8),imshow(Ierode),title('octagon 3'); % Neighborhood: % 0 0 1 1 1 0 0 % 0 1 1 1 1 1 0 % 1 1 1 1 1 1 1 % 1 1 1 1 1 1 1 % 1 1 1 1 1 1 1 % 0 1 1 1 1 1 0 % 0 0 1 1 1 0 0
注解 SE5
SE5 = strel ( ' pair ' , 10 , 0) ;
SE5 = strel ( ' pair ' , 10 , 30) ;
SE5 = strel ( ' pair ' , 10 , 45) ;
SE5 = strel ( ' pair ' , 10 , 90) ;
SE5 = strel ( ' pair ' , 10 , 135) ;
出现的结果不一定都是10个1元素,这点需要特别注意。