# -*- coding: utf-8 -*- from torchvision import transforms from PIL import Image import warnings warnings.filterwarnings("ignore") img = Image.open('/home/images/969743078.jpg') print(type(img)) print(img.size) # # 将输入的PIL.Image重新改变大小成给定的size,size是最小边的边长。 # crop = transforms.Scale(300) # croped_img=crop(img) # print(type(croped_img)) # print(croped_img.size) # # croped_img.show() # # img_tensor = transforms.ToTensor()(croped_img) # 转换成tensor # print(img_tensor) # # # 图像转换, # croped_img_1=transforms.ToPILImage(img_tensor) # print(croped_img_1) # 图像缩放,将原是PIL图像重新调整到指定形状。 croped_img_2=transforms.functional.resize(img, [150,212], interpolation=2) croped_img_2.save("new.jpg") # print(croped_img_2) # croped_img_2.show() # from PIL import Image # import torchvision.transforms as transforms # import matplotlib.pyplot as plt # # # def readImage(path='/home/zzz/program/new/DA_Detection/images/181470768.jpg
python中缩小图片并保持
最新推荐文章于 2024-04-13 16:45:00 发布
这篇博客展示了如何在Python中使用torchvision库的transforms和PIL库来缩小图片,通过设置指定尺寸,实现了图片的尺寸调整,并保存了调整后的图片。
摘要由CSDN通过智能技术生成