Auto align an image using Hough Transform

1 次查看(过去 30 天)
I have an image that is slightly misaligned. I thought the Hough transform would be relevant to aligning it.
But the answer is coming out to be 32 degrees which is wrong. Heres my code:
BW2 = edge(ROI,'canny');
figure(),imshow(BW2);
% Perform the Hough transform
[H, theta, rho] = hough(BW2);
% Find the peak pt in the Hough transform
peak = houghpeaks(H);
% Find the angle of the bars
barAngle = theta(peak(2));
title (num2str(barAngle))
Thanks for any help Jason

回答(1 个)

Pavel Dey
Pavel Dey 2016-1-21
编辑:Pavel Dey 2016-1-21
I would like to know how are you verifying the result? Have you written another code to get the output? In that case I would suggest you to do the same check with one of the example image given in the documentation page.
See if the results are matching for the given example. If the difference is still there then check the following things,
1) How large is the difference? 2) Make sure that your reference for measuring the angle is same as the MATLAB. See the algorithm part of the doc link for Hough Transform
Hope that helps.
  1 个评论
Jason
Jason 2016-1-21
Thanks for replying...I had given up as no responses!!
Its clear to see that the red line is not at 32 degrees with respect to the horizontal.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by