我發現了霍夫變換在MATLAB中的實現Rosetta Code,但我無法理解它。另外我想修改它以顯示原始圖像和重建線(去Houghing)。霍夫變換在MATLAB中不使用霍夫函數
任何幫助理解它和de-Houghing是讚賞。謝謝
爲什麼圖像翻轉?
theImage = flipud(theImage);
我不能換我的頭周圍的規範功能。它的目的是什麼,可以避免嗎?
編輯:規範僅僅是歐幾里得距離的同義詞:SQRT(寬度^ 2 +高度^ 2)
rhoLimit = norm([width height]);
有人可以提供如何解釋/爲什麼要計算rho,theta和houghSpace?
rho = (-rhoLimit:1:rhoLimit); theta = (0:thetaSampleFrequency:pi); numThetas = numel(theta); houghSpace = zeros(numel(rho),numThetas);
我該如何解開Hough空間來重新創建線條?
使用對角線的10×10圖像調用函數使用標識(眼)函數
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
對[DSP.SE](http://dsp.stackexchange.com/)更好的問題。 – Phonon 2012-03-29 01:33:33
@Phonon爲什麼?這是一個關於特定算法實現細節的問題。 – 2012-03-29 04:50:49