crumpets.augmentation module¶
- crumpets.augmentation.make_transform(source_size, target_size, angle=0, scale=1, aspect=1, shift=None, hmirror=False, vmirror=False, shear=None, scale_mode='shortest', __identity__=array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]))[source]¶
- crumpets.augmentation.randomize_image(im, size, background=None, color=True, angle=0, scale=1, shift=None, aspect=1, hmirror=False, vmirror=False, interp_method=1, gamma_gray=None, gamma_color=None, contrast=None, noise=None, blur=None, shear=None, is_rgb=True, scale_mode='shortest', supersampling=0, gpu_augmentation=False, do_rotate_and_resize=True)[source]¶
Randomizes image according to given parameters.
- Parameters
im – image to be transformed.
size – target size of resulting image.
background – background color that fills areas in the output where there is no pixel data; can be number or tuple with same number of elements as channel
color – Boolean that flags if image is black-white or colored.
angle – degrees of rotation
scale – Scales the image with respect to its target size. scale=1.0 scales the image to fit perfectly within the target size. Based on scale_mode either the shorter or longer edge is used as reference. scale=2.0 doubles the length of the sides, scale=0.5 halves it.
shift – tuple of int (x,y) defining a shift of the picture, may create undefined space, if source image is moved out of target image, filled up with background color.
aspect – float of aspect ratio change
hmirror – boolean flag for horizontal mirror
vmirror – boolean flag for vertical mirror
interp_method – some interpolation method. At the moment one of: INTERP_NEAREST INTERP_LINEAR INTERP_CUBIC INTERP_LANCZOS4 INTERP_AERA
gamma_gray – float defining a black-white gamma
gamma_color – tuple of floats defining a rgb gamma
contrast – float between -1 and 1 defining a contrast change
noise – float defining a noise strength
blur – float defining a blur intensity, i.e. the standard deviation of a gaussian filter relative to image width
shear – float defining shear intensity, i.e. the gradient of the horizontal edges. A shear of 0.0 therefore creates a rectangular image.
is_rgb – boolean that flags if rgb color encoding is used
scale_mode – Either ‘shortest’ or ‘longest’. Scale the image using either shortest or longest edge as reference. ‘shortest’ crops part of the image if the aspect ratio of image and target size do not match. ‘longest’ ensures that the whole image can be fit into target size. A scale > 1.0 makes it bigger than target image, thus parts of it get cut out. A scale < 1.0 makes it smaller than target image, thus parts of the target image are undefined and filled up with background.
supersampling – supersampling factor, 1 turns off supersampling, 2 means 4 samples per pixel, 3 means 9 samples and so on; default of 0 means choose best based on true image size, output size and scale factor
gpu_augmentation – boolean that flags if gpu augmentations is used elsewhere and thus disables cpu augmentations in this method for all augmentations where gpu versions are available.
do_rotate_and_resize – boolean that flags if rotation and resize operations are used. Mostly used for test cases. Should usually not be changed.
- Returns
randomized image