FAST corner detection

Corner detection is the process of extracting features from an image. 

The JuliaFeatures package implements Features from accelerated segment test (FAST). FAST is a computationally efficient corner detector and is suitable for real-time video analysis and a processing algorithm proposed by Edward Rosten and Tom Drummond. You can call the FAST algorithm by using the fastcorners function.

Because of its outstanding performance, quality, and simple configuration, we will be using FAST in all of the following examples. FAST works by scanning the entire image for object corners. It uses a circle of 16 pixels to evaluate whether a point is a corner. The process is also configured by two additional parameters:

The number of contiguous pixels (N) is used to compare whether the pixels in the circle are brighter or darker than the candidate point. N is usually fixed to 12, and the threshold value from 0.05 to X defines the number of features identified. The higher the value you set for a threshold parameter, the fewer features will get returned.

Let's try rerunning the FAST algorithm on one of the images of a cat, which was used earlier to see how the number of corners changes with a different value for a threshold parameter.

We will load the image, resize, and convert it to grayscale. We will also apply the fastcorners function with three different sets of threshold values, such as 0.15, 0.25, and 0.35, and compare the results. The code for it is as follows:

using Images, ImageFeatures

img = Gray.(load("sample-images/cat-3417184_640.jpg"))
img_f = Float16.(restrict(img))

new_img = Gray.(hcat(
img_f .* (~fastcorners(img_f, 12, 0.15)),
img_f .* (~fastcorners(img_f, 12, 0.25)),
img_f .* (~fastcorners(img_f, 12, 0.35))
))

imshow(new_img)

The trick we used in the preceding code when we multiplied the numeric representation of an image stored in the img_f variable by a negation of the result, the fastcorners function, allows us to place features on an image quickly. The result of running the code is shown in the following images:

You should be able to see black dots on the cat. Those dots represent corners identified by the fastcorners function. They are used by other algorithms to match identical objects. You should be able to see black dots around the cat. Those dots represent corners identified by FAST. They are used by other algorithms to match identical objects or parts of the area.

In case of processing images with text, FAST can help you to identify areas that contain content. This is shown in the following code:

using Images, ImageFeatures

img = Gray.(load("sample-images/newspaper-37782_640.png"))
img_f = Float16.(img)

new_img = Gray.(hcat(
img_f,
Float16.(img_f) .* (~fastcorners(img_f, 12, 0.15))
))

imshow(new_img)

In the following image, you can see the comparison between the original image and a single run of FAST with a threshold of 0.15. The black dots are all over the letters:

Let's move on and see how the results from FAST can be used to match images.