1. 读入PNG图片(RGBA)
from PIL import Image
from skimage import io, color, util
import cv2
img_pillow = Image.open(path) #<class 'PIL.PngImagePlugin.PngImageFile'> RGBA #L = R * 299/1000 + G * 587/1000 + B * 114/1000
img_skimage = io.imread(path) #<class 'numpy.ndarray'> RGBA #[0.2125, 0.7154, 0.0721]
img_cv = cv2.imread(path,cv2.IMREAD_UNCHANGED) #<class 'numpy.ndarray'> BGRA # RGB[0.299,0.587,0.114]
#通过img_cv[:, :,[0,2]] = img_cv[:,:,[2,0]] 验证三者读取出来的图像是等价的numpy
2. 转化为灰度图片
#全部不一致了,但差异不是很大,导致差异可能是计算精度和rgb权重的问题
gray_pillow = np.array(img_pillow.convert('L'))
gray_skimage = util.img_as_ubyte(color.colorconv.rgb2gray(img_skimage)) #这里因为归一化了,需要重新映射
gray_cv = cv2.cvtColor(img_cv, cv2.COLOR_BGR2GRAY)