New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Locally saving augmented images #258
Comments
import numpy as np
import imageio
from imgaug import augmenters as iaa
# random example image
image = np.random.randint(0, 255, size=(64, 64, 3)).astype(np.uint8)
# augment 16 times the example image
images_aug = iaa.Affine(rotate=(-45, 45)).augment_images([image] * 16)
# iterate over every example image and save it to 0.jpg, 1.jpg, 2.jpg, ...
for i, image_aug in enumerate(images_aug):
imageio.imwrite("%d.jpg" % (i,), image_aug) |
Change the line images_aug = iaa.Affine(rotate=(-45, 45)).augment_images([image[0]]*10) to images_aug = iaa.Affine(rotate=(-45, 45)).augment_images(images) and try again. Should work then. |
I am using this code and the augmented images look fine on Jupyter, but I am getting the same flat images, and hundreds of copies saved locally:
I have my code as |
You are iterating over path = 'C:\\path to folder containing folders of images'
ia.seed(2)
seq = iaa.Sequential([
iaa.Fliplr(0.5),
iaa.Crop(percent=(0, 0.1)),
iaa.Affine(rotate=(-25,25))
], random_order=True)
for folder in os.listdir(path):
i = 0
for fname in os.listdir(path + '\\' + folder):
img = imageio.imread(path + '\\' + folder + '\\' + fname)
print('Original:')
ia.imshow(img)
img_aug = seq.augment_image(img)
print('Augmented:')
ia.imshow(img_aug)
imageio.imwrite(os.path.join(path, path + '\\' + folder + '\\' + folder + "%06d.png" % (i,)), img_aug)
i += 1 |
That worked, thanks! |
To specify the path in your local computer or colab. |
I might have missed something in the documentation, or just don't have enough understanding of Python, but I was wondering if there is a way to save augmented images to a local folder on your PC. I am working on a project where I need to pull images, augment them, then resave them for future use and I was just wondering if that's possible.
The text was updated successfully, but these errors were encountered: