LAB 6

EDGE DETECTION AND HOUGH TRANSFORM

Source Code

bullet

    hough.m

bullet

    houglines.m

|| Lab2 || Lab3 || Lab4 || Lab5 || Lab6 || Lab7 || Lab8 ||
 Back to Main Menu

________________________________________________________________________________________________________________________

Aim of this lab:


The aim of this laboratory session is to experiment with edge detection and implement the Hough transform for finding lines in images.
________________________________________________________________________________________________________________________

Edge Detection

The first part of this lab was to about edge detection. The basic gradient based edge detection process is to calculate image derivatives in the vertical and horizontal directions, square and add the results, and then take the square root to obtain a gradient strength image. Prior to taking the derivatives the image is usually smoothed with a Gaussian filter to reduce the influence of noise. The degree of smoothing controls the scale of analysis. With heavy smoothing we obtain the large scale edges, and with little or no smoothing we obtain the fine scale edges.

We were asked to used our image to generate the gradient strength image for three very different levels of Gaussian smoothing and observe the difference. I've used three different values for the standard deviation parameters when creating the Gaussian filter. The results are shown below:

MATLAB Command:
g = rgb2gray(im);
imfft = fft2(g);
size(imfft)
gfilter = fspecial('gaussian',[276 368], 6);
gfft = fft2(gfilter);
newimfft = imfft.*gfft;
newim = fftshift(real(ifft2(newimfft)));
horizontal = [-1 0 1];
vertical = [-1;0;1];
hfilter = filter2(horizontal, newim);
vfilter = filter2(vertical, newim);
gsmoothimage = sqrt(hfilter.*hfilter + vfilter.*vfilter);
imagesc(gsmoothimage);


   

Figure1: The smoothing image with standard deviation = 2                    Figure2: The smoothing image with standard deviation = 4


Figure3: The smoothing image with standard deviation = 6

From the above result, we can see that a lower value of standard deviation for Gaussian filter will produce a more pleasing image compare to the images applied with higher standard deviation.

Then we used the Matlab's edge function which implements a variety of edge detection methods. The 'canny' option was used to generate the edge map of myself. Below are the results of using this function with different hysterisis threshold values.

MATLAB Command:
imshow(edge(g, 'canny', [0.05 0.1]));  %get the edge map of image using Matlab's edge function
imshow(edge(g, 'canny', [0.05 0.12]));
imshow(edge(g, 'canny', [0.05 0.15]));


   

Figure4: The edge map of myself, using threshold value of [0.05,0.1]         Figure5: The edge map of myself, using threshold value of [0.05,0.12]


Figure6: The edge map of myself, using threshold value of [0.05,0.15]

The results above shows that an image with more edge detected can be achieve by applying a lower value of the hysterisis threshold. Notice that the edge of the image reduces as the value of the hysterisis threshold increase.

Finding lines using Hough Transform

The next part of this lab is write a hough.m  function to find sets of straight lines of edge pixels in an edge image and after that, we will find what the dominant lines are and overlay them in the image. This operation is done by implementing the houghlines.m function. The results of executing these 2 functions is shown below:

MATLAB Command:
lego = imread('lego1.jpg');
legog = rgb2gray(lego);
h = hough(legog,[0.05, 0.1], 400, 400);   
%get the hough transform of lego1.jpg

First, we get the hough transform of the lego1.jpg by executing the hough.m with the threshold of [0.05, 0.1] and the result is:

   
Figure7: The Hough Transform of lego1.jpg          Figure8: The gamma enhanced version

Then we compute the houghlines function on the lego1.jpg to find the significant lines of the image. Various threshold values have been used to carry out this experiment.

   
Figure9: Houghlines of lego1.jpg by using threshold value = 100           Figure10: Houghlines of lego1.jpg by using threshold value = 200 


Figure11: Houghlines of lego1.jpg by using threshold value = 375

Figure11 is an image of the dominant straight detected in the Lego image when apply threshold value of 375 on it.

Written by Geoffrey Liau
Last updated: 24th May 2005
liauc01@student.uwa.edu.au