【问题标题】:Generalized Hough R-Table广义霍夫 R 表
【发布时间】:2012-04-16 14:34:51
【问题描述】:

我正在尝试在 MATLAB 中实现 this paper 中提出的广义霍夫变换。我也尝试使用this document 来理解算法。我一直在弄清楚如何计算梯度角以找到要在 R-Table 中使用的 Φ。

我试图运行这个matlab implementation,但轮廓函数试图访问负索引。缺少的功能如下。

距离.m

function [ d ] = distance( x1, y1, x2, y2 )
  d = sqrt( (x2-x1)^2 + (y2-y1)^2 );   
end

重心.m

function [ xo, yo ] = barycenter( img )
%   gravitational center coordinates of a shape 

  [rows, cols] = size(img);
  x = ones(rows, 1)*(1:cols);
  y = (1:rows)'*ones(1,cols);
  area = sum(sum(img));
  xo = sum(sum(double(img) .* x)) / area;
  yo = sum(sum(double(img) .* y)) / area;

end

modelHough.m

function [H]=ModelHough(imgRGB)
% Generalized Hough Transform Modeling

% Image Binarization
imgBW = rgb2gray(imgRGB);
imgBI = imgBW < 255;

% Retrieving information about the contour: points and number (N)
N = contour(imgBI);

% Model initialization:
    % row = beta value * 100
    % column = number of the couple (alpha, distance)
    % 3rd dimension: 1 = alpha, 2 = distance
H=zeros(round(100*2*pi),N,2);

% Compute of the barycenter coordinates
[ xo, yo ] = barycenter(imgBI);

% for each contour point
for i=1:N

    % beta compute for ith contour point
    b = beta(N, imgBI, i);

    % research of the first column
    k=1;
    while H(b+1,k,2)~=0
       k=k+1;
    end

    % compute of the alpha value
    H(b+1, k, 1) = alpha(N, i, imgBI);

    % compute of the distance value
    H(b+1, k, 2) = distance( xo, yo, i, b );

end

【问题讨论】:

    标签: matlab hough-transform


    【解决方案1】:

    使用合适的边缘检测器。您可以从Sobel operator 开始。梯度角度为 atan(Gy/Gx),如 wiki 文章中所述。

    【讨论】:

      【解决方案2】:

      如果您使用通用边缘检测器来检测边缘,您应该将第 14 行的 countor.m 更改为如下所示:

      while (img(i,j)~=1)
      

      【讨论】:

        猜你喜欢
        • 2018-01-15
        • 2013-03-28
        • 1970-01-01
        • 1970-01-01
        • 2014-10-29
        • 1970-01-01
        • 2012-07-20
        • 2023-03-23
        • 1970-01-01
        相关资源
        最近更新 更多