The R code underlying the functions in this vignette were borrowed with permission from Vinces Gaitan’s blog post: https://www.kaggle.com/vicensgaitan/image-registration-the-r-way/notebook

I have modified the code where necessary in order to make it more pipeline-friendly and function oriented.

Image which will be used throughout this tutorial

Image which will be used throughout this tutorial

We need to pad image a so that it is the same size as image b:

We can then overlay the two images to see how far apart they are:

Step 1: Keypoint Detection

The Harris corner detection algorithm has high values (light pixels) in areas where there are well-defined corners in the image.

Harris corner detector values for the shoeprint image

Harris corner detector values for the shoeprint image

The detector seems to be working fairly well, outlining major features of the shoe print.

Thresholding the image from the previous step at 99% produces the best 1% of keypoints:

The regions are labeled, and region centers are computed for each separately labeled region

Streamlined version

The first two steps can be streamlined using the harris_keypoints() function:

Step 2: Image Orientation

Calculating the dominant orientations for the whole image produces:

Step 3: Feature Detection

For each angle, we pull features from a 40x40 area around the keypoint. These features will be used to identify points of similarity across the two images.

Step 4: Match points

Match points are calculated using the K nearest neighbors algorithm, combined with some thresholding by distance.

match_points <- knn_points(kpf_a, kpf_b, hkp_a$centers, hkp_b$centers, show_plot = T)

Step 6: Image Warping

The homography can be used to warp one image onto the other:

We can then overlay the two images:

Areas that are in the first image only are shown in red; areas in the second image only are shown in blue. Areas in both images are shown in black.