The Structural Similarity Index (SSIM) is a perceptual metric that quantifies image quality degradation* caused by processing such as data compression or by losses in data transmission. It is a full reference metric that requires two images from the same image capture— a reference image and a processed image. The processed image is typically compressed. It may, for example, be obtained by saving a reference image as a JPEG (at any quality level) then reading it back in. SSIM is best known in the video industry, but has strong applications for still photography. Any image may be used, including those of Imatest test patterns such as Spilled Coins or Log F-Contrast.1

Warning

*SSIM actually measures the perceptual difference between two similar images. It cannot judge which of the two is better: that must be inferred from knowing which is the “original” and which has been subjected to additional processing such as data compression.

Using OpenCV library and structural_similarity from skimage.metrics, I adjusted an old Python program2 to calculate the similarity:

import cv2 as cv
from skimage.metrics import structural_similarity as ssim
 
first = cv.imread("suspicious.jpg")
 
second = cv.imread("original.jpg")
 
first = cv.resize(first, (2576, 1125))
second = cv.resize(second, (2576, 1125))
first = cv.cvtColor(first, cv.COLOR_BGR2GRAY)
second = cv.cvtColor(second, cv.COLOR_BGR2GRAY)
s = ssim(first, second)
 
print(s)
 
# Output
0.9970312534804193

Footnotes

  1. https://www.imatest.com/docs/ssim/

  2. https://github.com/asanka-code/ssim-calculator