Menu

Measuring SSIM and DSSIM

Let us begin by understanding SSIM and DSSIM before moving to measuring using these metrics.

SSIM -

Structural Similarity Index Measure (SSIM) is a method to measure similarity between two images.

Let us assume we received a high quality image from a photoshoot for the launch of a popular smartphone, this image is 50 MB. Now to publish it on the website we will likely compress it to a much smaller size for easier consumption over all types of connections, devices etc. We have covered why image/video compression is critical in detail in some of the previous blogs, kindly read them if you are interested in this topic. Assuming the compressed output is 350 KB SSIM can come in handy to measure how similar the two copies of the same image are.

DSSIM -

Structural Dissimilarity (DSSIM) as the name suggests is the exact opposite.

Why should I bother measuring similarity using these techniques ?

Extremely helpful in image compression workflows which are critical to applications which are either local to a device or delivered over internet. These techniques help measure the difference in perceptual quality of the source and the compressed version of an image. Most popular image compression tools deploy this technique to find the right balance between byte reduction and visual quality. 

SSIM and DSSIM are methods that helps in predicting the perceptual quality of an image. These are perception based techniques that take into consideration image degradation as perceived change in structural information while also incorporating luminance and chrominance data unlike other techniques like PSNR which are error based.

The earlier version or the predecessor to SSIM was UQI (Universal Quality Index), developed by Zhou Wang and Alan Bovik in 2001. This method evolved into SSIM with their collaboration with Hamid Sheikh and Eero Simoncelli.

There are multiple tools that help compute a SSIM/DSSIM score between two reference images. All these variants use algorithms that are trying to approximate human vision. I have used a couple variants below for my tests but you can browse the internet to find the one that best suits your needs.

Now let us take this beautiful image of a park with plenty of trees, the pristine/source file downloaded from the internet is a JPEG encoded at quality 92. Let me first convert this to a modern format - AVIF, while i perform this conversion what i also do is convert the output to quality 75. Quality levels for each format differ from each other (I intend to cover this in detail in a different blog). 

Original Image (JPEG at q92) - 



Converted to AVIF at q75 -


Now lets compare these two with both SSIM and DSSIM.

With SSIM the values go from 0 - 1 where 1 means identical images and 0 means the two images have no match at all. It is the exact opposite for DSSIM

To demonstrate this I took the same image and compared with both techniques, result below -

magick compare -metric SSIM park.jpg park.jpg null: 

1%

magick compare -metric DSSIM park.jpg park.jpg null:

0%     


Now then let us compare JPEG encoded at q92 and its converted AVIF output encoded at q75 -

magick compare -metric SSIM park.jpg park-75.avif null: 

0.981224%

magick compare -metric DSSIM park.jpg park-75.avif null:

0.00938778%


Now the above comparison tells us so much about AVIF as a more efficient modern image codec. The transcoded AVIF output at q75 is only 985 KB compared to the original JPEG at 1.4 MB. Yet the SSIM and DSSIM scores show the two images are almost identical, extremely hard to differentiate between.

Now let us take another image which is completely different to the above image of the exact same dimensions and compare them -

Original Image (JPEG at q92) - 

Comparison Image -

Results below -

magick compare -metric SSIM park.jpg park.png null:

0.00412148%

magick compare -metric DSSIM park.jpg park.png null:

0.497939% 


As you can see from the results the SSIM score is a few decimal points close to 0, 0 means no similarity between the two images per this metric. Now when we repeat the same with the DSSIM metric we do see a high enough number but not close to 1 which i expected for DSSIM, 1 in DSSIM means completely different or no similarity.

I continue to troubleshoot why the DSSIM results came out this way, for now i have used Fred's SSIM/DSSIM script. He has an amazing site where he provides ImageMagick scripts. Site link - http://www.fmwconcepts.com/imagemagick/ssim/index.php 

Here are the results below using Fred's script. The numbers here are quite accurate for both SSIM and DSSIM -

bash ./ssim.sh park.jpg park.png                   

ssim=0.00412 dssim=0.996


You can print the differences(SSIM/DSSIM) to a PNG if you would like to visualize them. Example below -

bash ./ssim.sh park.jpg park.png difference-fred.png    

ssim=0.00412 dssim=0.996


SSIM/DSSIM image -

Ok this scary looking SSIM/DSSIM image brings us to the end of this blog. Hope you enjoyed reading this one.

0 Comments


Add Comment Your email address will not be published.