python 之图像处理

使用python来实现图像图片的处理可以使用pillow 模块,我们可以基于这个模块对图片进行我们想要进行的预处理

pip install pillow
示例一:图片格式的转换

from PIL import Image
# def test():
#      打开读出图片
#     image = Image.open("114.jpg")
#     进行图像三色转换
#     dispose_image = image.convert('RGB')
#       规定图像的需要转换成的格式,后方为指定图片的转换格式
#     dispose_image.save('dispose_image.jpg','jpeg')

示例二:对图片的比例进行调整,此例为减少图片尺寸

# def change_size():
#     image = Image.open('114.jpg')
#     得到我们想要的尺寸
#     half_size = (image.size[0]/2,image.size[1]/2)
#     使用iamege.thumbnail来设定我们想要的尺寸
#     滤波器对像素进行高质量的采集,这里用作改变图像的尺寸大小
#     image.thumbnail(half_size,Image.ANTIALIAS)
#     保存时需要指定存储格式
#     image.save('change_size_iamge.jpg')

  

原文地址:https://www.cnblogs.com/1624413646hxy/p/11798449.html