Hough transform is used to detect lines in an image. It uses the parametric representation of a line:
where rho is the distance of the line from the origin and theta is the angle between the x-axis and the vector perpendicular to the line.
Fortunately, there are built-in functions in MATLAB that are useful for this activity.
Let us start with this image, taken in Cibo. The design of the place uses a lot of lines.
First, convert the image above to grayscale and use the edge function to detect the edges in the image. I tried the Canny algorithm.
So now we have the edges in the image. Let us now implement the hough function. The hough function returns this plot:
The x- and y- axis are theta and rho, respectively. The bright spots correspond to the most prominent lines in the image.
To detect the brightest spots or the peaks, let us use the function houghpeaks. The function returns a list of theta and rho coordinates that correspond to the peaks in the hough transform plot.
Shown in the figure above are the three peaks. To plot the lines that correspond to these peaks, we use the function houghlines. The figure below shows the superposition of the plotted lines on the grayscale of the original image. We can see that the lines coincide with the lines in the ceiling and the table. The lines from the table are somewhat unexpected because visually, the ceiling lines are more prominent. I expected that before the lines from the table will be detected, all the ceiling lines will be detected first.
I also noticed that the detected lines depend on the edge detection algorithm. Shown below are the different results for the different edge detection methods.
I give myself 10 points for this activity. The hough transform was used to identify and draw the lines detected in the image. I also investigated the effect of using different edge detection algorithms, although I cannot explain the differences yet.
Sunday, April 11, 2010
Hough Transform
Posted by irene at 5:59 PM 0 comments
Monday, April 5, 2010
Stereometry
Stereometry
We can see in three dimensions because we have two eyes, with one eye seeing a slightly different scene than the other. The two images of the scene are taken with a horizontal offset that is the distance between our eyes. In this activity, we will simulate how the eyes see three dimension with two images, or stereo vision.
There are two ways to do stereo imaging. We can use two identical cameras separated by a distance b from each other. Alternatively, we can use just one camera and move it by a distance b. For practicality, we went with the second option.
Two images of the object are taken. The second image is taken by moving the camera horizontally by a distance b apart from the location where the first image is taken. The vertical position of the camera was maintained at a constant height. The same camera settings were used for both images.
Figure 1 shows the geometry of the setup.
Using similar triangles, we can see that:
and that:
Solving for z gives us:

If we do this for many points, we can reconstruct the 3D surface of the object.
The calibration of the camera was done in a previous activity, and the focus was determined to be f = 1063.6 pixels. The distance b is b = 10cm.
The 3D object used here is a box, covered with graphing paper such that it will be easy to correspond the points on the surface. Figure 2 shows the two images captured with the camera displaced a distance b.
Figure 2. The two images taken with the camera displaced a distance b.The z values are calculated for each point following the equations above.
Figure 3 shows the reconstruction of the surface.
The 3D surface of the box is rendered, shown in Figure 3. The reconstruction was successful, the 3D shape of the box can be recognized. I give myself 9 points for this activity.
Thanks to Kaye and Miguel Sison, my groupmates in a previous class where this activity was previously done.
Posted by irene at 12:50 AM 0 comments

