You are on page 1of 6

Hough Transform (HT)

HT basically emerges in a situation where either edge detectors or image data are imperfect
such as in cases of missing points/pixels and spatial deviations. Hough Transform addresses
those problems by making edge points groupings possible in spite of them. Hough transform
perform an explicit voting procedure over a set of parameterized image objects.
Let in image space a straight line of several points x, y denoted as y = ax + b, in Hough Transform
it will be considered in parametric space of the slope parameter a and intercept parameter b, so
that its considered as (a, b).
For computational reason, that is to avoid infinity slope, we will use different pair of parameters
as r or some people denotes as and for the lines in Hough Transform where r or is the
distance from origin to the lines with being the angle of vector from the origin to closest
point.

Using parameterization concept of a line, it can be written as
r() =

sin

to further modified with respect to image plane coordinate to become
r() =

sin

of coordinates image (

).
Those equations can be simplified as to correspond to a sinusoidal curve in the (r, ) plane
which is unique to that point. If the curves corresponding to two points are superimposed, the
location (in the Hough space) where they cross corresponds to a line (in the original image
space) that passes through both points. More generally, a set of points that form a straight line
will produce sinusoids which cross at the parameters for that line. Thus, the problem of
detecting collinear points can be converted to the problem of finding concurrent curves.
Edge linking approach by Hough Transform can be summarized as:
1. Obtaining a binary or gray scale image
2. Find Edge of Images using edge functions/detector (Canny, Sobel, Prewit)
3. Apply Hough Transform to detect lines in image
a. Compute Hough Transform Matrix of Image
b. Find the peak of Hough Transform matrix


1
Re
2 +
|
.
|

\
|
=
solution Rho
D
ceil nRho , ( ) ( )
2 2
1 1 + = N M D , ) ( ] , [ BW size N M =

1
Re
90
2 +
|
.
|

\
|
=
solution Theta
ceil nTheta


According to hough transform default in MATLAB:

>> theta_res = 1;
>> rho_res = 1;
>> [M,N]=size(BW)
>> D = sqrt((M - 1)^2 + (N - 1)^2)
>> NRHO = 2*(ceil(D)/1) % NRHO = 2*(ceil(D)/RhoResolution)
>> DIAGONAL = 1*ceil(D)/1.
%DIAGONAL = RhoResolution*ceil(D)/RhoResolution)
>> >> norm(size(BW))







Original Images Grayscale Images




Sobel Hough Transform


*Sobel Edge Detection+


*HT Line Detection+


*H. Transform+

*Superimpose a plot of image+

Canny Hough Transform


*Canny Edge Detection+



*HT Line Detection+


*H. Transform+

*Superimpose a plot of image+


Sequential Scripting:
1. Read an image into the MATLAB workspace.
I = imread('nc3.jpg');
2. Convert image to grayscale image to make the process easier.
I_g = rgb2gray(I);
imshow(I_g);
3. Find the edges in the image using the edge function.
[e, th] = edge(I_g, 'sobel');
[f, th] = edge(I_g, 'canny');
4. Compute the Hough transform of the image. H is now our Hough
Transform matrix.
[H, theta, rho] = hough(e);
5. Display the Hough transform. Apply colour mapping to let easier
analysis.
figure, imshow(imadjust(mat2gray(H)),[],'XData',theta,'YData',rho,...
'InitialMagnification','fit');
xlabel('\theta (degrees)'), ylabel('\rho');
axis on, axis normal, hold on;
colormap(hot)
6. Find the peaks in the Hough transform matrix, H
P = houghpeaks(H, 5, 'threshold', ceil(0.3*max(H(:))));
7. Superimpose a plot on the image of the transform that identifies the
peaks
x = theta(P(:, 2));
y = rho(P(:,1));
plot(x,y,'s', 'color', 'blue');
8. Find lines in the image using the houghlines function
lines = houghlines(e, theta, rho, P, 'FillGap', 5, 'MinLength', 7);
9. Create a plot that superimposes the lines on the original image
figure, imshow(I_g), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');
plot(x,y,'s', 'color', 'blue');

You might also like