I am trying to calculate SSIM value for two images but I am getting error.
img_np.shape = (1, 256, 256)
out.detach()[0].cpu().numpy().shape = (1, 256, 256)
out
is the output image generated from the modelwhen i try to find SSIM value ssim_ = compare_ssim(img_np, out.detach().cpu().numpy()[0])
i am having error ValueError: win_size exceeds image extent. If the input is a multichannel (color) image, set multichannel=True.
I have tried
ssim_ = compare_ssim(img_np, out.detach().cpu().numpy()[0], full=True)
but same errorssim_ = compare_ssim(img_np, out.detach().cpu().numpy()[0], full=True, win_size=1,use_sample_covariance=False)
then i am getting output as an array not an numberThe shape (1, 256, 256) is interpreted as an image with 1 row, 256 columns and 256 color channels.
You may use numpy.squeeze for removing the redundant dimension:
img_np = np.squeeze(img_np)
The new shape is going to be (256, 256) - shape of a valid Grayscale image.
Most Python packages assumes "Channels-Last" image format.
See: A Gentle Introduction to Channels-First and Channels-Last Image Formats.