最近在学习cs231n的课程中,发现其给出的文档中,scipy中已经找不到这三个函数了,因为scipy版本>=1.3.0已经移除了。
from scipy.misc import imread, imsave, imresize
现记录下代替imread、imsave的方案:
from imageio import imread, imsave
如此便可像scipy库中一样使用了。
imresize的替换方案:
from PIL import Image # 调包PIL
img_tinted = np.array(Image.fromarray(np.uint8(img_tinted)).resize((300, 300)))
刚开始没有加上np.uint8会出现如下的错误
这是因为格式不匹配。
现在粘贴示例代码
import numpy as np
from imageio import imread, imsave
from PIL import Image # 调包PIL
# Read an JPEG image into a numpy array
img = imread('G:/cv/picture/sky.jpg')
print(img.dtype, img.shape)
img_tinted = img * [1, 0.95, 0.9]
# Resize the tinted image to be 300 by 300 pixels.
img_tinted = np.array(Image.fromarray(np.uint8(img_tinted)).resize((300, 300)))
# Write the tinted image back to disk
imsave('G:/cv/picture/sky_tinted.jpg', img_tinted)
文章出处登录后可见!
已经登录?立即刷新