ObjectDetectionXview / convert_to_jpg.py
valentynliubchenko
first commit
211cb30
raw
history blame contribute delete
893 Bytes
from PIL import Image
import os
def convert_tiff_to_jpeg(tiff_path, jpeg_path):
try:
with Image.open(tiff_path) as img:
img.convert('RGB').save(jpeg_path, 'JPEG')
print(f"converted: {tiff_path} -> {jpeg_path}")
except Exception as e:
print(f"error converted {tiff_path}: {e}")
def batch_convert_tiff_to_jpeg(input_folder, output_folder):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for filename in os.listdir(input_folder):
if filename.endswith('.tif') or filename.endswith('.tiff'):
tiff_path = os.path.join(input_folder, filename)
jpeg_path = os.path.join(output_folder, filename.split('.')[0] + '.jpg')
convert_tiff_to_jpeg(tiff_path, jpeg_path)
input_folder = './examples'
output_folder = './examples2'
batch_convert_tiff_to_jpeg(input_folder, output_folder)