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 it’s 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');

Find the peak of Hough Transform matrix D   nRho  2  ceil    1 .Edge linking approach by Hough Transform can be summarized as: 1.N]=size(BW) >> D = sqrt((M . >> [M.1)^2) >> NRHO = 2*(ceil(D)/1) % NRHO = 2*(ceil(D)/RhoResolution) >> DIAGONAL = 1*ceil(D)/1. N ]  size  ( BW ) 90   nTheta  2  ceil    1  Theta Re solution  According to hough transform default in MATLAB: >> theta_res = 1. Find Edge of Images using edge functions/detector (Canny. [M . Apply Hough Transform to detect lines in image a. >> rho_res = 1. Sobel. %DIAGONAL = RhoResolution*ceil(D)/RhoResolution) >> >> norm(size(BW)) . Compute Hough Transform Matrix of Image b. D   Rho Re solution  M  12  N  12 . Prewit) 3.1)^2 + (N . Obtaining a binary or gray scale image 2.

Transform+ *HT Line Detection+ *Superimpose a plot of image+ .Original Images – Grayscale Images Sobel Hough Transform *Sobel Edge Detection+ *H.

Find the edges in the image using the edge function.Canny Hough Transform *Canny Edge Detection+ *H. 'canny'). I_g = rgb2gray(I). th] = edge(I_g. th] = edge(I_g. 'sobel'). [f. . 2. [e. Read an image into the MATLAB workspace.jpg'). imshow(I_g). Convert image to grayscale image to make the process easier. I = imread('nc3. 3. Transform+ *HT Line Detection+ *Superimpose a plot of image+ Sequential Scripting: 1.

Superimpose a plot on the image of the transform that identifies the peaks x = theta(P(:. 7.. H P = houghpeaks(H. . Create a plot that superimposes the lines on the original image figure. axis normal. Find the peaks in the Hough transform matrix.'Color'. ylabel('\rho').2.'Color'.'x'.xy(1.1).2. Display the Hough transform.theta. 5.'s'. hold on.1). 'MinLength'. figure. ceil(0.point2]. colormap(hot) 6.2). axis on. 5.2). 2)).'LineWidth'. Apply colour mapping to let easier analysis.'fit'). for k = 1:length(lines) xy = [lines(k).'red'). 9.. rho.2).'LineWidth'. y = rho(P(:.[].rho.'x'.'yellow'). P.xy(2.'YData'. plot(xy(:. rho] = hough(e).xy(:. 'color'.2. hold on max_len = 0.. 'FillGap'. plot(xy(2.1). H is now our Hough Transform matrix.y. lines(k). [H. 'blue').point1. plot(x. Compute the Hough transform of the image. imshow(I_g). 7). imshow(imadjust(mat2gray(H)). 8.1)). theta. 5. % Plot beginnings and ends of lines plot(xy(1.3*max(H(:)))).'XData'.'LineWidth'. 'InitialMagnification'. Find lines in the image using the houghlines function lines = houghlines(e.'Color'. 'threshold'. xlabel('\theta (degrees)').4. theta.'green').

'Color'.xy_long(:. 'blue').2).'s'. plot(x.y.'LineWidth'.% Determine the endpoints of the longest line segment len = norm(lines(k). xy_long = xy.'red'). if ( len > max_len) max_len = len. end end % highlight the longest line segment plot(xy_long(:.point2).point1 . .lines(k).1).2. 'color'.

y.'s'.xy_long(:.'Color'.2).'LineWidth'. plot(x. .2. 'blue').'red').1).% highlight the longest line segment plot(xy_long(:. 'color'.

Sign up to vote on this title
UsefulNot useful