def full_trans(im): rotated = aug.random_rotation(im, sd=10, **newcrop) cropped = aug.randn_crop(rotated, sd=10, **newcrop) flipped = aug.random_flip(cropped) coloured = aug.random_colour_transform(flipped, rgb_eigval, rgb_eigvec) return imresize(coloured, (256, 256))
'bottom': crop['y'] + crop['height']} cropped_im = \ im[newcrop['top']:newcrop['bottom'], newcrop['left']:newcrop['right']] def gamma_augmentation(im, sd=0.3, lower_bound=0.1, upper_bound=100.0): gamma = 1.0 + np.random.randn() * sd gamma = np.clip(gamma, lower_bound, upper_bound) return im ** (1.0 / gamma) ############################################ # GAMMA tic = time() ims = [aug.randn_crop(im, sd=0, **newcrop) for _ in range(24)] ims = [gamma_augmentation(im) for im in ims] ims = [cropped_im] + ims print "Gamma correction took %fs per image" % ((time()-tic)/24.0) plot_grid(ims, savepath + 'gamma.png') sdsd ############################################ # ROTATIONS tic = time() rots = [aug.random_rotation(im, sd=10, **newcrop) for _ in range(24)] rots = [aug.randn_crop(im, sd=0, **newcrop) for im in rots] ims = [cropped_im] + rots print "Rotating took %fs per image" % ((time()-tic)/24.0) plot_grid(ims, savepath + 'rotations.png')