numpy格式读取图片,然后转成Image格式:
import numpy as np
import cv2
from PIL import Image
img = cv2.imread('img.jpg') # numpy格式
ori = Image.fromarray(img) # Image格式
ori_gray = ori.convert('L') # Image格式三通道转单通道灰度图
Image格式读取图片,转成numpy格式:
ori = Image.open('img.jpg')
img = np.array(ori) # Image转numpy