def main(): """Plot example augmentations for Lena and an image loaded from a file.""" # try on a lena image image = data.lena() augmenter = ImageAugmenter(image.shape[0], image.shape[1], hflip=True, vflip=True, scale_to_percent=1.3, scale_axis_equally=False, rotation_deg=25, shear_deg=10, translation_x_px=5, translation_y_px=5) augmenter.plot_image(image, 100) # check loading of images from file and augmenting them image = misc.imread("chameleon.png") augmenter = ImageAugmenter(image.shape[1], image.shape[0], hflip=True, vflip=True, scale_to_percent=1.3, scale_axis_equally=False, rotation_deg=25, shear_deg=10, translation_x_px=5, translation_y_px=5) augmenter.plot_image(image, 50) # move the channel from index 2 (3rd position) to index 0 (1st position) # so (y, x, rgb) becomes (rgb, y, x) # try if it still works image = np.rollaxis(image, 2, 0) augmenter = ImageAugmenter(image.shape[2], image.shape[1], hflip=True, vflip=True, scale_to_percent=1.3, scale_axis_equally=False, rotation_deg=25, shear_deg=10, translation_x_px=5, translation_y_px=5, channel_is_first_axis=True) augmenter.plot_image(image, 50)
from scipy import misc import numpy as np directory = os.getcwd() + "/training/positive_generated/" files = [f for f in listdir(directory) if isfile(join(directory, f))] for file in files: if "jpg" not in file and "png" not in file: continue image = misc.imread("./training/positive_generated/" + file) # image=Image.open("./training/positive/"+file) # for i in range(0,21): # image.save(os.getcwd()+"/training/positive_expanded/"+file.strip(".jpg").strip(".png")+str(i)+".jpg") height = image.shape[0] width = image.shape[1] augmenter = ImageAugmenter( width, height, # width and height of the image (must be the same for all images in the batch) hflip=True, # flip horizontally with 50% probability vflip=True, # flip vertically with 50% probability scale_to_percent=1.3, # scale the image to 70%-130% of its original size scale_axis_equally= False, # allow the axis to be scaled unequally (e.g. x more than y) rotation_deg=25, # rotate between -25 and +25 degrees shear_deg=10, # shear between -10 and +10 degrees translation_x_px=5, # translate between -5 and +5 px on the x-axis translation_y_px=5 # translate between -5 and +5 px on the y-axis ) fig = augmenter.plot_image(image, name=file, nb_repeat=20)