【问题标题】:Is there a better way to resize an image that is in the form of a numpy array?有没有更好的方法来调整 numpy 数组形式的图像的大小?
【发布时间】:2020-07-09 00:26:53
【问题描述】:

我是神经网络的新手,一直在练习图像预处理。我正在尝试调整 numpy 数组形式的图像大小,这是我目前的方法:

# using tensorflow, resize the image
im = tf.image.resize(img_as_array, [299, 299])

# then use .eval() which returns a numpy array in the size I want
im_arr = im.eval(session=tf.compat.v1.Session())

有没有更好的方法来做到这一点?

【问题讨论】:

    标签: numpy tensorflow image-preprocessing


    【解决方案1】:

    为避免在tf.tensornp.ndarray 张量数据类型之间进行转换,您可以使用skimage (scikit-image) 使用以下代码段直接在np.ndarray 对象上调整图像大小:

    import skimage.transform
    
    kwargs = dict(output_shape=self._size, mode='edge', order=1, preserve_range=True)
    im = skimage.transform.resize(im, **kwargs).astype(im.dtype)
    

    要安装skimage,请按照此处的安装说明进行操作:https://pypi.org/project/scikit-image/。希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-21
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多