- Python Pillow教程
 - 蟒蛇Pillow - 主页
 - Python Pillow - 概述
 - Python Pillow - 环境设置
 - Python Pillow - 使用图像模块
 - Python Pillow - 处理图像
 - Python Pillow - 创建缩略图
 - Python Pillow - 合并图像
 - Python Pillow - 模糊图像
 - Python Pillow - 裁剪图像
 - Python Pillow - 翻转和旋转图像
 - Python Pillow - 调整图像大小
 - Python Pillow - 创建水印
 - Python Pillow - 向图像添加滤镜
 - Python Pillow - 图像上的颜色
 - Python Pillow - ImageDraw 模块
 - Python Pillow - 图像序列
 - Python Pillow - 在图像上写入文本
 - Python Pillow - 使用 Numpy 进行机器学习
 - Python Pillow 有用资源
 - Python Pillow - 快速指南
 - Python Pillow - 有用的资源
 - Python Pillow - 讨论
 
Python Pillow - 翻转和旋转图像
在使用 python 图像处理库处理图像时,有时您需要翻转现有图像以从中获得更多见解、增强其可见性或满足您的要求。
Pillow库的图像模块使我们可以非常轻松地翻转图像。我们将使用图像模块中的转置(方法)函数来翻转图像。“transpose()”支持的一些最常用的方法是 -
Image.FLIP_LEFT_RIGHT - 用于水平翻转图像
Image.FLIP_TOP_BOTTOM - 用于垂直翻转图像
Image.ROTATE_90 - 用于通过指定角度旋转图像
示例 1:水平翻转图像
以下 Python 示例读取图像,水平翻转它,并使用标准 PNG 显示实用程序显示原始图像和翻转图像 -
# import required image module
from PIL import Image
# Open an already existing image
imageObject = Image.open("images/spiderman.jpg")
# Do a flip of left and right
hori_flippedImage = imageObject.transpose(Image.FLIP_LEFT_RIGHT)
# Show the original image
imageObject.show()
# Show the horizontal flipped image
hori_flippedImage.show()
输出
原图
翻转图像
示例 2:垂直翻转图像
以下 Python 示例读取图像,垂直翻转它,并使用标准 PNG 显示实用程序显示原始图像和翻转图像 -
# import required image module
from PIL import Image
# Open an already existing image
imageObject = Image.open("images/spiderman.jpg")
# Do a flip of left and right
hori_flippedImage = imageObject.transpose(Image.FLIP_LEFT_RIGHT)
# Show the original image
imageObject.show()
# Show vertically flipped image
Vert_flippedImage = imageObject.transpose(Image.FLIP_TOP_BOTTOM)
Vert_flippedImage.show()
输出
原始图像
翻转图像
示例 3:将图像旋转到特定角度
以下 Python 示例读取图像,旋转到指定的角度,并使用标准 PNG 显示实用程序显示原始图像和旋转图像 -
# import required image module
from PIL import Image
# Open an already existing image
imageObject = Image.open("images/spiderman.jpg")
# Do a flip of left and right
hori_flippedImage = imageObject.transpose(Image.FLIP_LEFT_RIGHT)
# Show the original image
imageObject.show()
#show 90 degree flipped image
degree_flippedImage = imageObject.transpose(Image.ROTATE_90)
degree_flippedImage.show()
输出
原始图像
旋转图像
