【Python学习】图片放缩

使用图片对模型进行训练时,对图片的大小有一定的要求,因此需要对图片进行放缩。

安装包PIL

pip install Pillow

image

简单介绍

image

基本使用方法

# Imports PIL module 
from PIL import Image
  
# open method used to open different extension image file
im = Image.open(r"C:\Users\System-Pc\Desktop\ybear.jpg") 
  
# This method will show image in any image viewer 
im.show() 

image

放缩,另存

img = Image.open(r"C:\Users\gong2\Desktop\cat (1).jpg")
print(img.size)

out = img.resize((128,128))
img.show()
out.save('cat (1).jpg')

放缩前454x454
image

放缩后128x128
image

posted @   寥若辰星  阅读(44)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
点击右上角即可分享
微信分享提示