0

I am trying to calculate SSIM for 2 numpy arrays using structural_similarity from skimage.metrics:

ydata.shape = (3, 230)
ydata3.shape = (3, 230)

When I try to calculate SSIM:

mse_value = mean_squared_error(ydata, ydata3)
ssim_value = ssim(ydata, ydata3, data_range=ydata3.max() - ydata.min())**

I have the error:

"win_size exceeds image extent.  If the input is a multichannel "
ValueError: win_size exceeds image extent.  If the input is a multichannel (color) image, set multichannel=True.**

I tried to set multichannel = True but it does not work.

ssm: ssim_value = ssim(ydata, ydata3, multichannel= True, data_range=ydata3.max() - ydata.min())

I also tried to increase the dimension of the array with:

ydata = ydata.reshape(ydata.shape[0], ydata.shape[1], 1)

The new shape of the arrays is ((3, 230, 1), (3, 230, 1)). However it keeps showing the same error

I tried also flatten but it changes a lot my results.

Any suggestions or help?

  • By _"I tried `multichannel = True`"_, do you mean you set a variable `multichannel` in your global scope to `True`? It very likely means you need to set `ssim.multichannel = True` or some attribute of the _module you're using_. (IDK what that is) – Pranav Hosangadi Dec 07 '22 at 17:34
  • Does this answer your question? [I want to get the SSIM when comparing two images in python](https://stackoverflow.com/questions/62585571/i-want-to-get-the-ssim-when-comparing-two-images-in-python) – Pranav Hosangadi Dec 07 '22 at 17:35
  • @PranavHosangadi Yes, I set multichannel=True when calculating ssm: ```ssim_value = ssim(ydata, ydata3, multichannel= True, data_range=ydata3.max() - ydata.min())```. I am using structural_similarity from skimage.metrics. Thank you for the answer suggestion, but I tried already to increase the dimension of the array with ```ydata = ydata.reshape(ydata.shape[0], ydata.shape[1], 1)``` . The new shape of the arrays is ```((3, 230, 1), (3, 230, 1))``` . However it keeps showing the same error. And they are float datatype. – Estefania Lopez Dec 07 '22 at 23:54
  • I'm not familiar with the skimage library, so I wouldn't be able to answer your question. Just want to reconfirm that you passed the `multichannel=True` argument _to your `ssim` function call_, and still got the same error? Because in the code you show in your question, you don't pass that argument. – Pranav Hosangadi Dec 07 '22 at 23:56
  • @PranavHosangadi Thank you . I passed ```multichannel= True```, however it seems that it is only accepted when the shape is > 7 and it is 3 in one dimension, for example, if the shape is (9,230, 1), ```multichannel= True``` is passed and I do not have errors, however, when I increase the value of the dimension the results are so incongruous for what I am trying to compare. – Estefania Lopez Dec 08 '22 at 00:10

0 Answers0