Last active
February 15, 2022 07:19
-
-
Save deepwilson/010a8c8f9a353ae22d6ae235ffc075ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Resize all images in a folder""" | |
from tqdm.notebook import tqdm | |
import os | |
import glob | |
input_folder = r"" #os.getcwd() | |
output_folder = r"" | |
resize_width = 512 | |
resize_height = 512 | |
filenames = glob.glob(os.path.join(input_folder,"*.jpg")) | |
for idx, filename in tqdm(enumerate(filenames), total=len(filenames)): | |
file_ext = filename.split(".")[-1] | |
img = cv2.imread(os.path.join(input_folder, filename)) | |
img = cv2.resize(img, (resize_width, resize_height), interpolation = cv2.INTER_CUBIC) | |
new_filename = filename.replace(f".{file_ext}", "") | |
cv2.imwrite(os.path.join(output_folder, f"{new_filename}_resized.jpg"), img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment