Created
July 30, 2020 19:18
-
-
Save robgon-art/5de9f198199abe4e66a0ece088bf1ad5 to your computer and use it in GitHub Desktop.
Prepare the images for GAN training
This file contains 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
# set up the file paths | |
from_path = 'art/cropped/' | |
to_path = 'art/resized/' | |
# set up some parameters | |
size = 1024 | |
num_augmentations = 6 | |
# set up the image augmenter | |
seq = iaa.Sequential([ | |
iaa.Rot90((0, 3)), | |
# iaa.Fliplr(0.5), | |
iaa.PerspectiveTransform(scale=(0.0, 0.05), mode='replicate'), | |
iaa.AddToHueAndSaturation((-20, 20)) | |
]) | |
# loop through the images, resizing and augementing | |
path, dirs, files = next(os.walk(data_path)) | |
for file in sorted(files): | |
print(file) | |
image = Image.open(path + "/" + file) | |
image.save(to_path + "/" + file) | |
image_resized = img.resize((size,size), resample=Image.BILINEAR) | |
image_np = np.array(image_resized) | |
images = [image_np] * num_augmentations | |
images_aug = seq(images=images) | |
for i in range(0, num_augmentations): | |
im = Image.fromarray(np.uint8(images_aug[i])) | |
to_file = to_path + "/" + file[:-4] + '_' + str(i).zfill(2) + '.jpg' | |
im.save(to_path) #, quality=95) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment