读取图片信息到 numpy 数组,并对数组进行变换得到新的图片

读取 cat.jpg 图片信息到
![img]( numpy 数组https://img-mid.csdnimg.cn/release/static/image/mid/ask/072385664356161.jpg "#left")
,(1)数组行对称交换,保存生成新的图 片; (2)数组列对称交换,保存生成新的图片

>>> import numpy as np
>>> from PIL import Image
>>> im = np.array(Image.open(r'd:\temp\072385664356161.jpg'))
>>> im.shape, im.dtype # im是numpy数组
((565, 808, 3), dtype('uint8'))
>>> im_ud = np.flipud(im) # 上下交换
>>> im_lr = np.fliplr(im) # 左右交换
>>> Image.fromarray(im_ud).save(r'd:\temp\im_ud.jpg')
>>> Image.fromarray(im_lr).save(r'd:\temp\im_lr.jpg')

下图分别是原图、上下交换图、左右交换图。

img

img

img