MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何在MATLAB中的霍夫变换中选择最大强度? (https://www.labfans.com/bbs/showthread.php?t=23021)

poster 2019-12-10 16:49

如何在MATLAB中的霍夫变换中选择最大强度?
 
在[URL="http://en.wikipedia.org/wiki/MATLAB"]MATLAB中[/URL]进行了[URL="https://en.wikipedia.org/wiki/Hough_transform"]Hough变换[/URL]后,如何选择线条,以便可以在两个或多个图像之间进行比较?

我按照Amro给出的示例进行操作,实际上我想检测的是第一张图片中的两行。但是,我得到的是第二张图片。我怎样才能做到这一点?

[IMG]https://i182.photobucket.com/albums/x11/veronicafmy/FYP/pict1.jpg[/IMG]

[IMG]https://i182.photobucket.com/albums/x11/veronicafmy/FYP/pict2.jpg[/IMG]


回答:
我认为您的目标是检测图像中的线条,而不是比较两个图像(?)。

无论如何,以找到最大强度[URL="http://en.wikipedia.org/wiki/Hough_transform"]霍夫变换[/URL]由所产生的矩阵[B][URL="http://www.mathworks.com/help/images/ref/hough.html"]hough[/URL][/B]功能,我们使用[B][URL="http://www.mathworks.com/help/images/ref/houghpeaks.html"]houghpeaks[/URL][/B]功能,并把它传递到峰值检测的所希望的数目。

[B]编辑1: [/B]

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

%# 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 [IMG]https://i.stack.imgur.com/YEAIU.png[/IMG][IMG]https://i.stack.imgur.com/qmSnt.png[/IMG]

[B]编辑2: [/B]

在您进行了最近的更新之后,我仅通过对上述相同的代码进行了一些更改来设法检测到这些行:
[LIST][*]我将该区域裁剪为: [200 70 160 140][*]我使用了sigma = 3的11x11高斯滤波器[/LIST]注意:您将必须添加偏移量以使线条在原始图像中的位置保持不变。另外,如果您想获得更准确的结果,则可能需要检测四行,并获得中间的行,如下所示:

[IMG]https://i.stack.imgur.com/WkUEM.png[/IMG]



[url=https://stackoverflow.com/questions/1975206]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:05

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.