from PIL import Image
import os
from tqdm import tqdm
Image.MAX_IMAGE_PIXELS = None
scale = 1.0/10 #此处为自己所需要的下采样率
num=1
source_path=r"D:\123\123\123" #文件读取路径
result_path=r"D:\123\123\456" #文件存储路径
files = os.listdir(source_path)
files.sort(key=lambda x: int(x.split('.')[0]))
for file in tqdm(files):
img = Image.open(os.path.join(source_path,file))
width = int(img.size[0] * scale)
height = int(img.size[1] * scale)
#img_resize = img.resize((width,height),Image.ANTIALIAS)
img_resize = img.resize((width,height),Image.Resampling.LANCZOS)
img_resize.save(os.path.join(result_path,"%d.tiff" %num))
num = num + 1
笔记:图片下采样
于 2024-01-04 21:57:16 首次发布
本文介绍了如何使用Python中的PIL库处理图像,对文件夹中的图片进行按文件名排序,然后按照给定的下采样率调整尺寸,最后保存为TIFF格式。
摘要由CSDN通过智能技术生成