Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Structural Similarity Index (SSIM) in Python (Multichannel error)

I want to calculate the Structural Similarity Index (SSIM) between a generated and a target image (that have been picked randomly from an array of images).

This is what I have tried-

from skimage.metrics import structural_similarity as ssim

print(tar_image.shape)
print(gen_image.shape)

ssim_skimg = ssim(tar_image, gen_image,
                  data_range = gen_image.max() - gen_image.min(), 
                  multichannel = True)

print("SSIM: based on scikit-image = ", ssim_skimg)

But I am getting this output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(1, 128, 128, 3)
(1, 128, 128, 3)

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

Can someone please tell me where I am going wrong and how I can fix this problem?

>Solution :

You have 3 channel images, so you should use the multichannel = True argument.

Also you should remove the first dimension of your images to get (128,128,3) shapes

import numpy as np
from skimage.metrics import structural_similarity as ssim 

tar_image = np.zeros((128, 128, 3))
gen_image = np.zeros((128, 128, 3))

ssim_skimg = ssim(tar_image, gen_image, multichannel = True)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading