Last active
August 31, 2022 13:31
-
-
Save wfng92/708c16940fd1bc132cc4e031f769cdb5 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
from PIL import Image | |
import glob | |
size = (512, 512) | |
# get all the files in a folder, make sure all are image files | |
files = glob.glob('./training_data/raw/*') | |
for fil in files: | |
# implement file type checking here if required | |
# get the basename, e.g. "dragon.jpg" -> ("dragon", ".jpg") | |
basename = os.path.splitext(os.path.basename(fil))[0] | |
with Image.open(fil) as img: | |
# resize the image to 512 x 512 | |
img = img.resize(size) | |
# rotate the image if required | |
# img = img.rotate(90) | |
# save the resized image, modify the resample method if required, modify the output directory as well | |
img.save(f"./training_data/key/{basename}.png", format="PNG", resample=Image.Resampling.NEAREST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment