import os
from PIL import Image, ImageFile
folder_path = 'D:\\lab资料\\数据集\\EX\\处理后\\DDR_png512\\test\\images'
output_folder_path = 'D:\\lab资料\\数据集\\EX\\处理后\\DDR_png512\\test\\images'
file_list = os.listdir(folder_path)
for file_name in file_list:
if file_name.endswith('.png'):
image_path = os.path.join(folder_path, file_name)
image = Image.open(image_path)
resized_image = image.resize((512, 512))
output_path = os.path.join(output_folder_path, file_name)
resized_image.save(output_path)
print(f"Resized {file_name} to 512x512 and saved as {file_name} in the output folder.")