【发布时间】:2015-02-05 18:52:48
【问题描述】:
所以我已经自己实现了霍夫变换的每个部分,除了实际将线条重新绘制到原始图像上。
我可以像这样设置我的数据数组。
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,因为当r 不为0 时th=0 会给出NAN 错误。
根据峰值,然后我用它来获取我需要的数据,然后计算一些值......但由于某种原因,这不能很好地绘制。
如果您注意到两个 y 值的 + 11。我必须这样做才能让线路到达他们需要的地方。我感觉还有什么地方出了问题。
我确实改变了它,所以我的 Rho 值现在都是正数。
【问题讨论】:
-
您没有正确使用
abs。我的意思是在积累阶段,而不是绘图阶段。画线时不要使用abs。在转换阶段计算rho时,取那里的绝对值。你好像误会了我的意思。 -
我实际上完全改变了我的 rho,所以没有负面影响。
-
没关系。画线时不要使用
abs。它们不会出现在图像上,因为从技术上讲它们会超出范围。 -
这里的 matlab 似乎将 y 值向下计数。所以没有腹肌,什么都没有。
-
当你显示图像时是的。另外,我假设这是您在计算转换时使用的约定。 TBH 我真的不知道你是怎么做到的。不管怎样,祝你好运!
标签: matlab image-processing hough-transform