使用梯度的圆形霍夫变换

时间:2013-01-06 18:20:58

标签: matlab image-processing hough-transform

我正在尝试使用霍夫变换算法来检测灰度图像中的圆。 我跑边检测器并在每个点使用渐变的方向,以获得半径所在的线。 然后,我试图为中心(cX,cY)和半径r的每个圆积累投票:

% run edge detection on image
Edges = edgeDetect(img);
% initialize accumulator matrix
Acc = zeros(imgRows, imgCols, maxR);    
% get indices of edge points
edgePoints = find(Edges);
% get number of edg points
numOfEdges = size(edgePoints);

for currEdge = 1 : numOfEdges

    % get edge cartesian coordinate
    [eY eX] = ind2sub([imgRows, imgCols], edgePoints(currEdge));        
    % find gradient's direction at this point
    theta = Directions(eY, eX);

    for r  = minR : maxR

        % find center point according to polar representation of circle
        cX = round( eX - r*cos(theta) );
        cY = round( eY - r*sin(theta) );

        % check if (cX,cY) is within image's boundaries
        if 1 <= cX && cX <= imgCols && 1 <= cY && cY <= imgRows

            % found a circle with (cX,cY) as center and r as radius
            Acc(cY, cX, r) = Acc(cY, cX, r) + 1; % increment matching counter

        end            
    end        
end

然而,累加器(Acc)中的最大值是10 - 所以我想我计算圆圈的方式有问题。我试过调试但是看不出问题出在哪里...... 什么想法可能是错的?任何帮助将不胜感激!

0 个答案:

没有答案