使用structural_similarity计算两幅图像之间的SSIM指标时窗口大小报错。

当使用报错structural_similarity计算两幅图像之间的SSIM指标时窗口大小报错如下:

ValueError: win_size exceeds image extent. Either ensure that your images are at least 7x7; or pass win_size explicitly in the function call, with an odd value less than or equal to the smaller side of your images. If your images are multichannel (with color channels), set channel_axis to the axis number corresponding to the channels.

它翻译为中文大概意思是:这个报错是由于窗口大小 win_size 超出了图像尺寸范围所致。建议确保图像至少为 7x7 大小,或者在调用函数时显式传递一个奇数值小于或等于图像较小一侧尺寸的 win_size 参数。如果你的图像是多通道图像(带有颜色通道),还需要设置 channel_axis 参数,指定对应通道的轴编号。

这有可能是因为你使用较新版本的scikit-image这个库计算两图片ssim,在在1.0.版本之后将会移除参数multichannel,将其替换成channel_axis参数,若此时你依然使用multichannel就有可能报错。

比如使用以下代码便会报错

from skimage.metrics import  structural_similarity

    def ssim(img1, img2):
    return structural_similarity(img1, img2, multichannel=(len(img1.shape) == 3), data_range=check_img_data_range(img1))

可以改成,即可运行成功

return structural_similarity(img1, img2, channel_axis=-1, data_range=check_img_data_range(img1))

这是因为,在1.0.版本之后将会移除参数multichannel,将其替换成channel_axis参数,其中,对channel_axis的描述为: 

channel_axis : int or None, optional
    If None, the image is assumed to be a grayscale (single channel) image.
    Otherwise, this parameter indicates which axis of the array corresponds
    to channels.

它的意思就是这个参数指定的是数组里面通道数的axis,为None的话默认是计算灰度图像的ssim。
因此,对三通道数组进行计算SSIM时,例如数组维度为(H, W, C),此时指定channel_axis=-1即可,不用再指定multichannel=True

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值