There are situations where we need to measure the similarity between two images. For example, when we have an original image and few other images with lower quality, we might need to identify when one is mostly similar to the original image. Bit-wise comparison of the image pixels is not applicable in this kind of scenarios. We need something more sophisticated. Structural similarity index (SSIM) is such a method. It provides a value between 1 and 0 when comparing two images. If two images are exactly similar the SSIM becomes 1. If they are totally different, SSIM becomes 0.
Following Python program implements SSIM to compare between to images. Since we need some extra python libraries for this code to run, we should install following libraries on Ubuntu Linux.
sudo apt install python-skimage
sudo apt install python-opencv
SSIM calculation code is as follows.