Auto align an image using Hough Transform

5 views (last 30 days)
Jason
Jason on 15 Jan 2016
Edited: Pavel Dey on 21 Jan 2016
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

Answers (1)

Pavel Dey
Pavel Dey on 21 Jan 2016
Edited: Pavel Dey on 21 Jan 2016
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 Comment
Jason
Jason on 21 Jan 2016
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!