Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save toshihiroryuu/fc7e4bf311389d6fc2b743ec66371aca to your computer and use it in GitHub Desktop.
Save toshihiroryuu/fc7e4bf311389d6fc2b743ec66371aca to your computer and use it in GitHub Desktop.
import os
try:
import Augmentor
except ImportError:
os.system('pip install Augmentor')
PATH="/path/to/image/folder" # path for images to be augmented
n=200 # no of images after augmentation
p = Augmentor.Pipeline(PATH)
p.scale(probability=0.2, scale_factor=1.2)
p.resize(probability=1.0, width=120, height=120)
p.resize(probability=0.1, width=100, height=200, resample_filter=u'BICUBIC')
p.zoom(probability=0.5, min_factor=1.1, max_factor=1.5)
p.zoom_random(probability=0.5, percentage_area=0.8)
p.flip_top_bottom(probability=0.5)
p.flip_left_right(probability=0.5)
p.rotate(probability=0.7, max_left_rotation=10, max_right_rotation=10)
p.rotate90(probability=0.5)
p.rotate180(probability=0.5)
p.rotate270(probability=0.5)
p.rotate_random_90(probability=0.1)
p.rotate_without_crop(probability=0.01, max_left_rotation=20, max_right_rotation=20, expand=False)
p.shear(probability=0.2, max_shear_left=2, max_shear_right=3)
p.skew(probability=0.3, magnitude=1)
p.skew_corner(probability=0.01, magnitude=1)
p.skew_left_right(probability=0.02, magnitude=1)
p.skew_tilt(probability=0.03, magnitude=1)
p.skew_top_bottom(probability=0.04, magnitude=1)
p.random_brightness(probability=0.4, min_factor=0, max_factor=0.65)
p.random_color(probability=0.3, min_factor=0.4, max_factor=0.6)
p.random_contrast(probability=0.2, min_factor=0, max_factor=1)
# p.random_erasing(probability=0.3, rectangle_area=0.2)
# p.random_distortion(probability=1, grid_width=4, grid_height=4, magnitude=8)
# p.gaussian_distortion(probability, grid_width, grid_height, magnitude, corner, method, mex=0.5, mey=0.5, sdx=0.05, sdy=0.05)
# p.black_and_white(probability=0.6, threshold=128)
# p.greyscale(probability)
# p.histogram_equalisation(probability=1.0)
# p.invert(probability)
# p.crop_by_size(probability, width, height, centre=True)
# p.crop_centre(probability, percentage_area, randomise_percentage_area=False)
# p.crop_random(probability, percentage_area, randomise_percentage_area=False)
p.sample(n)
@toshihiroryuu
Copy link
Author

The program will create augmented images and will save it in outputs folder under the PATH specified.

@toshihiroryuu
Copy link
Author

Change the value of n to be the number of augmented images to be created.

@toshihiroryuu
Copy link
Author

Check into Augmentor library for implementation of each augmentation techniques.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment