Spaces:
Runtime error
Runtime error
File size: 1,328 Bytes
2f8b452 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# This Program Resize the image into shape (299,299)
from PIL import Image
import os
def resize_images(input_folder, output_folder, new_size=(224, 224)):
# check whether the output folder exists ?
if not os.path.exists(output_folder):
os.makedirs(output_folder)
# Loop through all files in the input folder
for filename in os.listdir(input_folder):
# Check if the file is a valid image file
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
input_path = os.path.join(input_folder, filename)
output_path = os.path.join(output_folder, filename)
# Open and resize the image
with Image.open(input_path) as img:
resized_img = img.resize(new_size, Image.BICUBIC)
# Save the resized image to the output folder
resized_img.save(output_path)
if __name__ == "__main__":
# Specify the input and output folders
input_folder = "D:/dataset/boneage-test-dataset/boneage-validation-dataset/"
output_folder = "D:/dataset/resize_image/boneage-validation-dataset/"
# Specify the new size for the images
new_size = (299,299)
# Resize the images in the input folder and save them to the output folder
resize_images(input_folder, output_folder, new_size) |