COMP 4102A Computer Vision: Assignment 1: SVD, Edge Detection and Sticks filter
COMP 4102A: Assignment 1
Instructions for submission: Please submit a PDF with your solutions on theory questions. The PDF should explain your work. For coding questions you may use C/C++ and OpenCV or Python with OpenCV Python for this assignment. Comment your code to make it easier to grade. Include your codes for edge detection in a folder. Submit a single zip file that contains: 1 - PDF with your answers to question 1; 2 - folder containing edge detection code, images, and readme file that explains how to run your code; 2 - folder containing your sticks filtering code, images, and readme file that explains how to run your code. Please submit through Brightspace. You are expected to work on the assignment individually. Do not leave your submission to the last minute because if you run into technical issues the system will cut you off. You can submit multiple versions of your assignment, and we will grade the latest one.
(30 points) Theory questions
(5 points) Are three dimensional rotations expressed as Rx, followed by Ry, and then Rz (rotations around the x, y and z axis) commutative? That is, does the order in which they are applied matter. Explain the answer.
T 2 2 0 (8points)FindtheSVDofA,UΣV ,whereA= −1 1 0
Hint: first find AT A, then find λ by solving det(AT A − λI) = 0. Look at this example to find out how to calculate the U and V : https://www.d.umn.edu/~mhampton/m4326svd_example.pdf
(4 points) Scale a vector [x y]T in the plane can be achieved by x′ = sx and y′ = sy
where s is a scalar.
(a) Write out the matrix form of this transformation.
(b) Write out the transformation matrix for homogeneous coordinates.
(c) If the transformation also includes a translation
x′ = sx + tx and y′ = sy + ty
Write out the transformation matrix for homogeneous coordinates.
(d) What is the equivalent of the above matrix for three-dimensional vectors?
(5 points) Find the least square solution x for Ax = b if 20 1
A=−1 1,b=0 02 −1
Verify that the error vector b -Ax is orthogonal to the columns of A.
Matrix K is a discrete, separable 2D filter kernel of size k × k. Assume k is an odd number. After
applying filter K on an image I, we get a resulting image IK.
1
(a) (3 points) Given an image point (x,y), find its value in the resulting image, IK(x,y). Express your answer in terms of I, k, K, x and y. You don’t need to consider the case when (x, y) is near the image boundary.
(b) (5 points) One property of this separable kernel matrix K is that it can be expressed as the product of two vectors g ∈ Rk×1 and h ∈ R1×k, which can also be regarded as two 1D filter kernels. In other words, K = gh. The resulting image we get by first applying g and then applying h to the image I is Igh. Show that IK = Igh.
2 (35 points) Edge detection
Write a function that finds edge intensity and orientation in an image. Display the output of your function for one of the given images in the handout.
function[img1] = myEdgeFilter(img0,sigma) (1)
The function will input a greyscale image (img0) and scalar (sigma). sigma is the standard deviation of the Gaussian smoothing kernel to be used before edge detection. The function will output img1, the edge magnitude image.
First, use your convolution function to smooth out the image with the specified Gaussian kernel. This helps reduce noise and spurious fine edges in the image. The size of the Gaussian filter should depend on sigma (e.g., hsize = 2 * ceil(3 * sigma) + 1).
The edge magnitude image img1 can be calculated from image gradients in the x direction and y direction. To find the image gradient imgx in the x direction, convolve the smoothed image with the x-oriented Sobel filter. Similarly, find image gradient imgy in the y direction by convolving the smoothed image with the y-oriented Sobel filter. You can also output imgx and imgy if needed.
In many cases, the high gradient magnitude region along an edge will be quite thick. For finding lines its best to have edges that are a single pixel wide. Towards this end, make your edge filter implement non-maximum suppression, that is for each pixel look at the two neighboring pixels along the gradient direction and if either of those pixels has a larger gradient magnitude then set the edge magnitude at the center pixel to zero. Map the gradient angle to the closest of 4 cases, where the line is sloped at almost 0o,45o,90o, and 135o. For example, 30o would map to 45o. Please refer to the slides on non-maximum suppression for more details. You do not need to do hysteresis thresholding, but use a simple thresholding.
Your code cannot call on OpenCV edge function, or any other similar functions. You may use the edge detection from library just for comparison and debugging.
Submission
All results should be in a folder called Edge detection. You can use your own images and you should include the original image in the folder if you use your own. Submit your code with the edge detection result after non-maximum suppression, the gradient magnitude image and the gradient orientation image. Include your result from sticks filtering to this folder. Your code should have comments for each function and clear variables.
2
3 (35 points) Sticks filter
To enhance thin and connected line structures, we can use the sticks filter1, originally designed to reduce speckle noise and preserve linear structures. Sticks filtering uses the maximum result from the m oriented filters as the output for the current pixel. Use the maximum response to decide what to do at the central pixel. Compute the difference among all the directions around the region. The chosen orientation, with maximum difference in intensity from the region, aligns with the locally strongest feature. The intensity should be increased along the direction of maximum response, amplifying local tonal differences.
You can create a sticks map T(x,y) using equation 1:
Figure 1: Rasterization of a set of discrete directions, representing 8 line orientations (length n = 5)
The sticks direction T(x,y) determines the maximal contrast response, defined as the maximum differ- ˆ
ence between the average intensity μ(si) of a stick and the average intensity In(x,y) of the neighboring pixels. Parameter n is the length of each stick; there are i sticks. Apply sticks filtering on gradient magnitude image, using n = 5 for i = 8 sticks orientations to enhance the edge segments before applying non-maxima suppression.
Submission
Show the effect of your sticks filtering on your gradient magnitude image. Show the results of the edge detection after applying the sticks filtering on the gradient magnitude. Note that you need to write a function that creates the kernels of the sticks filter. You can use filter2D function in OpenCV for convolution of the sticks filter kernels.
1Line And Boundary Detection In Speckle Images (1997)
3