import os
import time
from PIL import Image,ImageChops,ImageEnhance
import matplotlib.pyplot as plt
import numpy as np
img = Image.open(r"C:\Users\xiahuadong\Pictures\风景\陆家嘴1.jpg")
plt.imshow(img)
img1 = img.transpose(Image.FLIP_LEFT_RIGHT) # 左右翻转
plt.imshow(img1)
img1 = img.transpose(Image.FLIP_TOP_BOTTOM) # 上下翻转
plt.imshow(img1)
img1 = img.rotate(20) # 旋转20度
plt.imshow(img1)
img1 = ImageChops.offset(img,300,0) # 沿X轴平移
plt.imshow(img1)
img1 = ImageChops.offset(img,0,300) # 沿Y轴平移
plt.imshow(img1)
img1 = ImageEnhance.Brightness(img).enhance(0.5) # 小于1为亮度减弱
plt.imshow(img1)
img1 = ImageEnhance.Brightness(img).enhance(1.5) # 大于1为亮度增强
plt.imshow(img1)
img1 = ImageEnhance.Color(img).enhance(0.5) # 小于1为色度减弱
plt.imshow(img1)
img1 = ImageEnhance.Color(img).enhance(1.5) # 大于1为色度增强
plt.imshow(img1)
img1 = ImageEnhance.Contrast(img).enhance(0.5) # 小于1为对比度减弱
plt.imshow(img1)
img1 = ImageEnhance.Contrast(img).enhance(1.5) # 大于1为对比度增强
plt.imshow(img1)
img1 = ImageEnhance.Sharpness(img).enhance(0.5) # 小于1为锐度减弱
plt.imshow(img1)
img1 = ImageEnhance.Sharpness(img).enhance(1.5) # 大于1为锐度增强
plt.imshow(img1)
img1 = img1.convert("L") # 转换为灰度图
plt.imshow(
img1,
cmap="gray" # 灰度显示
)
img1.save("./img/1.jpg") # 保存图像
arr_img = np.array(img1) # 图像转numpy数组