Sunday, March 7, 2010

Hough Tough on my Laf-tof


This image is a picture of Eden Nature Park's Greenhouse Hydroponic Vegetable Garden:) Where else can you find such a wonderful agricultural wonder but in Davao City, Philippines:)

We were asked to choose an images with lines to use the Hough Transform with, I chose the image above:)

The Hough Transform is a useful tool for shape identification in images. Commonly used to identify basic shapes, such as lines, the Hough transform can be invoked for a variety of applications: road mapping, surveying, structure analysis, etc.. Hough operates on binary images (white/'1'-valued and black/'0'-valued), where black = background, so before using the technique, make sure that the image has been pre-processed so that the pixels of interest are white.:)



The image below is a B&W version of a cropped section of the Eden Pic.
The way I understand Hough is not that it ain't that tough.:) For me, it's a mere transformation /"transposition" into the polar coordinate system("circular" system as opposed to the Cartesian "flat" system). By this, I mean that we can represent an image in terms of each pixel having a specific radius and angle from a fixed point. So, instead of saying (x,y), we have (r, theta), gets?:)

(refer more to this for a review of polar coordinates: http://csdt.rpi.edu/na/shoban/polar/polar.html)


The advantage of having to represent our image in (r,theta), as what the Hough transform does, is that we can then identify which pixels actually lie on the same line!:) How??

(Warning: geeky part here...) [Reference: http://www.cogs.susx.ac.uk/users/davidy/teachvision/vision4.html ]

Representing each pixel as (r, theta) enables us to plot the image in an r-theta graph which gives us some cyclic patterns (since we are traversing the image not from left to right, top to down, but rather from -90 to +90 degrees). In this graph, each "sinusoidal strand" represents one cycle and in each cycle, we mark out only those where pixels are present (valued '1' / colored white).
Hence, when we are able to represent the whole image in terms of these sinusoidal strands, we find that there are more intense points which correspond to pixels lying on the same line!:) (remember the equation of a line: y=mx+b; theta will be related to slope; and since one line=1 slope, you'll get the same theta values for pixels on the same line)


I tried the Hough Transform in scilab using this original image:

and came out with this "polar" graph:

I really didn't know what to do after that but i decided to shift to Matlab (hehehehe) since i know this tool better:)


Shown below is a figure with 2 subplots. The top plot is the Original cropped Truss image and the bottom plot is the r-theta graph produced by the hough transform.
Notice how this Hough transform is in "Hot" colormap with the most intense pixels being yellow, or bright orange or white. The x axis is theta and the y axis is r. we limit theta to -90 to 90 but the r can go negative of positive which then tells us simply that the span of this hough space covers the entire 360-degree possibility for the allowed radius, r of the image.

Shown below is the same Hough Transform plot in r-theta but without the colormap. This image was generated using the houghpeaks function in Matlab. Marked in white squares are the top 20 most intense locations. The r-theta information of these locations are potential lines.:)
Using the houghlines function in Matlab, the figure below is generated. This shows the overlay of the potential lines as investigated through the houghpeaks function and we see the possible lines with the blue line as the longest line detected using the hough transform.

Notice that the lines detected were those that were thin (edges) not the broad ones:)

Grade I give for this activity: 1.25, or from 0-10, 9.5 - i could have done this faster...

No comments:

Post a Comment