PNG图像为四通道时:RGBA,第四通道表示透明度,图像位数为32位。
PNG图像为三通道时:RGB,图像位数为24位。
from PIL import Image
import os
path = "C:/Users/tianr/Desktop/breastShear_raw(150)_test/"
all_images = os.listdir(path)
# print(all_images)
for image in all_images:
image_path = os.path.join(path, image)
img = Image.open(image_path) # 打开图片
img = img.convert("RGB") # 4通道转化为rgb三通道
save_path = 'C:/Users/tianr/Desktop/breastShear_raw(150)_test/'
img.save(save_path + image)