【发布时间】:2012-03-28 21:57:12
【问题描述】:
我在Rosetta Code 找到了 MATLAB 中霍夫变换的实现,但我无法理解它。另外我想修改它以显示原始图像和重建的线条(去霍夫)。
感谢您对理解它和去 Houghing 的任何帮助。谢谢
-
为什么图片会翻转?
theImage = flipud(theImage); 我无法理解规范函数。它的目的是什么,可以避免吗?
编辑: norm 只是欧式距离的同义词:sqrt(width^2 + height^2)
rhoLimit = norm([width height]);
-
有人可以解释如何/为什么计算 rho、theta 和 houghSpace 吗?
rho = (-rhoLimit:1:rhoLimit); theta = (0:thetaSampleFrequency:pi); numThetas = numel(theta); houghSpace = zeros(numel(rho),numThetas); 如何去霍夫空间重新创建线条?
使用使用身份(眼睛)函数创建的对角线的 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
【问题讨论】:
-
DSP.SE 的更好问题。
-
@Phonon 为什么?这是一个关于特定算法的实现细节的问题。