如何反转枕头图像的轴

How to invert axis of a pillow image

Seaborn 提供了反转图像轴的可能性。我想对 PIL 做同样的事情。这是我的代码。

# Imports
import seaborn as sns; sns.set_theme()
import matplotlib.pyplot as plt
import numpy as np
import numpy as np; np.random.seed(0)
from PIL import Image
import random

# Arrays
r = []
g = []
b = []
for i in range(200):
    r.append(random.sample(range(0, 255), 200))
    g.append(random.sample(range(0, 255), 200))
    b.append(random.sample(range(0, 255), 200))
    
# Change color of the left part of the image
r = np.array(r)
r[:, 0:10]=0

# Change color of the right part of the image
r = np.array(r)
r[:, -10:-1]=150

g = np.array(g)
g[:, -10:-1]=150


# Plot seaborn heatmap
fig, ax = plt.subplots()

sax = sns.heatmap(r)
sax.invert_xaxis() 

sax.invert_xaxis() 反转绘图的 x 轴。

我也想对枕头做同样的事情。我已经 google 很长时间了,什么也没找到。 这是我的 rgb 枕头图像。

rgbarr = np.zeros((200,200,3), 'uint8')
rgbarr[..., 0] = np.array(r)
rgbarr[..., 1] = np.array(g)
rgbarr[..., 2] = np.array(b)
img = Image.fromarray(rgbarr)
img

opencv 的可能性也将受到欢迎。

我想你只是想翻转它:

 im_flipped = im.transpose(method=Image.FLIP_LEFT_RIGHT)