| from PIL import Image
|
| import os
|
|
|
| def batch_convert_images(input_dir, output_dir):
|
|
|
| if not os.path.exists(output_dir):
|
| os.makedirs(output_dir)
|
|
|
|
|
| for filename in os.listdir(input_dir):
|
|
|
| if filename.lower().endswith('.ppm') or filename.lower().endswith('.pgm'):
|
| img_path = os.path.join(input_dir, filename)
|
| img = Image.open(img_path)
|
|
|
|
|
| new_filename = os.path.splitext(filename)[0] + '.png'
|
| save_path = os.path.join(output_dir, new_filename)
|
|
|
|
|
| img.save(save_path)
|
| print(f"Converted: {filename} -> {new_filename}")
|
|
|
|
|
| input_dir = 'D:/U2UData-2/Sunny_Rain/2025-07-28-20-19-32/images'
|
| output_dir = 'D:/U2UData-2/Sunny_Rain/2025-07-28-20-19-32/PNG'
|
| print("------------------")
|
| batch_convert_images(input_dir, output_dir) |