python ope翻转90度
时间: 2024-10-02 19:02:25 浏览: 38
在Python中,如果你想要翻转一个图像矩阵(比如一张图片),通常涉及到的是图像处理或计算机视觉领域。你可以使用PIL(Python Imaging Library)或者更现代的库如OpenCV来实现。这里是一个简单的例子,使用PIL库:
```python
from PIL import Image
def rotate_90_degree(image_path):
with Image.open(image_path) as img:
rotated_img = img.rotate(90)
# 保存旋转后的图片
rotated_img.save('rotated_' + image_path)
# 使用函数并传入你的图片路径
rotate_90_degree('original_image.jpg')
```
这个函数会读取指定的图片文件,然后将其顺时针旋转90度,并保存到原图名前加上“rotated_”的新文件。
如果你想直接操作像素,可以使用NumPy数组,但这通常是处理二维数组(不是图像文件)的情况:
```python
import numpy as np
import cv2
def np_rotate_90(arr):
return arr.reshape(-1, arr.shape[1]).T
# 假设arr是你的二维numpy数组
rotated_arr = np_rotate_90(arr)
```
阅读全文
相关推荐
















