python 图像翻转
时间: 2023-10-20 09:33:47 浏览: 80
要在Python中进行图像翻转,可以使用Pillow库提供的transpose()方法。具体的代码如下:
1. 左右翻转:
```python
from PIL import Image
image = Image.open("image.png") # 替换为你的图片路径
flipped_image = image.transpose(Image.FLIP_LEFT_RIGHT)
flipped_image.save("flipped_image.png") # 替换为你保存的图片路径
```
2. 上下翻转:
```python
from PIL import Image
image = Image.open("image.png") # 替换为你的图片路径
flipped_image = image.transpose(Image.FLIP_TOP_BOTTOM)
flipped_image.save("flipped_image.png") # 替换为你保存的图片路径
```
使用以上代码,可以将原始图片左右翻转或上下翻转,并保存为新的图片。请替换代码中的"image.png"为你的图片路径,并将"flipped_image.png"替换为你保存的图片路径。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [小案例:利用Python实现图片上下、左右翻转](https://blog.csdn.net/xun527/article/details/127286295)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文