Issue with fftconvolve when running SSIM
Hi, when I run your ssim.py example, I get the following error message:
/usr/bin/python2.7 /home/<user>/PycharmProjects/python-ssim/signal_processing/sp/ssim.py
Traceback (most recent call last):
File "/home/<user>/PycharmProjects/python-ssim/signal_processing/sp/ssim.py", line 110, in <module>
sys.exit(main())
File "/home/<user>/PycharmProjects/python-ssim/signal_processing/sp/ssim.py", line 92, in main
ssim_map = ssim(img1, img2)
File "/home/<user>/PycharmProjects/python-ssim/signal_processing/sp/ssim.py", line 34, in ssim
mu1 = signal.fftconvolve(window, img1, mode='valid')
File "/usr/lib/python2.7/dist-packages/scipy/signal/signaltools.py", line 345, in fftconvolve
raise ValueError("in1 and in2 should have the same dimensionality")
ValueError: in1 and in2 should have the same dimensionality
Inside the ssim() method, you are passing the image and a window to the fftconvolve function:
mu1 = signal.fftconvolve(window, img1 mode='valid')
It looks like that img1 and window is swapped, because the 1st param is to be expected to be of the same dimension, or of larger size, accoring to the fftconvolve-docs:
in1 : array_like First input. in2 : array_like Second input. Should have the same number of dimensions as in1; if sizes of in1 and in2 are not equal then in1 has to be the larger array.
But when I try to exchange the window and img params, the ssim() method returns a huge matric (just a bit smaller than the image, due to the VALID padding). I think it should return a scalar representing the metric index, right?
I could solve it!
swapping windows and img1/img2 is the way to go! Mybe the signature of fftconvolve has changed since the library has been written.
What is was missing afterwards is to calculate the mean of the result. Hence, I was looking for the MSSID (mean SSID) that is a scalar value.