ValueError:win_size 超出图像范围。如果输入是多通道(彩色)图像,则设置 multichannel=True

2 python image-processing ssim scikit-image

我正在尝试计算两个图像的 SSIM 值,但出现错误。

  • img_np.shape = (1, 256, 256)
  • out.detach()[0].cpu().numpy().shape = (1, 256, 256)
  • out是从模型生成的输出图像

当我尝试查找 SSIM 值时ssim_ = compare_ssim(img_np, out.detach().cpu().numpy()[0])出现错误ValueError: win_size exceeds image extent. If the input is a multichannel (color) image, set multichannel=True.

我努力了

  • ssim_ = compare_ssim(img_np, out.detach().cpu().numpy()[0], full=True)但同样的错误
  • ssim_ = compare_ssim(img_np, out.detach().cpu().numpy()[0], full=True, win_size=1,use_sample_covariance=False)然后我得到的输出是数组而不是数字

Rot*_*tem 5

形状 (1, 256, 256) 被解释为具有 1 行、256 列和 256 个颜色通道的图像。

您可以使用numpy.squeeze来删除冗余维度:

img_np = np.squeeze(img_np)
Run Code Online (Sandbox Code Playgroud)

新形状将是 (256, 256) - 有效灰度图像的形状。


大多数 Python 包都采用“Channels-Last”图像格式。
请参阅:通道优先和通道最后图像格式的简要介绍