首页 > 编程语言 >【Python学习】图片放缩

【Python学习】图片放缩

时间:2023-01-16 10:22:05浏览次数:42  
标签:PIL img show Python image 放缩 open 图片

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

安装包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

标签:PIL,img,show,Python,image,放缩,open,图片
From: https://www.cnblogs.com/harper-blogs/p/17054807.html

相关文章

  • 学习python 爬虫之pyppteer
    1、安装pyppteer库 pipinstallpyppteer 如果安装出错,使用国内镜像安装 pipinstallpyppeteer-ihttps://pypi.douban.com/simple2、下载chromium浏览......
  • Python 量化交易编程技巧积累
    1.计算股票中的16个常用指标-stockstatus。地址:https://blog.csdn.net/freewebsys/article/details/785785482.获得全世界所有市场的交易日历-exchange_calendar。地址:ht......
  • 尝试python 爬虫新工具playwright
    1、安装playwright库pipinstallplaywright 2、安装浏览器驱动文件(安装过程稍微有点慢)python-mplaywrightinstall......
  • 【801】Python绘制机器学习特征相关性热力图
    参考:python特征相关性热力图怎么画_如何在python中绘制热地图(实例)参考:seaborn.heatmap参考:Choosingcolorpalettes根据具体的特征数据集,计算不同特征之间的相关性,然后......
  • AirSim 自动驾驶仿真 (2-3) python控制无人机 win10
    1首先搭建好环境参考 2python控制https://blog.csdn.net/Zhaoxi_Li/article/details/108002544官方代码位置 自己pythonj教程https://www.cnblogs.com/gooutlo......
  • python django学生选课系统
    pythondjango学生选课系统后端:Pythondjango数据库:MySQL前端:htmlcssjs实现功能:登录、注册、查看自己信息、修改自己信息等学生:看课、选课、查学分老师:创建课程、......
  • python利用subprocess执行shell命令
    subprocess以及常用的封装函数运行python的时候,我们都是在创建并运行一个进程。像Linux进程那样,一个进程可以fork一个子进程,并让这个子进程exec另外一个程序。在Python中,......
  • Python django 公寓管理系统
    Pythondjango公寓管理系统django公寓租房系统django酒店订购系统django公寓订购系统技术:Pythondjango数据库:MySQL前端:htmlcssjs涉及到的功能:登录、注册、......
  • Python django 会议室管理系统
    Pythondjango会议室管理系统django会议室申请系统django会议室系统技术:Pythondjango数据库:MySQL涉及功能:登录、注册、登出、管理员登录、管理用户信息等添加会......
  • Python django 图书馆管理系统
    Pythondjango图书馆管理系统技术:Python  django数据库:sqlite3(或MySQL)前段:html css  js 功能:注册,注销,改密码,添加图书,添加图书照片,查看图书,普通用户只能查看......