3

有谁知道如何使用霍夫变换来检测二值图像中最强的线条:

A = zeros(7,7);
A([6 10 18 24 36 38 41]) = 1;

使用 (rho; theta) 格式和 theta,从 -45° 到 90° 以 45° 为步长。以及如何在 MATLAB 中显示累加器数组。

请问有什么帮助或提示吗?

谢谢!

4

2 回答 2

5

如果您有权访问图像处理工具箱,则可以使用函数HOUGHHOUGHPEAKSHOUGHLINES

%# your binary image
BW = false(7,7);
BW([6 10 18 24 36 38 41]) = true;

%# hough transform, detect peaks, then get lines segments
[H T R] = hough(BW);
P  = houghpeaks(H, 4);
lines = houghlines(BW, T, R, P, 'MinLength',2);

%# show accumulator matrix and peaks
imshow(H./max(H(:)), [], 'XData',T, 'YData',R), hold on
plot(T(P(:,2)), R(P(:,1)), 'gs', 'LineWidth',2);
xlabel('\theta'), ylabel('\rho')
axis on, axis normal
colormap(hot), colorbar

%# overlay detected lines over image
figure, imshow(BW), hold on
for k = 1:length(lines)
    xy = [lines(k).point1; lines(k).point2];
    plot(xy(:,1), xy(:,2), 'g.-', 'LineWidth',2);
end
hold off

霍夫 线条

于 2011-07-14T18:14:55.313 回答
1

每个像素 (x,y) 映射到一组穿过它的线 (rho,theta)。

  1. 建立一个以 (rho theta) 为索引的累加器矩阵。
  2. 对于每个打开的点 (x,y),生成与 (x,y) 对应的所有量化 (rho, theta) 值,并在累加器中递增对应点。
  3. 找到最强的线对应于在累加器中找到峰值。

在实践中,极坐标参数的描述对于正确处理很重要。太细和不够的点会重叠。太粗糙,每个 bin 可能对应多行。

在具有自由的伪代码中:

accum = zeros(360,100);
[y,x] = find(binaryImage);
y = y - size(binaryImage,1)/2;  % use locations offset from the center of the image
x = x - size(binaryImage,2)/2;
npts = length(x);
for i = 1:npts
    for theta = 1:360  % all possible orientations
        rho = %% use trigonometry to find minimum distance between origin and theta oriented line passing through x,y here
        q_rho = %% quantize rho so that it fits neatly into the accumulator %% 
        accum(theta,rho) = accum(theta,rho) + 1;
    end
end
于 2011-07-13T15:18:19.360 回答