Continuing the series of articles on multimedia file processing, this time, I will explain how to check image similarity using python.
Basically, we need SciKit and OpenCV installed.
The code below takes 2 image paths, converts the image colour to gray scale and calculates their structural similarity index measure.
#!/usr/bin/env python3
import cv2
from skimage.measure import compare_ssim
def loadAndGrayScaleImage(path):
image = cv2.imread(path)
cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
grayA = loadAndGrayScaleImage("/home/netto/Desktop/rec/image1.jpg")
grayB = loadAndGrayScaleImage("/home/netto/Desktop/rec/image2.jpg")
(score, diff) = compare_ssim(grayA, grayB, full = True)
diff = (diff * 255).astype("uint8")
print("SSIM: {}".format(score))