MATLAB 中的霍夫变换

发布于 2024-11-19 23:58:30 字数 210 浏览 4 评论 0原文

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

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

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

有什么帮助或提示吗?

谢谢你!

Does anyone know how to use the Hough transform to detect the strongest lines in the binary image:

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

Using the (rho; theta) format with theta in steps of 45° from -45° to 90°. And how do I show the accumulator array in MATLAB as well.

Any help or hints please?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尸血腥色 2024-11-26 23:58:30

如果您有权访问图像处理工具箱,则可以使用函数 HOUGH< /a>、HOUGHPEAKSHOUGHLINES:

%# 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

hough
lines

If you have access to the Image Processing Toolbox, you can use the functions HOUGH, HOUGHPEAKS, and HOUGHLINES:

%# 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

hough
lines

再可℃爱ぅ一点好了 2024-11-26 23:58:30

每个像素 (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

Each pixel (x,y) maps to a set of lines (rho,theta) that run through it.

  1. Build an accumulator matrix indexed by (rho theta).
  2. For each point (x,y) that is on, generate all the quantized (rho, theta) values that correspond to (x,y) and increment the corresponding point in the accumulator.
  3. Finding the strongest lines corresponds to finding peaks in the accumulator.

In practice, the descritization of the polar parameters is important to get right. Too fine and not enough points will overlap. Too coarse and each bin could correspond to multiple lines.

in pseudo code with liberties:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文