imresize in PIL/scipy.misc only works for uint8 images? any alternatives?

前端 未结 2 1933
不思量自难忘°
不思量自难忘° 2021-02-10 04:59

It seems the imresize implemented in PIL/scipy.misc only works for uint8 images

>>> import scipy.misc
>>>         


        
2条回答
  •  鱼传尺愫
    2021-02-10 05:17

    Thanks to cgohlke's comment. Below are two alternatives I found that works for float-number images.

    1. Use scipy.ndimage.interpolation.zoom

    For single-channel images: im2 = scipy.ndimage.interpolation.zoom(im, 0.5)

    For 3-channel images: im2 = scipy.ndimage.interpolation.zoom(im, (0.5, 0.5, 1.0))

    1. Use OpenCV.

    im2 = cv2.resize(im, (im.shape[1]/2, im.shape[0]/2))

    This works for both single-channel and 3-channel images. Note that one needs to revert the shape order in second parameter.

提交回复
热议问题