自定义霍夫变换功能

时间:2012-11-30 20:06:11

标签: matlab image-processing octave hough-transform

我正在MATLAB中实现自定义hough变换,这是我目前的代码:

 function [ H ] = HoughTransform(M)
    %M is a boolean matrix containg 1's where there is an edge 0 otherwise

        ThetaFreq=20;           
        M=rot90(M,2); %So that our origin is at the bottom left of the image

        [height,width]=size(M);
        pMax = sqrt(width^2+height^2);   
        theta = (0:1/ThetaFreq:pi);

        Thetas = numel(theta);
        H = zeros(round(2*pMax+1),Thetas);

        [x,y] = find(M); % The co-ordinates of all non-zero points in M

    for i=1:length(x)
            p=x(i)*cos(theta)+y(i)*sin(theta);

            p=round(p+pMax+1) %To center it at the vertical center of H

            for j=1:length(p)

                H(p,j)=H(p,j)+1;
            end
    end

图像H在执行此代码后包含(几乎)直线水平线,而不是它应该的美丽正弦曲线,因为任何给定i的向量p中的值彼此非常接近。 我做错了吗?

0 个答案:

没有答案