python – Which SSIM is correct : skimage.metrics.structural_similarity()?
Ive opened an issue on the scikit-image Github repository and I got an answer. Here the answer, Ive change nothing to the answer and you can find it here:
I think the primary issue here is that the way you computed images from PIL results in floating point images, but ones where the values are in the range [0, 255.0]. skimage will assume a range [-1.0, 1.0] for data_range when the input is floating-point, so you will need to manually specify data_range=255.
Also, see the Notes section of the docstring for recommendations to set gaussian_weights=True, sigma=1.5 to more closely match the Matlab script by Wang et. al. (I think recent Matlab also has its own built-in SSIM implementation, but I havent tried comparing to that case and dont know if it is exactly the same).
ref_image = np.asfarray(Image.open(avion.bmp).convert(L)) impaired_image = np.asfarray(Image.open(avion_jpeg_r5.bmp).convert(L)) structural_similarity(ref_image, impaired_image, multichannel=True, gaussian_weights=True, sigma=1.5, use_sample_covariance=False, data_range=255)
0.8292when I tried it.
Alternatively you can use skimage.io.imread and rgb2gray to read in the data and convert it to grayscale. In that case, values will have been scaled within [0, 1.0] for you and data_range should be set to 1.0.
from skimage.io import imread from skimage.color import rgb2gray ref_image = imread(avion.bmp) ref_image = rgb2gray(ref_image) impaired_image = imread(avion_jpeg_r5.bmp) impaired_image = rgb2gray(impaired_image) structural_similarity(ref_image, impaired_image, multichannel=True, gaussian_weights=True, sigma=1.5, use_sample_covariance=False, data_range=1.0)
I think the small difference between the two cases above is probably due to
rgb2gray using a different luminance conversion than PILs