pil 常见用法
目录
缩放和裁剪
torch预处理:
缩放和裁剪
image=Image.open(img_path)
# 获取图像的宽度和高度
width, height = image.size
# 定义裁剪区域
crop_area = (0, 0, width//2, height)
# 裁剪图像
cropped_image = image.crop(crop_area)
# tuya_img.resize((960, 576),Image.LANCZOS)
torch预处理:
from torchvision import transforms
self.transform = transforms.Compose(
[
# transforms.Resize((576,960), interpolation=transforms.InterpolationMode.BILINEAR),
transforms.ToTensor(),
transforms.Normalize([0.5], [0.5]),
]
)