Преобразование Хафа в MATLAB без использования функции Хафа

Я нашел реализацию преобразования Хафа в MATLAB в Rosetta Code, но у меня возникли проблемы с ее пониманием. Также я хотел бы изменить его, чтобы показать исходное изображение и реконструированные линии (de-Houghing).

Приветствуется любая помощь в понимании этого и де-Хафинга. Спасибо

  1. Почему изображение перевернуто?

    theImage = flipud(theImage);

  2. Я никак не могу понять функцию нормы.Какова его цель и можно ли его избежать?

РЕДАКТИРОВАТЬ: норма — это просто синоним евклидова расстояния: sqrt (ширина ^ 2 + высота ^ 2)

rhoLimit = норма ([ширина высота]);

  1. Кто-нибудь может объяснить, как и почему вычисляются rho, theta и houghSpace?

    ро = (-ролимит:1:ролимит);
    тета = (0: thetaSampleFrequency: пи);
    numThetas = число (тета);
    houghSpace = нули (numel (rho), numThetas);
    
  2. Как бы я расшифровал пространство Хафа, чтобы воссоздать линии?

Вызов функции с помощью изображения диагональной линии размером 10x10, созданного с помощью функции тождества (глаза)

theImage = eye(10)
thetaSampleFrequency = 0.1
[rho,theta,houghSpace] = houghTransform(theImage,thetaSampleFrequency)

Фактическая функция

function [rho,theta,houghSpace] = houghTransform(theImage,thetaSampleFrequency)

    %Define the hough space
    theImage = flipud(theImage);
    [width,height] = size(theImage);

    rhoLimit = norm([width height]);
    rho = (-rhoLimit:1:rhoLimit);          
    theta = (0:thetaSampleFrequency:pi);

    numThetas = numel(theta);
    houghSpace = zeros(numel(rho),numThetas);

    %Find the "edge" pixels
    [xIndicies,yIndicies] = find(theImage);

    %Preallocate space for the accumulator array
    numEdgePixels = numel(xIndicies);
    accumulator = zeros(numEdgePixels,numThetas);

    %Preallocate cosine and sine calculations to increase speed. In
    %addition to precallculating sine and cosine we are also multiplying
    %them by the proper pixel weights such that the rows will be indexed by 
    %the pixel number and the columns will be indexed by the thetas.
    %Example: cosine(3,:) is 2*cosine(0 to pi)
    %         cosine(:,1) is (0 to width of image)*cosine(0)
    cosine = (0:width-1)'*cos(theta); %Matrix Outerproduct  
    sine = (0:height-1)'*sin(theta); %Matrix Outerproduct

    accumulator((1:numEdgePixels),:) = cosine(xIndicies,:) + sine(yIndicies,:);

    %Scan over the thetas and bin the rhos 
    for i = (1:numThetas)
        houghSpace(:,i) = hist(accumulator(:,i),rho);
    end

    pcolor(theta,rho,houghSpace);
    shading flat;
    title('Hough Transform');
    xlabel('Theta (radians)');
    ylabel('Rho (pixels)');
    colormap('gray');

end

5
задан waspinator 29 March 2012 в 02:42
поделиться