Computer Vision Homework #1 - Fall 2005.

1 Edge and Corner Detection Problem 1: Gradients and Images Here you will explore the use of different image smoothing approaches a) (2D Gaussian Filter) Write a Matlab function to implement a 2D Gaussian Filte r with size (e.g., support) equal to n = 2×(3×)+1. By separability and for efficiency you should implement it as a 1D filt er. The Matlab function should look like this function outimg=GaussianFilter(inimg,sigma) % GaussianFilter implements a Discrete Gaussian filter of % size 2*(3*sigma+1) and variance sigma % % Usage: outimg=GaussianFilter(inimg,sigma) % % argin : inimg = input image (already in Matlab’s memory) % sigma = filter variance % argout: outimg = filtered image % % Requires: Matlab 7.x, Image Processing Toolbox % Author: J.C. Cockburn % Revised: Sept 15, 2005 (cockburn@ce.rit.edu) % Check input arguments if nargin<2, help GaussianFilter return end ... end Note that the size of the filter should be 2 × (3 × ) + 1. Apply this filter to the image graph.png using three different values of : 2, 4 a nd 8. Describe what happens (look at how it affects texture, details, edges, etc, etc). The following lines show “a script” that executes the Matlab commands that you will probably use to effect the filtering. Make sure that you understand what every command does (This code is e ducational, it shows some neat tricks that I learned over the years) sigmas=[2,4,8]; % variances of smoothing filter img = double(rgb2gray(imread(’graph.png’))); colormap(’gray’); imagesc(img); for i=sigmas cmd=sprintf(’img_%1.0f=GaussianFilter(img,%1.0f);imagesc(img_%1.0f)’,i,i,i); eval(cmd); end % for k=1; for i=sigmas figure(k); colormap(’gray’); cmd=sprintf(’imagesc(img_%1.0f)’,i); eval(cmd); k=k+1; end % for Instructor: J.C. Cockburn page 1 of 3 Computer Vision Homework #1 - Fall 2005.1 b) (First Gaussian Derivatives) The effects of applying a filter can be studied (in the spatial domain) by looking at their impulse response. Note that at a point x

G(x) = 1 p2 exp(− x2 d dx G(x) = − 2 p23 x exp(− x2 First, implement Matlab functions that implement the equations (1) and (2) with prototypes gauss(x,sigma) and gauss dx(x,sigma), where x is the point of evaluation. Then set = 6 and defi ne the following 1D filter kernels G and D sigma=6.0; x = [round( 3.0*sigma):round(3.0*sigma)]; G = gauss(x,sigma); D = gauss_dx(x,sigma); Now create a 25 × 25 test image in which only the central pixel has a non zero val ue, for example imgImp = zeros(25,25); imgImp(13,13)=255; What will happen when you apply the following filter combinations ? (display the resulting image with imagesc) (a) first G then G (b) first G then D (c) first D then GT (d) first GT then D (e) first DT then G Note: GT is the transpose of the matrix G. In Matlab you do G’ c) (2D Derivative of Gaussian) Write a Matlab function that implements a Derivat ive of Gaussian (DoG) filter that returns the 2D Gaussian derivatives of an input image in the x and y directions. Implemented your filter using the separability property of the Gaussian. Your function should be named DofGaus s.m and should have the following prototype function [imgDx,imgDy]=DofGauss(img,sigma) ... end d) (Second Gaussian Derivatives) In a similar manner, write a function that retu rns the second derivatives of the gaussian of an input image. Your function should be named SDerivGauss.m and shou ld have the following prototype function [imgDxx,imgDxy,imgDyy]=SDerivGauss(img,sigma) ... end e) (Image Gradients) Write a Matlab function to compute the gradient of an image at an arbitrary point and returns its magnitude and direction. Your function should be named ImgGrad.m and should have the following syntax function [gradMag,gradDir]=ImgGrad(img,sigma) ... end

 

 

f) (2D Laplacian of Gaussian) Finally, write a Matlab function that implements a Laplacian of Gaussian (LoG) filter that returns the 2D Gaussian derivatives of an input image in the x and y direct ions. It should be based on the 1D filter d dx G = − 2 p23 x exp(− x2 Your function should be named LofGauss.m and should have the following syntax function logimg=LofGauss(img,sigma) ... end Note: All the Matlab function should be documented (use the form given in part a ) as an example) Instructor: J.C. Cockburn page 2 of 3 Computer Vision Homework #1 Fall 2005.1 Problem 2: Edge Detection a) Here you will experiment with a very simple edge detector. Write a function G etEdges that returns a binary image formed by thresholding an the gradient of an input image as follows: For a given threshold value the value of the pixel p is set to 1 if its gradient magnitude exceeds the threshold and t o 0 otherwise. Your function should be named GetEdges.m and should have the following syntax function imgEdges=GetEdges(img,sigma,tau) ... end b) Experiment with the function GetEdges on the given sample images. Try to obta in good edge images for different values of sigma. What difficulties do you observe ? (Note: it may be useful to l ook at a small patch of the image where certain features can be easily observed, for example, imgMag(1:10,1:10)) c) You will see that the above function returns edges that are several pixels wi de. To sharpen the edges it is necessary to further process the edge image to thin the edges to one pixel. One way to do this is to use a non maximum suppression algorithm (read the book for details). Write a function that impleme nts a non maximum suppression algorithm and call it Nonmaxsup.m. The prototype of the function should be function imgEdges=Nonmaxsup(imgMag,imgDir) ... end Apply this function to the given images and comment on the results. d) Another problem with finding edges is that a suitable value for the threshold tau usually varies substantially between images. Extend the function GetEdges such that the threshold tau 2 [0, 1 ] is defined relative to the maximal gradient magnitude value in the image. Apply this function to the given images and comment on the results. Problem 3: Corner Detection a) Implement an algorithm to detect corners. The function should be called Corne rs.m and have the following syntax function lst=Corners(img,theta,nbh) ...

 

 

 

end where img is an input image, theta is a threshold, nbh the size of the (evaluati on) neighborhood and lst a list with the image coordinates of points that are considered corners. b) Develop an interface displaying corners superimposed on the original images ( use the script ImagePatch.m as an example). c) Experiment with different values for nbh and theta. For each fixed pair of va lues measure the robustness of your implementation with synthetic images of squares corrupted by increasing amounts of Gaussian noise, as follows: Record the RMS distance of the estimated corners from the true positions, and th e number of spurious and missed corners. Then Plot these values in three graphs, against the standard deviation of the noise. Do the graphs agree with your expectations ? Instructor: J.C. Cockburn page 3 of 3