jterrace / pyssim

A Python module for computing the Structural Similarity Image Metric (SSIM)
MIT License
340 stars 62 forks source link

I got SSIM = 1 for two quite different images #23

Open ghost opened 8 years ago

ghost commented 8 years ago

Hi

I have been using the library for SSIM in C# http://www.lomont.org/Software/Misc/SSIM/SSIM.html. Now I want to use this more advanced library that handles both SSIM and CW-SSIM. I have a windows 10 machine with python 2.7, with numpy and scipy. However, by doing some regression, I notice quite a critical difference. For two images that I have been using in my research (solar sunspot two dimensional neural network forecasting), the c# code gives me 0.683600449, while the python one give me 1. Clearly the pictures are different, so it should give SSIM<1.

pyssim magnetic_butterfly_forecast.png magnetic_butterfly_original.png 1

I also tested with option --cw and that seems to work and gives me

pyssim magnetic_butterfly_forecast.png magnetic_butterfly_original.png --cw 0.8519043

I am using:

Windows 10 numpy (1.11.1+mkl) Pillow (3.3.1) pip (8.1.1) pyssim (0.3) scipy (0.18.0) setuptools (20.10.1)

I have attached the two images to allow you guys to debug.

Any idea what I am doing wrong or is there any issue?

Thanks

Eurico Covas

magnetic_butterfly_forecast magnetic_butterfly_original
ghost commented 8 years ago

Hi

One more thing, my images are 24BPP, does that matter? If reduce to 8 bits and it now works...

Eurico

ghost commented 8 years ago

Hi @euricocovas ,

I commented out these two lines from ssim/ssimlib.py:

self.img_gray, self.img_alpha = to_grayscale(self.img)
# if self.img_alpha is not None:
#     self.img_gray[self.img_alpha == 255] = 0

Now it outputs 0.8907.

If you construct SSIMImage object with these two lines, the image arrays in grayscale based on the images you supplied are 0s everywhere. Not sure about the reasons yet.

jterrace commented 8 years ago

Thanks for the report. Sorry I haven't had a chance to take a look yet. Thanks for looking @jz0627

Can you try running self.img_gray.show() and self.img_alpha.show() after the call to to_grayscale? Is the alpha channel looking correct?

I'm guessing this is a dupe of #5