Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 试图找到/理解Harris Corners的正确实现_Matlab_Image Processing_Computer Vision - Fatal编程技术网

Matlab 试图找到/理解Harris Corners的正确实现

Matlab 试图找到/理解Harris Corners的正确实现,matlab,image-processing,computer-vision,Matlab,Image Processing,Computer Vision,我试图理解如何计算哈里斯角m,如中所定义 似乎需要对一系列补丁进行求和 但是,我看到很多实现都是这样做的: R = (Ix2.*Iy2 - Ixy.^2) - k*(Ix2 + Iy2).^2; 发件人: 没有求和,你永远不会看到补丁 这些对我来说不一样。例如,像素5,5的“R”值仅为该像素的Ix2、Iy2和Ixy值的平方。然而,数学似乎建议你在一个补丁上求和,比如说,像素5,5。哪个实现是正确的?二者都它们相等吗 注:Ix2=图像I在x方向上的平方梯度 Iy2除y方向外,其他方向相同

我试图理解如何计算哈里斯角m,如中所定义

似乎需要对一系列补丁进行求和

但是,我看到很多实现都是这样做的:

  R = (Ix2.*Iy2 - Ixy.^2) - k*(Ix2 + Iy2).^2; 
发件人:

没有求和,你永远不会看到补丁

这些对我来说不一样。例如,像素5,5的“R”值仅为该像素的Ix2、Iy2和Ixy值的平方。然而,数学似乎建议你在一个补丁上求和,比如说,像素5,5。哪个实现是正确的?二者都它们相等吗

注:Ix2=图像I在x方向上的平方梯度 Iy2除y方向外,其他方向相同 Ixy=Ix.*Iy


另外,.*或.^是表示逐点乘法或幂运算的matlab符号

对于自包容,哈里斯角点的计算基于相关矩阵的计算
M

对于图像中的每个像素,您希望收集一个通过高斯权重加权的
nxn
像素窗口,并通过以下方式计算图像中
(x,y)
位置处的响应值
R

超过阈值的
R
值被视为兴趣点
Ix
Iy
分别是水平和垂直导数。现在,你关心的代码我将把它放在这篇文章中进行自我约束。顺便说一句,这应该归功于谁编写了你文章中链接的原始函数:

% HARRIS - Harris corner detector
%
% Usage:  [cim, r, c] = harris(im, sigma, thresh, radius, disp)
%
% Arguments:   
%            im     - image to be processed.
%            sigma  - standard deviation of smoothing Gaussian. Typical
%                     values to use might be 1-3.
%            thresh - threshold (optional). Try a value ~1000.
%            radius - radius of region considered in non-maximal
%                     suppression (optional). Typical values to use might
%                     be 1-3.
%            disp   - optional flag (0 or 1) indicating whether you want
%                     to display corners overlayed on the original
%                     image. This can be useful for parameter tuning.
%
% Returns:
%            cim    - binary image marking corners.
%            r      - row coordinates of corner points.
%            c      - column coordinates of corner points.
%
% If thresh and radius are omitted from the argument list 'cim' is returned
% as a raw corner strength image and r and c are returned empty.

% Reference: 
% C.G. Harris and M.J. Stephens. "A combined corner and edge detector", 
% Proceedings Fourth Alvey Vision Conference, Manchester.
% pp 147-151, 1988.
%
% Author: 
% Peter Kovesi   
% Department of Computer Science & Software Engineering
% The University of Western Australia
% pk@cs.uwa.edu.au  www.cs.uwa.edu.au/~pk
%
% March 2002

function [cim, r, c] = harris(im, sigma, thresh, radius, disp)

error(nargchk(2,5,nargin));

dx = [-1 0 1; -1 0 1; -1 0 1]; % Derivative masks
dy = dx'; %'

Ix = conv2(im, dx, 'same');    % Image derivatives
Iy = conv2(im, dy, 'same');    

% Generate Gaussian filter of size 6*sigma (+/- 3sigma) and of
% minimum size 1x1.
g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);

Ix2 = conv2(Ix.^2, g, 'same'); % Smoothed squared image derivatives
Iy2 = conv2(Iy.^2, g, 'same');
Ixy = conv2(Ix.*Iy, g, 'same');

cim = (Ix2.*Iy2 - Ixy.^2)./(Ix2 + Iy2 + eps); % Harris corner measure

% Alternate Harris corner measure used by some.  Suggested that
% k=0.04 - I find this a bit arbitrary and unsatisfactory.
%   cim = (Ix2.*Iy2 - Ixy.^2) - k*(Ix2 + Iy2).^2; 

if nargin > 2   % We should perform nonmaximal suppression and threshold

