python图像处理

Python常用处理图像的库是PIL,另外还有opencv、Matplotlib、NumPy、SciPy、skimage 详情请参考:https://www.cnblogs.com/qiaozhoulin/p/4509954.html、  https://www.cnblogs.com/skyfsm/p/8276501.html

PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了。PIL功能非常强大,但API却非常简单易用,但其只支持Python 2.7,在PIL的基础上创建了兼容的版本,名字叫Pillow,支持最新Python 3.x

1.缩放篇

Image.resize()函数用于修改图片的尺寸;Image.thumbnail()函数用于制作当前图片的缩略图。from PIL import Image

img01= Image.open('F:/pytest/101.jpeg')
img01.show()
w01,h01=img01.size # 获得图像尺寸:
print('current image01 size:%sX%s'%(w01,h01))

img01.thumbnail((w01//2,h01//2)) # 缩放到50%:
img01.save('F:/pytest/102.jpeg','jpeg') # 缩放后保存为102.jpeg
img02=Image.open('F:/pytest/102.jpeg')
img02.show()
w02,h02=img02.size # 获得图像尺寸:
print('current image02 size:%sX%s'%(w02,h02))

#print('resized size',img01.resize((128,128)).size)
img03 = img01.resize((128,128)) #t图像修改尺寸为128*128
img03.save('F:/pytest/103.jpeg','jpeg')
img03.show()
w03,h03=img03.size # 获得图像尺寸:
print('current image03 size:%sX%s'%(w03,h03))

2.旋转篇

待续

猜你喜欢

转载自www.cnblogs.com/jintianniu/p/11246791.html