Question

The hough transform in matlab is called in the following way:

[H, theta, rho] = hough(BW)

If I want to specify the theta values, I can use

[H, theta, rho] = hough(BW, 'Theta', 'begin:step:end')

The theta parameter specify a vector of Hough transform theta values. My problem is the fact that the acceptable range of theta values in Matlab is between -90 and 90 degrees. I want to calculate the hough transform with theta values between 0 and 180 degrees. Should I re-implement hough transform in matlab? is there any other code that allows this range in hough transform?

Was it helpful?

Solution

Due to the definition of the hough-Transformation, the vale for r(roh,theta)=r(-roh,theta+180). You can flip the data you get for -90:0 horizontally and you will get the data for 90:180.

The following code uses the example from the documentation and completes the data to full 360 degree:

%example code
RGB = imread('gantrycrane.png');

% Convert to intensity.
I  = rgb2gray(RGB);

% Extract edges.
BW = edge(I,'canny');
[H,T,R] = hough(BW,'RhoResolution',0.5,'Theta',-90:0.5:89.5);

% Display the original image.
subplot(3,1,1);
imshow(RGB);
title('Gantrycrane Image');

% Display the Hough matrix.
subplot(4,1,2);
imshow(imadjust(mat2gray(H)),'XData',T,'YData',R,...
      'InitialMagnification','fit');
title('Hough Transform of Gantrycrane Image');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
colormap(hot);

%Modifications begin
subplot(3,1,3);
%append another 180 degree to the axis
T2=[T T+180];
%append flipped data
H2=[H,H(end:-1:1,:)];
%plot the same way.
imshow(imadjust(mat2gray(H2)),'XData',T2,'YData',R,...
      'InitialMagnification','fit');
title('Hough Transform of Gantrycrane Image');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
colormap(hot);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top