SIFT Algorithm for Image Comparison

SIFT stands for Scale-Invariant Feature Transform. This is used for comparison of images to check for similarities.

We will check this out step by step with codes and open CV.

Let's first check which images are we going to inspect using SIFT.

Images for Test

These are the two images and it can clearly be seen there are high similarities and I have simply moved my hands' position.

Let's get started. I will first read both the images in grayscale.

The SIFT algorithm is based on Feature Detection and Feature Matching. In simple terms, if you want to understand this, we know an image is stored as a matrix of pixel values. The SIFT algorithm takes small regions of these matrices and performs some mathematical transformations and generates feature vectors which are then compared. For more details, you can check official OpenCV notes here.

For the SIFT algorithm, we need to detect the Keypoints and descriptions for comparison. Let us try to detect those.

Next, we need to compare the Keypoints and Descriptions of the two images. I use the code from Pysource from here for this.

Let's display and check the Mapping between the images.

Correlated Images

The Mapping of both images is shown above. It's not clear. You would need to run the codes to understand it better.

The Advantage of SIFT for comparison :

It is not affected by :

  1. Rotation
  2. Scaling
  3. Image Brightness

Masters Student at Universität Stuttgart, Germany

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store