jterrace / pyssim

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

Normalize gaussian kernel #16

Closed w-m closed 8 years ago

w-m commented 8 years ago

Resolves #9.

The discrete gaussian kernel created in this helper function does not perfectly sum up to 1. Especially when sigma < 1, the sum of the kernel will be larger than 1, at around 1.01.

Trying to compute the variance with the algebraic formula creates a second term that is larger than the first term with a kernel like this. The variance becomes negative, and the computed SSIM overflows.

Pylint checked.

The SSIM computed for the images reported in issue #9 is now always below 1.

The results of the tests are now slightly different:

test-images/test1-1.png - test-images/test1-1.png: 1 test-images/test1-1.png - test-images/test1-2.png: 0.9980119 test-images/test1-1.png - test-images/test2-1.png: 0.6726952 test-images/test1-1.png - test-images/test2-2.png: 0.6485879 test-images/test1-1.png - test-images/test3-cro.jpg: 0.2306724 test-images/test1-1.png - test-images/test3-lig.jpg: 0.2919399 test-images/test1-1.png - test-images/test3-orig.jpg: 0.2276495 test-images/test1-1.png - test-images/test3-rot.jpg: 0.2387026

I'm not sure there is any single reference implementation these values should be checked against? Or a test set of images? Trying to compare with the implementation in scikit-image yields very different results already in the current implementation.

jterrace commented 8 years ago

Thanks for fixing this! It looks like Travis CI might be broken?

You can go ahead an update the test values.

jterrace commented 8 years ago

Travis CI is healthy again. If you rebase your changes with master and update the tests, things should be passing.

w-m commented 8 years ago

Rebased on master. For updating the test values I amended the commit as the new values are directly associated with the change in the code.

jterrace commented 8 years ago

Thanks again!