读出来的图像是RGBA四通道的,A通道为透明通道,该通道值对深度学习模型训练来说暂时用不到,因此使用convert(‘RGB’)进行通道转换。
import os
from PIL import Image
path_img = os.path.join(os.path.dirname(os.path.abspath(__file__)), "picture.png")
img1 = Image.open(path_img)
img2 = Image.open(path_img).convert('RGB')
print("img1:", img1)
print("img2:", img2)
参考文章:
https://blog.csdn.net/MasterCayman/article/details/118707553