Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Computer Vision Lab: Harris Corner Detection CSCI 380 Computer Vision 1. Create a new matlab script 'harrisCorner.m 2. Read in the Penguins.jpg image from the
Computer Vision Lab: Harris Corner Detection CSCI 380 Computer Vision 1. Create a new matlab script 'harrisCorner.m 2. Read in the Penguins.jpg image from the Windows sample pictures folder using the imread 3. 4. command (store it in 'mylmage') Convert the image to grayscale using the rgb2gray command. Cast your variable to a double and reassign it to itself. mylmage double(mylmage) 5. Create the x and y derivative filters dyFilterdxFilter 6. Create an X derivative image and a Y derivative image by convolving the appropriate filters with the grayscale penguin image. Use the following names for your new images: mylmageDerivativex mylmageDerivativeY 7. Now that we have the derivatives, we can calculate A, B, C from the book. A mylmageDerivativeX.2 B mylmageDerivativeY.2 C mylmageDerivativeX.* mylmageDerivativeY After you calculate the above you want to apply Gaussian smoothing (using a Gaussian Filter) using the conv2 command. Store each of the smoothed derivatives in: smoothedA, smoothedB, smoothedC. You can use the following command to create your Gaussian filter: 8. gaussianFilterfspecial('gaussian'); 9 In order to compute the Corner Response Function, we use the following formula (define alpha 0.04): cornerResponseFunction A. B-c alpha (AB) **Note: Please be sure to use the smoothed versions of A, B & C for the above formula 10. Next we need to create our isLocalMax function. The Corner Response function usually will have several 'corners' all that appear in the same area. This function will help us to determine which is the best corner for our program to use. Use the following code for isLocalMax: function [myBool] = isLocalMax (harrisMatrix, u, v) height = size (harrisMatrix, 1) ; widthsize (harrisMatrix, 2) if (u = height II v=width) else myBool false: pix = reshape (harrisMatrix, 10 = (v-1)"height+u; i2 = (v+1) *height+u; cp = pix (11); height * width, 1); %return the image as a 1 dimensional array (like the book does) pix (i1-1)&&cp pix (12+1) pix (i1+1) && cp > pix (12-1)&&cp > pix(12)&&cp end end 11. We use this function to help us determine the best corners to use. We do this by stepping through our cornerResponseFunction matrix and check to see if it's value is greater than a certain threshold and it is a local maximum (this is checked by calling the isLocalMax function you just created) 12. Implement the pseudo code listed below in order to perform the above task: Initialize totalCorners to zero For each u For each v If (cornerResponseFunction (u, v)> threshold && islocalMax(cornerResponseFunction, u, v) Increment totalCorners by 1. Add the corner to our list (each corner contains u, v, q) cornerList (tota!Corners) x = u; cornerList (totalCormers) .y v cornerList (totalCorners).q q Output the total number of corners that passed the threshold and isLocal Max *NOTE: Use an initial threshold of 200000 (threshold 200000) 13. Sort the corners by their respective q value in descending order 14. Create a new variable goodCorners and initialize it to an empty array: goodCorners[ 15. Our corner response function may return a lot of corners that can be quite close to each other. What we'd like to do next is define a minimum distance that we want these features (corners) to be from each other. We'll then want to step through each of our corners and remove the ones that are close too close to each other. We do this by starting with the strongest corner that we found (the first one in the list because it's sorted) and remove other corners that are within the minimum distance to this point. 16. First thing we will want to do is initialize our minimum distance: minDistance10: 17. Copy and paste the following code into your program and complete the code while (size (cornerList,2) > 0) cl-cornerList (1) cornerList cornerList (2 : end); goodCorners[goodCorners cl]; cornersToRemove = []; %remove the first one for i-2:size (cornerList,2) if( complete code>>>>) cornersToRemove-[cornersToRemove i] end end corne rList (corne rsToRemove) = []; %remove the corners that we found that are too close end 18. Step through the goodCorners list and mark each of the corners in the image with a green 'cross' or x that is 3 pixels in width and height. 19. Display the image to the user, it should look similar to: Figure If you complete early you may: 1. Play with modifying the 'minDistance', threshold, and k values. Observe the changes made to the output Implement the above lab using the 'corners' command. Instead of representing the corners in the image with a cross or x, numerically represent the corner in the image. (ie the best corner would have a '1', the second best would have a '2). 2. 3. Computer Vision Lab: Harris Corner Detection CSCI 380 Computer Vision 1. Create a new matlab script 'harrisCorner.m 2. Read in the Penguins.jpg image from the Windows sample pictures folder using the imread 3. 4. command (store it in 'mylmage') Convert the image to grayscale using the rgb2gray command. Cast your variable to a double and reassign it to itself. mylmage double(mylmage) 5. Create the x and y derivative filters dyFilterdxFilter 6. Create an X derivative image and a Y derivative image by convolving the appropriate filters with the grayscale penguin image. Use the following names for your new images: mylmageDerivativex mylmageDerivativeY 7. Now that we have the derivatives, we can calculate A, B, C from the book. A mylmageDerivativeX.2 B mylmageDerivativeY.2 C mylmageDerivativeX.* mylmageDerivativeY After you calculate the above you want to apply Gaussian smoothing (using a Gaussian Filter) using the conv2 command. Store each of the smoothed derivatives in: smoothedA, smoothedB, smoothedC. You can use the following command to create your Gaussian filter: 8. gaussianFilterfspecial('gaussian'); 9 In order to compute the Corner Response Function, we use the following formula (define alpha 0.04): cornerResponseFunction A. B-c alpha (AB) **Note: Please be sure to use the smoothed versions of A, B & C for the above formula 10. Next we need to create our isLocalMax function. The Corner Response function usually will have several 'corners' all that appear in the same area. This function will help us to determine which is the best corner for our program to use. Use the following code for isLocalMax: function [myBool] = isLocalMax (harrisMatrix, u, v) height = size (harrisMatrix, 1) ; widthsize (harrisMatrix, 2) if (u = height II v=width) else myBool false: pix = reshape (harrisMatrix, 10 = (v-1)"height+u; i2 = (v+1) *height+u; cp = pix (11); height * width, 1); %return the image as a 1 dimensional array (like the book does) pix (i1-1)&&cp pix (12+1) pix (i1+1) && cp > pix (12-1)&&cp > pix(12)&&cp end end 11. We use this function to help us determine the best corners to use. We do this by stepping through our cornerResponseFunction matrix and check to see if it's value is greater than a certain threshold and it is a local maximum (this is checked by calling the isLocalMax function you just created) 12. Implement the pseudo code listed below in order to perform the above task: Initialize totalCorners to zero For each u For each v If (cornerResponseFunction (u, v)> threshold && islocalMax(cornerResponseFunction, u, v) Increment totalCorners by 1. Add the corner to our list (each corner contains u, v, q) cornerList (tota!Corners) x = u; cornerList (totalCormers) .y v cornerList (totalCorners).q q Output the total number of corners that passed the threshold and isLocal Max *NOTE: Use an initial threshold of 200000 (threshold 200000) 13. Sort the corners by their respective q value in descending order 14. Create a new variable goodCorners and initialize it to an empty array: goodCorners[ 15. Our corner response function may return a lot of corners that can be quite close to each other. What we'd like to do next is define a minimum distance that we want these features (corners) to be from each other. We'll then want to step through each of our corners and remove the ones that are close too close to each other. We do this by starting with the strongest corner that we found (the first one in the list because it's sorted) and remove other corners that are within the minimum distance to this point. 16. First thing we will want to do is initialize our minimum distance: minDistance10: 17. Copy and paste the following code into your program and complete the code while (size (cornerList,2) > 0) cl-cornerList (1) cornerList cornerList (2 : end); goodCorners[goodCorners cl]; cornersToRemove = []; %remove the first one for i-2:size (cornerList,2) if( complete code>>>>) cornersToRemove-[cornersToRemove i] end end corne rList (corne rsToRemove) = []; %remove the corners that we found that are too close end 18. Step through the goodCorners list and mark each of the corners in the image with a green 'cross' or x that is 3 pixels in width and height. 19. Display the image to the user, it should look similar to: Figure If you complete early you may: 1. Play with modifying the 'minDistance', threshold, and k values. Observe the changes made to the output Implement the above lab using the 'corners' command. Instead of representing the corners in the image with a cross or x, numerically represent the corner in the image. (ie the best corner would have a '1', the second best would have a '2). 2. 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started