4

この論文で紹介されている一般化されたハフ変換をMATLAB で実装しようとしています。また、このドキュメントを使用してアルゴリズムを理解しようとしました。Rテーブルで使用するΦを見つけるために勾配角度を計算する方法を考え出すことに固執しています。

このmatlab 実装を実行しようとしましたが、輪郭関数は負のインデックスにアクセスしようとします。不足している機能は次のとおりです。

距離.m

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

barycenter.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

モデルHough.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
4

2 に答える 2

0

エッジ検出に一般的なエッジ検出器を使用する場合はcountor.m、行 14 を次のように変更する必要があります。

while (img(i,j)~=1)
于 2013-06-27T17:00:27.317 に答える