1. Right around the corner
Hi again! In this video, we'll learn how to detect another feature of an image, the corners. We'll also look at why this is useful in image processing.
2. Corner detection
Corner detection is an approach used to extract certain types of features and infer the contents of an image.
It's frequently used in motion detection, image registration, video tracking, panorama stitching, 3D modelling, and object recognition.
We saw in the previous video how to detect edges with the Canny Edge detector, and before that with Sobel, in chapter 2. Edges are a type of feature in images.
3. Points of interest
Features are the points of interest which provide rich image content information.
Points of interest are points in the image which are invariant to rotation, translation, intensity, and scale changes. (Basically, robust and reliable). There are different interest points such as corners and edges.
So corner detection is basically detecting (one type of) interest points in an image.
4. Corners
A corner can be defined as the intersection of two edges. Intuitively, it can also be a junction of contours.
We can see some obvious corners in this checkerboard image. Or in this building image on the right.
5. Matching corners
So by detecting corners as interest points, we can match objects from different perspectives. Like in this image, where we detect the corners of the original image on the left and then match them in a downscaled image in the right.
6. Matching corners
Here is another example of corner matching, this time, in a rotated image. We see how the relevant points. are still being matched.
7. Harris corner detector
Harris Corner Detector is a corner detection operator that is widely used in computer vision algorithms.
Here, we see an original image of a building, and on the right we see the corners detected by the Harris algorithm, marked in red.
8. Harris corner detector
Let's use this image of a Japanese gate to work with the Harris detector.
9. Harris corner detector
We can access it by importing the corner_harris function from the feature module of scikit-image.
This function requires grayscale images, so we need to first convert the image from rgb to gray. We can do this with the rgb2gray function we used previously.
This corner_harris function gives us the Harris measure response image, meaning, the resulting image showing only the possible corners that were measured.
So when we show it,
10. Harris corner detector
We see how only some black lines are shown. These are the approximated points where the corners candidates are.
11. Harris corner detector
To find the corners in the measure response image, we can use the corner_peaks function. Which will return the coordinates of the peaks of the possible corners.
Optionally, we can make sure these peak corners are separated by a minimum distance, in pixels, using the min_distance parameter. Here we're setting the minimum distance between corners to 5 pixels.
In this image, a total of 122 corners were found from the measure response image.
12. Corners detected
Here the image is shown with the detected corners marked in red, using a preloaded function that uses matplotlib and the resulting coordinates to do so, similar to show_image.
13. Show image with contours
This function uses the coordinates of the corners to plot cross red marks on it and show it all together.
14. Let's practice!
Now it's your turn to detect useful features!