【图像处理】

踩坑skimage.transform.resize


问题描述:
重新写模型的测试代码时,读取图片的时候没有使用skimage.transform.resize方法,导致模型的输出结果突破天际。
问题解决:
https://blog.csdn.net/agoodboy1997/article/details/112476841
skimage.transform.resize会顺便把图片的像素归一化缩放到(0,1)区间内,

source_image = imageio.imread(opt.source_image)
# 加入以下这句,在之后转化tensor时就不用归一化了,不然直接转换tensor,数值在[0,255]之间,
source_image = resize(source_image, opt.img_shape)[..., :3]
source_image = torch.tensor(source_image[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2)

看到skimage.transform.resize的源码

def resize(image, output_shape, order=1, mode='reflect', cval=0, clip=True,
           preserve_range=False, anti_aliasing=True, anti_aliasing_sigma=None):
preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input
        image is converted according to the conventions of `img_as_float`.
        Also see https://scikit-image.org/docs/dev/user_guide/data_types.html

通过设置preserve_range=True就可以保持原来的模式了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值