dilateerode.m
来自「是一本教科书的各个章节的源程序代码,适合初学数字图像的人」· M 代码 · 共 54 行
M
54 行
%读取原始灰度图像
BW0 = imread('brain.bmp');
figure(1)
imshow(BW0); %如图7-29所示
%变为二值图像
BW1 = im2bw(BW0,0.8);
figure(2)
imshow(BW1); %如图7-30所示
%确定两种结构元素
se1=[0 1 1 1; 1 0 1 1; 1 1 0 1; 1 1 1 0];
se2=ones(3);
%按结构元素se1进行膨胀操作
BW2 = dilate(BW1,se1);
figure(3)
imshow(BW2); %如图7-31所示
%按结构元素se2进行膨胀操作
BW3 = dilate(BW1,se2);
figure(4)
imshow(BW3); %如图7-32所示
%按结构元素se1进行腐蚀操作
BW4 = erode(BW1,se1);
figure(5)
imshow(BW4); %如图7-33所示
%按结构元素se2进行腐蚀操作
BW5 = erode(BW1,se2);
figure(6)
imshow(BW5); %如图7-34所示
%按结构元素se1对原图像进行闭操作
BW6 = erode(BW2,se1);
figure(7)
imshow(BW6); %如图7-35所示
%按结构元素se1对原图像进行开操作
BW7 = dilate(BW5,se1);
figure(8)
imshow(BW7); %如图7-36所示
%按结构元素se1对原图像进行闭-开操作
BW8 = dilate(erode(BW6,se1),se1);
figure(9)
imshow(BW8); %如图7-37所示
%按结构元素se1对原图像进行开-闭操作
BW9 = erode(dilate(BW7,se1),se1);
figure(10)
imshow(BW9); %如图7-38所示
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?