UAV/tools/convert_jpg.py

15 lines
484 B
Python
Raw Normal View History

from PIL import Image
import os
convert_format = "tif"
img_dir = r"E:\datasets\UAV\134\project\images"
output_dir = r"E:\datasets\UAV\134_tif\project\images"
for file_name in os.listdir(img_dir):
img = Image.open(os.path.join(img_dir, file_name))
if convert_format == "png":
img.save(os.path.join(output_dir, file_name.replace(".jpg", ".png")))
elif convert_format == "tif":
img.save(os.path.join(output_dir, file_name.replace(".jpg", ".tif")), "TIFF")