python 将图像长宽调整为32的整数倍
可以使用Pillow库中的resize函数来将图像的长宽调整为32的整数倍。
具体步骤如下:
- 导入Pillow库
from PIL import Image
- 打开要处理的图像
image = Image.open("image.jpg")
- 获取原图像的宽和高
width, height = image.size
- 计算调整后的宽和高
new_width = (width // 32) * 32
new_height = (height // 32) * 32
- 调整图像大小
resized_image = image.resize((new_width, new_height))
完整代码:
from PIL import Image
image = Image.open("image.jpg")
width, height = image.size
new_width = (width // 32) * 32
new_height = (height // 32) * 32
resized_image = image.resize((new_width, new_height))
原文地址: http://www.cveoy.top/t/topic/bFBV 著作权归作者所有。请勿转载和采集!