Spaces:
Sleeping
Sleeping
File size: 956 Bytes
99c3bcf |
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 |
import os
import random
from PIL import Image
input_folder = "Dataset NST\TamilStyleImages"
output_folder = "resized_output"
target_size = (256, 256)
sample_size = 100
os.makedirs(output_folder, exist_ok=True)
image_files = [f for f in os.listdir(input_folder) if f.lower().endswith(('.jpg', '.jpeg', '.png'))]
sampled_files = random.sample(image_files, min(sample_size, len(image_files)))
for i, filename in enumerate(sampled_files, 1):
input_path = os.path.join(input_folder, filename)
output_path = os.path.join(output_folder, filename)
try:
with Image.open(input_path) as img:
img_resized = img.resize(target_size, Image.Resampling.LANCZOS)
img_resized.save(output_path)
print(f"[{i}/{sample_size}] Processed: {filename}")
except Exception as e:
print(f"Failed to process {filename}: {e}")
|