EN161 - Image Processing and Understanding
Lab 5 - Edge Detection
Due Tuesday 10/8
NOTE: Problems should be done in MATLAB.  Type up your solutions for each one including: (1) The answer to any questions posed, (2) any resulting images (include in document), and (3) the name of any functions you used. 

Zip or tar your document with your source code (m-files) into a file called [Lastname_FirstInitial_Lab5.zip/tar] and email it to mcchang@lems.brown.edu with the subject "EN161 Lab5".

Overview:
This lab will introduce you to various methods of edge detection.  You should use matlabs edge detection program for Problem 2 and write your own  edge detector algorithms for problems 3 and 4.
Data:
 
Image A
Image B
 k_coef.mat

 
Problem 1:
Give a few examples of each of these types of edges in the images A and B.
  • Reflectance Edges
  • Texture Edges
  • Highlight Edges
  • Shadow Edge
for example:
Problem 2:
Run matlabs edge (edge) detection function over Image A and Image B.  Use:
  • Canny
  • Prewitt
  • Sobel
  • Laplacian
on each image.  Determine the strengths and weaknesses of one relative to the other. 
Specifically look for the success of each algorithm with respect to corners, curved edges, noise inclusion/exclusion, etc. 
Which of the edge types above are most easily detected; which are more difficult.
Provide specific examples and images to illustrate your findings.

 
Problem 3:
In this problem you will explore a very simple edge detector.

a. Load imageA and smooth it with a Gaussian filter to eliminate noise.
b. Use the gradient function to compute the 1st derivatives in the x and y direction:

[dy,dx]=gradient(A);

c. Look at the magnitude of the gradient image using imshow, M=sqrt(dx^2+dy^2)
d. Now use the command quiver(dy,dx) to view the actual gradient vectors; you may want to zoom in.  (The image will be upside down, don't worry about it).  It is very important that you understand what is going on here for this and the next lab.
e. Create a binary edge image by thresholding the gradient magnitude image.  Pick a value that gives you few gaps in the edges.
f. Finally thin the edges using the following process:

   1.  Visit every edge pixel in the binary image.  For each one, look at the gradient direction at that point (dy,dx) and round it to the nearest of the 8 pixel directions.
   2.  Look at the gradient magnitude of the pixel in that direction and also at the pixel in the oposite direction.
   3.  If the pixel in question has a gradient magnitude less than either of those two neighbors, set its value in the binary image to 0.

Submit the thinned and unthinned images.  Also try it on image B.


 
Problem 4:
Implement an edge detecting program using a Cubic Image Approximation (from page 165 of edge detection handout given out in class). 

I have provided the masks k1-k10 in the matlab file k_coef.mat, download it into a matlab directory and type load k_coef to load the masks into your workspace.  I recommend using filter2 to apply the masks (don't forget to scale them by the value given below each mask).

Hints: You will want to filter the image first to eliminate noise.  Also, if your edges are too thick, try reducing the pixel radius.  Also, when checking to make sure the first derivative is not zero, you will probably want to say something like:

d > gamma
instead of
d ~= 0

Try it out on Images A and B.  Show the resulting edge images.