代码语言:javascript复制
import os
from PIL import Image
dirname_read="D:datasetcityscapescityscape_voc_cleanJPEGImages_png\"
dirname_write="D:datasetcityscapescityscape_voc_cleanJPEGImages_jpg\"
names=os.listdir(dirname_read)
count=0
for name in names:
img=Image.open(dirname_read name)
name=name.split(".")
if name[-1] == "png":
name[-1] = "jpg"
name = str.join(".", name)
r,g,b=img.split()
img=Image.merge("RGB",(r,g,b))
to_save_path = dirname_write name
img.save(to_save_path)
count =1
print(to_save_path, "------conut:",count)
else:
continue