mdbloice / Augmentor

Image augmentation library in Python for machine learning.
https://augmentor.readthedocs.io/en/stable
MIT License
5.06k stars 865 forks source link

augment only a single, or set of images #68

Open niekverw opened 6 years ago

niekverw commented 6 years ago

I was wondering if it is possible to use Augmentor to augment a single image or augment multiple images in exactly the same manner (e.g. multiple np.array as input, not filename)? if you have image + Masks, it may be necessary to augment masks the exact same way.

so something like:

i1 = cv2.imread (f1)
i2 = cv2.imread (f2)

x = []
x.append (i1)
x.append (i2)
print(np.array(x).shape)

rotate = ops.RotateRange(probability=0, max_left_rotation=50, max_right_rotation=10)

img_ro = np.array(rotate.perform_operation(Image.fromarray(x)))
for ii in img_ro:
  plt.imshow(ii) # each image in x is rotated in the same way
  plt.show()
mdbloice commented 6 years ago

Hi @niekverw , yes, this is now finally possible using the ground_truth() function in the Pipeline class (as of Augmentor v0.2.0).

Basically, just use this function to point to a directory containing the mask images, and when you generate new image data, images will be generated for both the mask and the original images:

p = Augmentor.Pipeline("/home/user/images")
p.ground_truth("/home/user/mask_images")

Call p.sample() in the same way as per usual to generate both sets of images.

See the README for more details.

kmsravindra commented 6 years ago

@mdbloice, Thanks for this awesome library. Just wondering similar to transforming the mask, is it possible to transform the bounding box coordinates as well ?

jaelim commented 6 years ago

@mdbloice Hi there, Can you explain more about masks in the ground truth directory? I have image files and annotation files (a text file containing coordinates and dimensions of bounding boxes). My interest is to apply augmentation on image (shift, rotation, or flip), but also similarly to grounding boxes (masks?). Thanks.