oops / downsize.py
deansmile123's picture
Upload folder using huggingface_hub
75f0bc0 verified
Raw
History Blame Contribute Delete
798 Bytes
import os
import cv2
input_dir = "/scratch/ds5725/OOPS/images/"
output_dir = "/scratch/ds5725/OOPS/images_resized/"
os.makedirs(output_dir, exist_ok=True)
valid_ext = (".png", ".jpg", ".jpeg", ".bmp")
for fname in os.listdir(input_dir):
if not fname.lower().endswith(valid_ext):
continue
input_path = os.path.join(input_dir, fname)
output_path = os.path.join(output_dir, fname)
img = cv2.imread(input_path)
if img is None:
print(f"Skipping unreadable file: {fname}")
continue
h, w = img.shape[:2]
new_h = h // 4
new_w = w // 4
resized = cv2.resize(img, (new_w, new_h), interpolation=cv2.INTER_AREA)
cv2.imwrite(output_path, resized)
print(f"{fname}: {h}x{w} -> {new_h}x{new_w}")
print("All images resized successfully.")