SSIM calculation for RGB images

21 次查看(过去 30 天)
What is the difference in the operation of SSIM function on RGB data when using ssim(a, b, 'DataFormat', 'SSC') and ssim(a, b)? The first one, averaged across all three channels, gives ~0.45 (the same as calculating SSIM for all three channels separately and then averaging the result), whereas the second gives a single value of around 0.76. I'm using Matlab r2023b.

回答(1 个)

Raghava S N
Raghava S N 2024-8-6
Hi,
There is an operational difference in the function “ssim” when called without passing the name-value argument “DataFormat”. The difference in the output values as described in your query arises because a 2-D RGB image is treated differently in these two scenarios.
When no optional parameters are provided, the function processes the image in the default manner. This is equivalent to passing the value “SSS” as the “DataFormat” parameter. This signifies that the image has 3 spatial dimensions.
ref = imread("peppers.png");%load 2D RGB Image
A = imgaussfilt(ref,1.5,"FilterSize",11,"Padding","replicate");%create a blurred copy
montage({ref A})%plot the 2 images side-by-side
title("Reference Image (Left) vs. Blurred Image (Right)")
[ssimVal,ssimMap] = ssim(A,ref);%default operation
disp(ssimVal)
0.9845
[ssimVal,ssimMap] = ssim(A,ref, 'DataFormat', 'SSS');%call the function with 'DataFormat' set to 'SSS'
disp(ssimVal)
0.9845
However, when the “DataFormat” argument is set to “SSC”, the function interprets that the image in question has 2 spatial dimensions and 1 channel dimension. This is the recommended format for processing 2-D RGB images as per MATLAB documentation - https://www.mathworks.com/help/releases/R2023b/images/ref/ssim.html?searchHighlight=ssim&s_tid=doc_srchtitle#:~:text=Example%3A%20%22SSC%22%20indicates%20that%20the%20array%20has%20two%20spatial%20dimensions%20and%20one%20channel%20dimension%2C%20appropriate%20for%202%2DD%20RGB%20image%20data. Hence, there is a difference in the output value, as seen here:
[ssimVal,ssimMap] = ssim(A,ref, 'DataFormat', 'SSC');%call the function with 'DataFormat' set to 'SSC'
disp(mean(ssimVal))
0.9169
For more information on the function ssim, please refer to this documentation link -
Hope this helps!
Raghava

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by