Skip to content
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

How to pass an image path as parameter and only preprocess it? #62

Closed
Kongsea opened this issue Jan 10, 2018 · 5 comments
Closed

How to pass an image path as parameter and only preprocess it? #62

Kongsea opened this issue Jan 10, 2018 · 5 comments

Comments

@Kongsea
Copy link

Kongsea commented Jan 10, 2018

It seems Augmentor needs a work directory as the parameter and it will preprocess all files in it.
However, we always need to preprocess a specific image and use the image path as the parameter.
So how to use Augmentor in this situation?
Thank you.

@mdbloice
Copy link
Owner

Hi there, the best thing to do would be to pass the single image as an array. So create a pipeline object without specifying an image directory:

import Augmentor
import numpy as np
from PIL import Image
# Create a Pipeline object without specifying a directory:
p = Augmentor.Pipeline()
# Add operations to the pipeline object as per usual:
p.rotate(probability=1, max_left_rotation=5, max_right_rotation=5)

and then pass an image as an array to the function sample_with_array():

img = Image.open("/tmp/test.JPEG")
img_array = np.asarray(img)
img_augmented = p.sample_with_array(img_array)

The image contained in img_augmented is an image in PIL format.

Admittedly this is not very intuitive, I'll try to fix that for a future version. Also the documentation for this functionality is sparse, I'll fix that too in an upcoming version.

M.

@Kongsea
Copy link
Author

Kongsea commented Jan 15, 2018

Thank you.
Look forward to the new version.

@mhnatiuk
Copy link

Hi,
I need to use Augmentor to process images file-by-file (i am generating artifical dataset and I have to do more operations than just augmenting). Im doing exactly what you posted above, however for
augmentation_pipeline.sample_with_array(np.asarray(img)) (a numpy array) I get error:

    return images[0]  # Here we return only the first image for the generators.
IndexError: list index out of range

@unnir
Copy link

unnir commented Jun 1, 2018

@mhnatiuk

you can do it like this:

import Augmentor
import numpy as np
from PIL import Image
# Create a Pipeline object without specifying a directory:
p = Augmentor.Pipeline()
# Add operations to the pipeline object as per usual:
p.rotate(probability=1, max_left_rotation=5, max_right_rotation=5)

And then change your image:
p.sample_with_array((X_train[0].reshape(480,480)))

If it does not work, check this:
#90

@ddfabbro
Copy link

I used p._execute_with_array instead

img = Image.open("/tmp/test.JPEG")
img_array = np.asarray(img)
img_augmented = p._execute_with_array(img_array)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants