Object Detection using Hough Transform (II)

In previous post we've compare the Hough Matrix of a single dot, 2 dots and a single line. In this post, we'll look into more shapes:

a. Square Object




The right hand plot shows the frequencies of an intensity occurs in the Hough Matrix. It can also interpreted as: Number of lines that cross the number of points shown in the x-axis. For e.g.: for a dot, number of lines that cross one point is 180, for 2 dots image, number of lines that cross one point is 358, while number of lines that cross 2 points are 1. (refer to previous post)

For a square object, numbers of lines that cross 1 point, 2 points.....until n points in which n is the lenght of the square (approximately) would be almost the same. This could be noticed in the right figure.

b. Round Object

For a round object, numbers of lines that cross 1 point, 2 points.....until n points in which n is the diameter of the round object (approximately) would be increase in exponently. This could be noticed in the right figure.

Well, there are much more information we could get from the Hough Matrix, and what I written here might be wrong in someway, so try it out by using different images with 1 dot, 2 dots, 3 dots... using the code provided in the previous post, you would find more and more useful information from the plots!

Object Detection using Hough Transform (I)

Hough Transform convert the binary image from x-y plane to rho-theta plane. This series of examples are going to show some properties that we can observe from the hough matrix and classify some simple object shapes based on it. For more information on the Hough Transform, you can use any searh engine such as google or yahoo to searh for the keyword: "Hough Transform".

1. Original image and convert to binary image
S = imread('img1.bmp');
S = im2bw(S);
imshow(S);

2. Perform Hough Transform and show the result
[H, theta,rho]=hough(S);
figure;
imshow(H,[],'xdata',theta,'ydata',rho);
xlabel('\theta'),ylabel('\rho')
axis on, axis normal;
title('Hough Matrix');

3. Count the "frequency" of the intensity of the Hough Matrix.
clear data;
for cnt = 1:max(max(H))
data(cnt) = sum(sum(H == cnt));
end
figure;
plot(data,'.');

The codes are applied to different images to compare the differences of
the Hough Matrix on different objects' shapes.

Some simple objects' shape and their Hough Matrix are as follow:

a. Single Point


To obtain the Hough Transform, draw lines from -90 to 90 degree that cross the dot, follow by drawing a Perpendicular line from the upper left of the image to the line, and measure the lenght(rho) and the angle (theta) of the Perpendicular line.

The "hough" function will perform this for every 1 degree, and hence, for a single dot, the there will be 180 of '1' in the "Hough Matrix".

b. Two Points

When there are two points on an image, the Hough Matrix consist of 2 lines, and interect at a point which is a line that link the 2 points together in x-y plane (left figure).

Since there is only one intersection (only one line that link 2 points together), the frequencies of '1' in Hough Matrix is 358, while the frequencies of '2' is 1 in the Hough Matrix. (the '1' and '2' indicates how many time a rho-theta appear in the Hough Matrix)

c. Line

A line consists of numbers of points, ideally (the line is 45 degree) the intersection in the Hough Matrix will have the intensity same as the line lenght.

Hough Transform always used to detect lines in a real image, in which the edges always distorted. A higher value in the Hough Matrix indicates the higher possibility of the existence of a straight line.

More objects shapes will be shown in the next post...