所以我已经实现了霍夫变换的每个部分,除了实际将线条绘制回原始图像之外。霍夫变换:将极坐标转换回笛卡儿,但仍然无法绘制它们
我可以设置我的数据我有这样的数组。
points | theta | rho
-------|-------|----
[246,0] -90 -246
[128,0] -90 -128
[9,0] -90 -9
[0,9] 0 9
[0,128] 0 128
[0,246] 0 246
点在于被极坐标转换从峰的点。所以现在我需要画出所有这六行,而且我没有运气。
编辑
所以我试图改变基于关我的代码的建议。这是我想出的。
function help(img, outfile, peaks, rho, theta)
imshow(img);
x0 = 1;
xend = size(img,2);
peaks_len=length(peaks);
for i=1:peaks_len
peak=peaks(i,:);
r_ind=peak(1);
t_ind=peak(2);
r=rho(r_ind);
th=theta(t_ind);
%display([r,th,peak]);
%// if a vertical line, then draw a vertical line centered at x = r
% display([r, th]);
if (th == 0)
display('th=0');
display([1, size(img,1)]);
line([r r], [1 size(img,1)], 'Color', 'green');
else
%// Compute starting y coordinate
y0 = abs((-cosd(th)/sind(th))*x0 + (r/sind(th)))+11;%-25;
%// Compute ending y coordinate
yend = abs((-cosd(th)/sind(th))*xend + (r/sind(th)))+11;%-25;
display('y');
display([y0, yend]);
display('x');
display([x0 xend]);
%// Draw the line
line([x0 xend], [y0 yend], 'Color', 'green');
end
end
end
我不得不从r==0
更改为th==0
因为th=0
会给NAN
错误时根据离峰r为不为0
,然后我用,要得到我需要再计算一些数据价值......但由于某种原因,这不是很好的策划。
如果您注意到两个y值的+ 11。我必须这样做才能使线路成为他们需要的地方。我有一种感觉,还有其他的错误。
我确实改变了它,所以我的Rho值现在都是正值。
您没有正确使用“abs”。我的意思是在积累阶段,而不是绘画阶段。画线时不要拿“abs”。当你在变换阶段计算'rho'时,在那里取绝对值。你似乎误解了我。 – rayryeng 2015-02-06 01:29:08
我实际上完全改变了我的rho,所以没有负面因素。 – 2015-02-06 01:54:06
这很好。绘制线条时不要使用“abs”。它们不会出现在图像上,因为它们在技术上会超出范围。 – rayryeng 2015-02-06 02:09:28