hough函数 matlab,在不使用hough函数的情况下在MATLAB中进行Hough变换

我在

Rosetta Code的MATLAB中找到了Hough变换的实现,但是我无法理解它.另外我想修改它以显示原始图像和重建线(de-Houghing).

理解它和de-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);

>我如何去霍夫空间重建线条呢?

使用使用身份(眼睛)功能创建的对角线的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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值