inverse hough transform in matlab

To perform inverse Hough transform in MATLAB, you can follow these steps:

  1. Load the Hough transform data obtained from the original image using hough function in MATLAB.

  2. Determine the maximum value of rho and theta parameters using the size of the Hough transform data.

main.m
[H,theta,rho] = hough(BW);
max_rho = norm(size(BW));
max_theta = 180;
70 chars
4 lines
  1. Create a meshgrid of theta and rho arrays.
main.m
[T,R] = meshgrid(theta,rho);
29 chars
2 lines
  1. Find the (x,y) coordinates of the lines using the inverse Hough transform equations for each (theta,rho) pair.
main.m
X = R.*cosd(T);
Y = R.*sind(T);
32 chars
3 lines
  1. Create a binary image of the same size as the original image and set the image values to zero.
main.m
BW_inv = false(size(BW));
26 chars
2 lines
  1. Loop over all the lines and set the corresponding pixels in the binary image to 1.
main.m
for k = 1:length(theta)
    x = X(:,k);
    y = Y(:,k);
    idx = sub2ind(size(BW),round(y)+1,round(x)+1);
    BW_inv(idx) = 1;
end
132 chars
7 lines
  1. Obtain the final output by inverting the binary image using ~ operator.
main.m
output = ~BW_inv;
18 chars
2 lines

The output variable will contain the original binary image after performing inverse Hough transform.

gistlibby LogSnag