形态学图像处理

来源:互联网 发布:知乎等论坛 编辑:程序博客网 时间:2024/06/11 22:17

一、形态学图像处理知识框架



二、二值图像基本形态学运算

2.1 腐蚀

%% 图像放缩  imgErode.m%{函数: I1=imerode(I,se);          %图像腐蚀       se=strel(shape,parameters);%产生结构元素se函数说明:图像腐蚀参数说明: I:输入图像          se:由strel函数返回的自定义或预设的结构元素对象返回值:腐蚀后目标图像备注:strel函数中的shape参数,可以为‘square’(正方形)、‘rectangle’(矩形)等%}I=imread('erode_dilate.bmp');se=strel('square',3);%产生边长为3的正方形结构元素I1=imerode(I,se);   %腐蚀操作se=strel('square',6);%产生边长为6的正方形结构元素I2=imerode(I,se);   %腐蚀操作subplot(2,3,1);imshow(I);title('source');subplot(2,3,2);imshow(I1);title('erode_3');subplot(2,3,3);imshow(I2);title('erode_6');

运算结果:



2.2膨胀

%% 图像膨胀  imgdilate.m%{函数: I1=imdilate(I,se);          %图像腐蚀       se=strel(shape,parameters);%产生结构元素se函数说明:图像膨胀参数说明: I:输入图像          se:由strel函数返回的自定义或预设的结构元素对象返回值:膨胀后图像备注:strel函数中的shape参数,可以为‘square’(正方形)、‘rectangle’(矩形)等%}I=imread('starcraft.bmp');se=strel('square',3);%产生边长为3的正方形结构元素I1=imerode(I,se);   %腐蚀操作se=strel('square',6);%产生边长为6的正方形结构元素I2=imerode(I,se);   %腐蚀操作se=strel('square',3);%产生边长为6的正方形结构元素I3=imdilate(I,se);   %膨胀操作se=strel('square',6);%产生边长为6的正方形结构元素I4=imdilate(I,se);   %膨胀操作subplot(2,3,1);imshow(I);title('source');subplot(2,3,2);imshow(I1);title('erode_3');subplot(2,3,3);imshow(I2);title('erode_6');subplot(2,3,4);imshow(I3);title('dilate_3');subplot(2,3,5);imshow(I4);title('dilate_6');
运算结果:




2.3开及闭运算

%% 二值图像的开和闭运算  imgOpen_Close.m%{函数: I1=imopen(I,se);          %图像开运算(先腐蚀后膨胀)       I1=imclose(I,se);         %图像闭运算(先膨胀后腐蚀)函数说明:图像开和闭参数说明: I:输入图像          se:由strel函数返回的自定义或预设的结构元素对象返回值:运算后图像备注:strel函数中的shape参数,可以为‘square’(正方形)、‘rectangle’(矩形)等备注:开操作,和先用erode后用dilate效果是一样的%}I=imread('erode_dilate.bmp');se=strel('square',6);%产生边长为3的正方形结构元素I1=imopen(I,se);   %开操作I2=imclose(I,se);   %闭操作subplot(2,3,1);imshow(I);title('source');subplot(2,3,2);imshow(I1);title('open');subplot(2,3,3);imshow(I2);title('close');

运算结果:



原创粉丝点击