【问题标题】:Harris Corner Detection哈里斯角检测
【发布时间】:2017-03-29 22:54:28
【问题描述】:

我正在做一个使用 Harris 方法检测角点的程序。该方法的输出显示了角点。我想要做的是将阈值应用于图像。这是我的代码:

 % Create a mask for deteting the vertical edges 
 verticalMask = [-1 0 1;
            -2 0 2;
            -1 0 1]* 0.25;

% Create a mask for deteting the horizontal edges 
horisontalMask = [-1 -2 -1;
              0 0 0;
              1 2 1]* 0.25;

% Create a mask for Gaussian filter(is used to improve the result)

gaussianFilter= [1 4 1;
             4 7 4;
             1 4 1].*(1/27);


K = 0.04; % The sensitivity factor used in the Harris detection algorithm (Used to detect
            sharp corners).



% Get the gradient of the image [Ix,Iy], using the convulation function
Ix = conv2(grayImage,verticalMask);
Iy = conv2(grayImage,horisontalMask);


% get the input arguments of the harris formula

Ix2 = Ix.* Ix; % get Ix to the power of two
Iy2 = Iy.* Iy; % get Iy to the power of two
Ixy = Ix .* Iy; %get the Ixy by multiply Ix and Iy

% Apply the gaussian filter to the the arguments
Ix2 = conv2(Ix2,gaussianFilter);
Iy2 = conv2(Iy2,gaussianFilter);
Ixy = conv2(Ixy,gaussianFilter);

% Enetr the arguments into the formula
C = (Ix2 .* Iy2) - (Ixy.^2) - K * ( Ix2 + Iy2 ).^ 2;

现在,我想将阈值应用于公式的输出 C。 我找到了一个我试过的代码,它工作得很好,但如果有人能解释一下,我想先理解它。(对于 thresh 和 radius 变量,我更改了它们的值,以便它可以与我的图像一起使用)。

thresh = 0.000999;
radius = 1;
sze = 2*radius + 1;                   % Size of dilation mask
mx = ordfilt2(cim, sze^2, ones(sze));      % Grey-scale dilate

% Make mask to exclude points on borders
bordermask = zeros(size(cim));
bordermask(radius+1:end-radius, radius+1:end-radius) = 1;

% Find maxima, threshold, and apply bordermask
cimmx = (cim==mx) & (cim>thresh) & bordermask;
[r, c] = find(cimmx);     % Return coordinates of corners

figure, imshow(im),
hold on;
plot(c, r, '+');
hold off;

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    首先,图像cim 的每个像素都被替换为其最大邻居的值。 邻居罩定义为大小为sze 的正方形。这会扩大图像,即明亮的图像区域变得更厚。见matlab doc

     mx = ordfilt2(cim, sze^2, ones(sze));      % Grey-scale dilate
    

    cim==mx 表示您只接受原始图像和拨号图像中相同的像素。这仅包括大小为sze 的邻域中最大的像素。

    cim>thresh 表示您只考虑值大于thresh 的像素。因此,所有较暗的像素都不能是边缘。

    边框蒙版确保您只接受距离图像边框大于radius 的像素。

    [r, c] = find(cimmx) 为您提供角像素的行和列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-16
      • 2014-12-14
      • 2016-12-20
      • 2020-04-15
      • 2020-10-15
      • 2011-09-08
      • 1970-01-01
      • 2020-10-14
      相关资源
      最近更新 更多