eiseg版本为1.1.1
报错显示cannot write mode RGBA as JPEG
出现这种问题的原因是一开始搜集图片的时候只是简单的将数据格式后缀png.以及其他格式简单的修改了图片本身的属性并没有变
RGBA为四通道图片,查看图片属性-详情信息-位深度32为四通道24为三通道
通过以下代码实现通道变换
from PIL import Image
import os
import string
from matplotlib import pyplot as plt
path = "D:\\xxx\\" #最后要加双斜杠,不然会报错
filelist=os.listdir(path)
for file in filelist:
whole_path = os.path.join(path, file)
img = Image.open(whole_path) # 打开图片img = Image.open(dir)#打开图片
img = img.convert("RGB") # 将一个4通道转化为rgb三通道
save_path = 'D:\\xxx\\data1\\'
#img.save(save_path + img1)
img.save(save_path + file)