0
点赞
收藏
分享

微信扫一扫

自动驾驶右向辅助功能规范

何以至千里 2023-12-11 阅读 39


安装Pillow

pip install pillow

获取图像属性

# 读取图像获得Image对象
image = Image.open('mori.jpg')
# format属性获得图像的格式
print(image.format) 
# size属性获得图像的尺寸
print(image.size) 
# mode属性获取图像的模式
print(image.mode) 
# show方法显示图像
image.show()

#输出
JPEG
(721, 451)
RGB

 效果

裁剪

# crop方法指定剪裁区域剪裁图像
image.crop((80, 20, 310, 360)).show()

生成缩略图

# thumbnail方法生成指定尺寸的缩略图
image.thumbnail((128, 128))

旋转

# rotate方法实现图像的旋转
image.rotate(45).show()

翻转

# transpose方法实现图像翻转
# Image.FLIP_LEFT_RIGHT - 水平翻转
# Image.FLIP_TOP_BOTTOM - 垂直翻转
image.transpose(Image.FLIP_TOP_BOTTOM).show()

滤镜

from PIL import ImageFilter

# filter方法对图像进行滤镜处理
image.filter(ImageFilter.CONTOUR).show()

 效果


系列文章索引

Python(一)关键字、内置函数

Python(二)基本数据类型

Python(三)数据类型转换

Python(四)字符串

Python(五)数字

Python(六) 列表

Python(七) 条件控制、循环语句

Python(八) 字典

Python(九) 集合

Python (十) 元组


举报

相关推荐

0 条评论