Matlab自己实现Sobel边缘提取和ROA边缘提取

Sobel梯度强度图G


提取梯度强度本质是一种滤波,同高斯模糊滤波一样,只不过所用算子(kernel)不同,sobel梯度图所用的算子如下两个矩阵,分别同图像A做卷积,得到两个大小与A相同的二维浮点矩阵Gx、Gy:


求Gx和Gy两个矩阵的平方和根号,得到二维浮点矩阵:


浮点矩阵G就是图像A的梯度强度图,大小与A相同的。



Matlab实现Sobel边缘提取

%copyright by Institute of Electronic ,Chinese Academy of Sciences
%get the gradient edge of optical image by sobel method
function [ G ] = Sobel( Image )
Image=double(Image);
h=[-1 -2 -1;0 0 0;1 2 1];    
Gx=filter2(h,Image);           %Gx is the gradient of x axel  
Gy=filter2(h',Image);          %Gy is the gradient of y axel 
G=sqrt(Gx.^2+Gy.^2);           %amplitude of gradient
G=255*G./max(G(:));
G=uint8(G);                   %trans from double to uint8
figure;
imshow(G);
end


原图                                                                                                 


Sobel梯度强度图


2. ROA梯度强度图

     

       合成孔径雷达图像作为遥感图像,有强烈的斑点噪声,ROA可以通过取平均的方式来减少影响。提取SAR图像B所使用的梯度提取算子与上面不同,具有四个模板算子,如下图所示,所用算子为四个模板,, 分别是当前像素第k对的边侧区域像素的平均灰度值。


以水平方向模板为例,中心像素为B(i,j),、的值定义为:


根据以上式子分别计算四个模板的R值,并取其中最大值为最终R值,定义为:


        对每个像素做以上计算后,可以得到所有像素对应的R值,ROA梯度强度图的定义如下,大小与B相同。



Matlab实现ROA边缘提取
copyright by Institute of Electronic ,Chinese Academy of Sciences
%get the gradient edge of SAR image by ROA method
function [ G ] = ROA( Image )
Image=double(Image);
[m,n]=size(Image);
G=zeros(m,n);
for j=1:n-1
    for i=1:m-1  
        if i>=2 && i<=m-1 && j>=2 && j<=n-1
        %horizontal
        P1=mean(Image(i-1,j-1:j+1));
        Q1=mean(Image(i+1,j-1:j+1));
        R1=max(P1/Q1,Q1/P1);             %this step is extremly dangerous,since Q1 or P1 might be zero.
        %vertical
        P2=mean(Image(i-1:i+1,j-1));
        Q2=mean(Image(i-1:i+1,j+1));
        R2=max(P2/Q2,Q2/P2);
        %45 degree left div
        P3=mean([Image(i,j-1),Image(i+1,j-1),Image(i+1,j)]);
        Q3=mean([Image(i-1,j),Image(i-1,j+1),Image(i,j+1)]);
        R3=max(P3/Q3,Q3/P3);
        %135 degree right div
        P4=mean([Image(i-1,j-1),Image(i,j-1),Image(i-1,j)]);
        Q4=mean([Image(i+1,j+1),Image(i,j+1),Image(i+1,j)]);
        R4=max(P4/Q4,Q4/P4);
        % find the max R
        G(i,j)=max([R1,R2,R3,R4]); 
        
        %in case of the value of G(i,j) is inf
        if G(i,j)>=255
            G(i,j)=0;
        end;
        end;
    end;
end;
G=255*G./max(G(:));%the value of R vary around 1
G=uint8(G); 
figure;
imshow(G);
end

猜你喜欢

转载自blog.csdn.net/Z5337209/article/details/44202713