% Extract local maxima by performing a grey scale morphological
% dilation and then finding points in the corner strength image that
% match the dilated image and are also greater than the threshold.
sze = 2*radius+1;                   % Size of mask.
mx = ordfilt2(cim,sze^2,ones(sze)); % Grey-scale dilate.
cim = (cim==mx)&(cim>thresh);       % Find maxima.

[r,c] = find(cim);                  % Find row,col coords.

if nargin==5 & disp      % overlay corners on original image
    figure, imagesc(im), axis image, colormap(gray), hold on
    plot(c,r,'ys'), title('corners detected');
end

else  % leave cim as a corner strength image and make r and c empty.
r = []; c = [];
end

cim
是为图像中的每个像素位置
(x,y)
计算的相关矩阵,或
M(x,y)
。我知道你的困惑源在哪里。在此代码中,计算
M(x,y)
的窗口被假定为1 x 1。在您引用我的链接中,对于代码中的每个点,窗口实际上是5 x 5。如果您想扩展此功能,以便相关矩阵包含5 x 5像素,则会想到类似的内容:

%//.........

%// From before - Need to modify to accommodate for window size
% Generate Gaussian filter of size 5 x 5 with sigma value
g = fspecial('gaussian', 5, sigma);

Ix2 = conv2(Ix.^2, g, 'same'); % Smoothed squared image derivatives
Iy2 = conv2(Iy.^2, g, 'same');
Ixy = conv2(Ix.*Iy, g, 'same');

%// New - add this before the computation of cim
kernel = ones(5,5); 
Ix2 = conv2(Ix2, kernel, 'same'); % To incorporate 5 x 5 patches
Iy2 = conv2(Iy2, kernel, 'same');
Ixy = conv2(Ixy, kernel, 'same');

%// Continue with original code....
cim = (Ix2.*Iy2 - Ixy.^2)./(Ix2 + Iy2 + eps); % Harris corner measure

%//.....
在输入和
内核
之间执行卷积,这是局部补丁和内核的加权和。在这种情况下,我们需要对
Ix2
Iy2
Ixy
进行求和,以遵守
M
中的符号。如果我们将内核指定为5x5窗口中的所有1,这实际上是将所有值相加,并为图像中的每个位置输出该总和。现在,在链接中它说内核是高斯的。文件中说,你可以用高斯函数对图像进行预过滤,然后累积窗口,代码目前正在这样做。但是,您需要确保高斯分布的窗口大小与文档中所述的相同,因此我们也将其更改为5 x 5

现在,您可以正常计算
cim
或相关矩阵
M(x,y)
,该矩阵现在应包含
Ix2
Iy2
Ixy
的5 x 5窗口的像素总和,只需使用元素操作即可。更改代码后,
Ix2
Iy2
Ixy
的每个元素计算5 x 5窗口内导数值的总和,其中每个变量中的每个像素标记该位置作为中心的总和。在这一点之后,一旦您计算了
cim
,这将为
im
中的每个像素提供
M(x,y)

现在,代码的其余部分执行所谓的非最大抑制。这样可以确保删除可能是误报的角点。这意味着您需要查看图像修补程序,并确定此修补程序中的最大值是多少。如果此面片中的此最大值等于此面片的中心如果此最大值超过阈值,则保留此点。这正是这部分代码的作用:

sze = 2*radius+1;                   % Size of mask.
mx = ordfilt2(cim,sze^2,ones(sze)); % Grey-scale dilate.
cim = (cim==mx)&(cim>thresh);       % Find maxima.
是一个顺序统计过滤器,其中第一个输入是您想要的图像,第二个输入是您正在查找的顺序统计,第三个输入是您想要处理的像素邻域。这告诉我们,您需要最大顺序统计信息
sze^2
,它对应于
sze x sze=ones(sze)
邻域中包含的最大

代码的下一部分:

[r,c] = find(cim);                  % Find row,col coords.

if nargin==5 & disp      % overlay corners on original image
    figure, imagesc(im), axis image, colormap(gray), hold on
    plot(c,r,'ys'), title('corners detected');
end
。。。查找通过非最大抑制的点的精确行和列坐标,并根据需要在图像上显示这些点


简而言之,这就是哈里斯角点检测的原因。。。希望有帮助

似乎建议您对补丁进行求和。哈里斯角上的所有其他笔记似乎都在暗示你要求和。我是不是误读了符号?相关矩阵?这是由ordfilt2处理的吗?
cim
是在您发送给我的URL中计算的相关矩阵或
R
矩阵
ordfilt2
用于帮助抑制非最大值。这种情况发生在何处:“收集相关矩阵中这些值的补丁”@lars-好的,我知道现在发生了什么。Kovesi的代码不考虑使用5×5的窗口。他只使用一个像素或1 x 1窗口。指定为函数输入的窗口用于非最大抑制。