Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 . Create a new matlab script harrisCorner . m 2 . Read in the Penguins.jpg image from the Windows sample pictures folder using the
Create a new matlab script harrisCornerm
Read in the Penguins.jpg image from the Windows sample pictures folder using the imread command store it in myImage
Convert the image to grayscale using the rgbgray command.
Cast your variable to a double and reassign it to itself.
myImage doublemyImage
Create the x and y derivative filters
dxFilter ; ; ;
dyFilter dxFilter';
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:
myImageDerivativeX
myImageDerivativeY
Now that we have the derivatives, we can calculate A B C from the book.
A myImageDerivativeX
B myImageDerivativeY
C myImageDerivativeX myImageDerivativeY
After you calculate the above you want to apply Gaussian smoothing using a Gaussian Filter
using the conv command. Store each of the smoothed derivatives in: smoothedA, smoothedB,
smoothedC. You can use the following command to create your Gaussian filter:
gaussianFilter fspecialgaussian;
In order to compute the Corner Response Function, we use the following formula define alpha:
cornerResponseFunction A B C alpha A B
Note: Please be sure to use the smoothed versions of A B & C for the above formula
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 isLocalMaxharrisMatrix u v
height sizeharrisMatrix;
width sizeharrisMatrix;
ifu u height v vwidth
myBool false;
else
pix reshapeharrisMatrix heightwidth; return the image as
a dimensional array like the book does
ivheightu;
i vheightu;
ivheightu;
cp pixi;
myBool cp pixi && cp pixi && cp pixi && cp
pixi && cp pixi && cp pixi && cp pixi && cp
pixi;
end
end
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 its value is greater than a
certain threshold and it is a local maximum this is checked by calling the isLocalMax function
you just created
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 && islocalMaxcornerResponseFunction u v
Increment totalCorners by
Add the corner to our list each corner contains u v q
cornerListtotalCornersx u;
cornerListtotalCornersy v;
cornerListtotalCornersq q;
Output the total number of corners that passed the threshold and isLocalMax
NOTE: Use an initial threshold of threshold
Sort the corners by their respective q value in descending order
Create a new variable goodCorners and initialize it to an empty array:
goodCorners ;
Our corner response function may return a lot of corners that can be quite close to each other.
What wed like to do next is define a minimum distance that we want these features corners to
be from each other. Well 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 its sorted and remove other corners that are within the
minimum distance to this point.
First thing we will want to do is initialize our minimum distance:
minDistance ;
Copy and paste the following code into your program and complete the code
whilesizecornerList
c cornerList;
cornerList cornerList:end; remove the first one
goodCorners goodCorners c;
cornersToRemove ;
for i:sizecornerList
if
cornersToRemove cornersToRemove i;
end
end
cornerListcornersToRemove; remove the corners that we found
that are too close
end
Step through the goodCorners list and mark each of the corners in the image with a green cross that is pixels in width and height.
Display the image to the user
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