欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PIL.Image.open与cv2.imread格式问题

程序员文章站 2022-05-16 11:23:43
...
# -*- coding: utf-8 -*-
"""
Created on 2019/8/13 9:36
@Author: Johnson
@Email:[email protected]
@File: test.py
"""
'''
常用图片读取方式:

PIL.Image.open

scipy.misc.imread

scipy.ndimage.imread

cv2.imread(速度最快)

matplotlib.image.imread

skimage

caffe.io.load_image
'''

import numpy as np
from PIL import  Image
imagepath = "1.jpg"
im1 = Image.open(imagepath)
im1 = np.array(im1) #获取numpy对象,RGB
print(type(im1))
print(im1.shape)

#2 opencv
import cv2
im2 = cv2.imread(imagepath)
print(type(im2)) #numpy BGR
print(im2.shape) #[width,heigth,3]

#3 skimage
from skimage import io
im3 = io.imread(imagepath) #
print(type(im3))
print(im3.shape)