0
点赞
收藏
分享

微信扫一扫

python PIL-Image

PIL库用于图像处理
​​​from PIL import Image​​​ Image是PIL库中代表一个图像的类(对象)
图像是一个三维数组,维度分别是高度、宽度和像素RGB值

>>> from PIL import Image
>>> import numpy as np
>>> im = np.array(Image.open("C:\\Users\\dell\\Desktop\\1.jpg"))
>>> print(im.shape)
(444, 500, 3)
>>> print(im.dtype)
uint8

图像的变换
读入图像后,获取像素RGB值,修改后存为新的文件

>>> from PIL import Image
>>> import numpy as np
>>> a = np.array(Image.open("C:\\Users\\dell\\Desktop\\1.jpg"))
>>> b = [255,255,255]-a
>>> im = Image.fromarray(b.astype("uint8"))
>>> im.save("C:\\Users\\dell\\Desktop\\2.jpg")


举报

相关推荐

0 条评论