| | 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 = 'E:/THU_Projects/DataSets/2025-03-22-20-29-50/images' |
| | output_dir = 'E:/THU_Projects/DataSets/2025-03-22-20-29-50/PNG' |
| | batch_convert_images(input_dir, output_dir) |