资源简介

基于形态学的matlab边缘检测小程序,亲测可用,大家放心下载吧!

资源截图

代码片段和文件信息

blood = imread(‘lenna.BMP‘);
[xy]=size(blood);                % 求出图象大小
b=double(blood);                  
N =sqrt(100) * randn(xy);        %  生成方差为10的白噪声
I=b;%+N;                            %  噪声干扰图象

for i=1:x                         % 实际图象的灰度为0~255
    for j=1:y
        if (I(ij)>255)
            I(ij)=255;
        end
        if (I(ij)<0)
            I(ij)=0;
        end
    end
end    


z0=max(max(I));                   % 求出图象中最大的灰度
z1=min(min(I));                   % 最小的灰度 

T=(z0+z1)/2;                      
TT=0;
S0=0; n0=0;
S1=0; n1=0;
allow=0.5;                       % 新旧阈值的允许接近程度
d=abs(T-TT);
count=0;                         % 记录几次循环

while(d>=allow)                 % 迭代最佳阈值分割算法
    count=count+1;
    for i=1:x
        for j=1:y
            if (I(ij)>=T)
                S0=S0+I(ij);
                n0=n0+1;
            end
            if (I(ij)                S1=S1+I(ij);
                n1=n1+1;
            end
        end
    end 
    T0=S0/n0;
    T1=S1/n1;
    TT=(T0+T1)/2;
    d=abs(T-TT);
    T=TT;
end

Seg=zeros(xy);
for i=1:x
    for j=1:y
        if(I(ij)>=T)
            Seg(ij)=1;               % 阈值分割的图象
        end
    end
end

SI=1-Seg;                            % 阈值分割后的图象求反,便于用腐蚀算法求边缘
se1=strel(‘square‘3);               % 定义腐蚀算法的结构
SI1=imerode(SIse1);                 % 腐蚀算法
BW=SI-SI1;                           % 边缘检测
%=====传统的边缘检测方法======%
I=uint8(I);
BW1=edge(I‘sobel‘ 0.11);
BW2=edge(I‘log‘ 0.015);
%===========图象显示==========%
figure(1);
imshow(I);title(‘Original‘)                         % 显示阈值分割的图象
figure(2);
imshow(BW2);title(‘Soble‘)                         % 显示新算法的边缘图象
figure(3)
imshow(BW1);title(‘Gauss-Laplace‘) 
figure(4)
imshow(BW);title(‘New algorithm‘) 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-05-09 03:40  edgeextraction\
     文件      254838  2005-05-17 15:26  edgeextraction\lenna.bmp
     文件        1963  2005-05-17 15:26  edgeextraction\P0701.m

评论

共有 条评论