jterrace / pyssim

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

Always get a 1.0 value #3

Closed jossi closed 10 years ago

jossi commented 10 years ago

No matter what two images I use the SSIM returned is always 1.0

jterrace commented 10 years ago

Have you tried it with the test images?

jterrace commented 10 years ago

Working for me:

$ pyssim test-images/test1-1.png test-images/test1-1.png 
1.0

$ pyssim test-images/test1-1.png test-images/test1-2.png 
0.998107055283

$ pyssim test-images/test1-1.png test-images/test2-1.png 
0.673010007986

$ pyssim test-images/test1-1.png test-images/test2-2.png 
0.648811237728
jossi commented 10 years ago

I am using 32-bit PNGs so maybe that is the problem? I will try with the test images

jossi commented 10 years ago

bash-3.2$ pyssim test1-1.png test1-2.png 0.998107055283

that works. But not my images.

jterrace commented 10 years ago

Could you post your images?

jossi commented 10 years ago

car_imagewarp car_source

Note that the images are visually identical, but not bit-by-bit identical. Using a similarity index ImageMagik script I get an index of 0.99884

http://www.fmwconcepts.com/imagemagick/similar/index.php

jterrace commented 10 years ago

I see what's happening. Your images are RGBA and the alpha channel is all 255 values and all transparent pixels are ignored.

jossi commented 10 years ago

Thanks for the prompt response. What to do then? Convert the PNGs to another format?

jossi commented 10 years ago

Converting the PNGs from 32-bit to 24-bit resolves it.

$ pyssim Car_source.png Car_ImageWarp.png 0.996363163123

Thank you!

jterrace commented 10 years ago

I just looked up the PNG spec though and it says this:

An alpha value of zero represents full transparency, and a value of (2^bitdepth)-1 represents a fully opaque pixel.

So I'm thinking that we're using the wrong value for transparency. We should treat 0 as transparent and 255 as opaque.

jossi commented 10 years ago

Indeed...

Sent from my iPad

On Oct 10, 2013, at 8:22 PM, Jeff Terrace notifications@github.com wrote:

So I'm thinking that we're using the wrong value for transparency. We should treat 0 as transparent and 255 as opaque.

jterrace commented 10 years ago

Closing this and opened #5 instead