Python图片处理

Python 读取图片

1. PIL

目前主要使用python3,python2已经不支持更新了。使用anaconda管理python的各种库较为方便。

pip install pillow

PIL 读取的通道顺序为RGB,实际上使用的是PIL库中的Image类
读取shape为(Width, Height),省略了通道

from PIL import Image

img=Image.open(imagepath)
img.show()
im.save(outfilepath, format, options…)

2. cv2

cv2是OpenCV的python版本

pip install opencv-python

cv2读取的通道顺序是BGR
cv2读取的数据类型是numpy数组,是uint8的整型数据,范围为0-255,numpy 数组的shape是(Height, Width, Channel)

import cv2

img= cv2.imread(imagepath )
cv2.imshow('title', img)
cv2.waitKey(0)   # 按任意键继续
cv2.imwrite(outfilepath)

3. matplotlib.image

安装好了matplotlib其中就包括了matplotlib.image
plt.imread()读取的通道顺序是RGB
plt.imread()读取的数据类型是numpy数组,是uint8的整型数据,范围为0-255
numpy 数组的shape是(Height, Width, Channel)

import matplotlib.image as mpimg
import matplotlib.pyplot as plt

img = mpimg.imread(imagepath)
plt.imshow(img)
plt.show()
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值