处理内容图像
from PIL import Image
import numpy as np
- 读取图像,并转化为float类型。
content_target = np.float32(Image.open(config.content_target))
- 去掉图像的透明度通道。
有的图像格式除了RGB通道外,还有透明度通道。因此,去掉图像最后一维的最后一列。
图像的维度:[Height, Width, RGB]
# remove alpha channel
if content_target.shape[-1] == 4:
content_target = content_target[..., :-1]
- 裁切图像,使其形状与密度场形状相同。
# crop
ratio