资源简介

该代码首先实现了图像的腐蚀处理和图像的膨胀处理。然后,经过先腐蚀(Erosion)处理,后膨胀(Dilation)处理得到了Opening Image;又经过先膨胀(Dilation)处理,后腐蚀(Erosion)处理得到了Closing Image。 程序执行后能够得到原始图像、膨胀后图像、腐蚀后图像、Opening Image和Closing Image这五幅图像的对比显示结果。

资源截图

代码片段和文件信息

%Function:Gray-Scale Morphological Operations

clc;clear all;close all;

%%%%%%%%%%%%%%%%%%%%%%%%
%%%  Input & Imread  %%%
%%%%%%%%%%%%%%%%%%%%%%%%
se=[111;111;111;111]; %Structuring Element
I0=imread(‘yourimage.jpg‘);
I=rgb2gray(I0);
imshow(I[]);title(‘Original Image‘);
I=double(I);
[im_heightim_width]=size(I);
[se_heightse_width]=size(se);
halfheight=floor(se_height/2);
halfwidth=floor(se_width/2);
[se_origin]=floor((size(se)+1)/2);
image_dilation=padarray(Ise_origin0‘both‘); %Image to be used for dilation
image_erosion=padarray(Ise_origin256‘both‘); %Image to be used for erosion

%%%%%%%%%%%%%%%%%%
%%%  Dilation  %%%
%%%%%%%%%%%%%%%%%%
for k=se_origin(1)+1:im_height+se_origin(1)
    for kk=se_origin(2)+1:im_width+se_origin(2)
        dilated_image(k-se_origin(1)kk-se_origin(2))=max(max(se+image_dilation(k-se_origin(1):k+halfheight-1kk-se_origin(2):kk+halfwidth-1)));
    end
end
figure;imshow(dilated_image[]);title(‘Image after Dilation‘);

%%%%%%%%%%%%%%%%%
%%%  Erosion  %%%
%%%%%%%%%%%%%%%%%
se=se‘;
for k=se_origin(2)+1:im_height+se_origin(2)
    for kk=se_origin(1)+1:im_width+se_origin(1)
        eroded_image(k-se_origin(2)kk-se_origin(1))=min(

评论

共有 条评论