如何选择MATLAB中霍夫变换的最大强度? [英] How to select maximum intensity in Hough transform in MATLAB?

查看:1056
本文介绍了如何选择MATLAB中霍夫变换的最大强度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 函数,我们使用 houghpeaks 功能,并传递所需的峰检测数量。






EDIT1:



我想我将添加一个示例来显示过程:

 %#加载图像,处理它,找到边缘
I = rgb2gray(imread('pillsetc.png'));
I = imcrop(I,[30 30 450 350]);
J = imfilter(I,fspecial('gaussian',[17 17],5),'symmetric');
BW = edge(J,'canny');

%#执行霍夫变换和显示矩阵
[H,T,R] = hough(BW);
imshow(imadjust(mat2gray(H)),[],'XData',T,'YData',R,...
'InitialMagnification','fit')
xlabel '\theta(degrees)'),ylabel('\rho')
轴打开,轴正常,保持
颜色(热),颜色条

%检测峰值
P = houghpeaks(H,4);
plot(T(P(:,2)),R(P(:,1)),'gs','LineWidth'

%#检测图像上的线条和覆盖图
lines = houghlines(BW,T,R,P);
figure,imshow(I),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







EDIT2:



我设法通过只对上面的代码进行几个更改检测线路:




  • 我裁剪区域为: [200 70 160 140]

  • 我使用了一个带有sigma = 3的11x11高斯滤镜



注意:您将必须添加偏移量,以获取原始图像中线条的位置。此外,如果您想获得更准确的结果,您可能需要检测四行,并获取中间的行,如下所示:




After doing the Hough transform in MATLAB, how do I pick the lines so that I can compare between two or more images?

I followed the example given by Amro and actually what I wanted to detect is the two lines in the first picture. However, what I got is the one in the second picture. How can I do this?

解决方案

I think you meant the goal to be to detect lines in an image, not comparing two images (?).

Anyway, to find the maximum intensities in the Hough transform matrix generated by the hough function, we use the houghpeaks function, and pass it the desired number of peaks to detect.


EDIT1:

I figured I would add an example to show the procedure:

%# Load image, process it, find edges
I  = rgb2gray( imread('pillsetc.png') );
I = imcrop(I, [30 30 450 350]);
J = imfilter(I, fspecial('gaussian', [17 17], 5), 'symmetric');
BW = edge(J, 'canny');

%# Perform Hough transform and show matrix
[H,T,R] = hough(BW);
imshow(imadjust(mat2gray(H)), [], 'XData',T, 'YData',R, ...
       'InitialMagnification','fit')
xlabel('\theta (degrees)'), ylabel('\rho')
axis on, axis normal, hold on
colormap(hot), colorbar

%# Detect peaks
P  = houghpeaks(H, 4);
plot(T(P(:,2)), R(P(:,1)), 'gs', 'LineWidth',2);

%# Detect lines and overlay on top of image
lines = houghlines(BW, T, R, P);
figure, imshow(I), 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


EDIT2:

Following your recent update, I managed to detect the lines by only making a few changes to the same above code:

  • I cropped the region to: [200 70 160 140]
  • I used an 11x11 Gaussian filter with sigma=3

Note: You will have to add the offset to get the position of the lines in the original image uncropped. Also, if you want more accurate results, you might want to detect four lines and get the lines in the middle as shown below:

这篇关于如何选择MATLAB中霍夫变换的最大强度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