python中用Pillow库进行图片处理


PIL:PIL.Image.open

 

PIL即Python Imaging Library,也即为我们所称的Pillow,是一个很流行的图像库,它比opencv更为轻巧,正因如此,它深受大众的喜爱。

一、图片读取

PIL读进来的图像是一个对象,而不是我们所熟知的numpy 矩阵。

from PIL import Image
img = Image.open('呆头鸟.jpg')
print(img.format) 
print(img.size) #注意,省略了通道 (w,h)
print(img.mode) #L为灰度图,RGB为真彩色,RGBA为加了透明通道
img.show() # 显示图片

显示效果:

 

二、灰度的调整

from PIL import Image
img = Image.open('呆头鸟.jpg')
gray = Image.open('呆头鸟.jpg').convert('L')
gray.show()

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM