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

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

  • img_np.shape = (1,256,256)
  • out.detach()[0].cpu().numpy().shape = (1,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,full=True,win_size=1,use_sample_covariance=False) 然后我将输出作为数组而不是数字
tomehack110 回答:ValueError: win_size 超出图像范围。如果输入是多通道(彩色)图像,则设置 multichannel=True

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

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

img_np = np.squeeze(img_np)

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


大多数 Python 包采用“Channels-Last”图像格式。
请参阅:A Gentle Introduction to Channels-First and Channels-Last Image Formats

本文链接:https://www.f2er.com/215603.html

大家都在问