Python41 深度学习常用库 PIL库(图像处理)

一、展示图像、获得图像的处理模式和大小

"""
PIL库
安装pillow-pil
"""
from PIL import Image
import matplotlib.pyplot as plt
img=Image.open("qisui.jpg")
plt.imshow(img)
plt.show()

# 获得图像的模式
img_mode=img.mode
print(img_mode)

width,height=img.size
print(width,height)

二、图像旋转

# 对图片进行旋转
img_rotate=img.rotate(45)
plt.imshow(img_rotate)
plt.show()

三、图像剪切

# 对图片进行剪切
from PIL import Image
import matplotlib.pyplot as plt

img1=Image.open("qisui.jpg")
# 剪切图片 四个参数分别是(左上角点的x、y坐标  右下角点的x、y坐标)
img1_crop_result=img1.crop((126,0,381,249))

# 保存图片
img1_crop_result.save("sisui_crop_result.jpg")

# 展示图片
plt.imshow(img1_crop_result)
plt.show()

四、图像缩放

"""
图片的缩放
"""
from PIL import Image
import matplotlib.pyplot as plt

image=Image.open("qisui.jpg")

width,height=image.size

# 缩放
img2_resize_result=image.resize((int(width*0.6),int(height*0.6)))

print(img2_resize_result)

# 保存图片
img2_resize_result.save("qisui_resize_result.jpg")

# 展示图片
plt.imshow(img2_resize_result)
plt.show()

五、图片的左右旋转和图片的上下旋转

"""
图片的左右旋转和图片的上下旋转

"""
from PIL import Image
import matplotlib.pyplot as plt
from PIL.Image import Transpose

img=Image.open('qisui.jpg')
# 左右反转
img_lr=img.transpose(Transpose.FLIP_LEFT_RIGHT)

plt.imshow(img_lr)
plt.show()
# 上下翻转
img_bt=img.transpose(Transpose.FLIP_TOP_BOTTOM)

plt.imshow(img_bt)
plt.show()
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值