Warp an image according to a given coordinate transformation
tefla.da.data.fast_warp (img, tf, output_shape, mode='constant', mode_cval=0, order=0)
This wrapper function is faster than skimage.transform.warp
Args
- img:
ndarray
, input image - tf: For 2-D images, you can directly pass a transformation object e.g. skimage.transform.SimilarityTransform, or its inverse.
- output_shape: tuple, (rows, cols)
- mode: mode for transformation
available modes: {
constant
,edge
,symmetric
,reflect
,wrap
} - mode_cval: float, Used in conjunction with mode
constant
, the value outside the image boundaries - order: int, The order of interpolation. The order has to be in the range 0-5: 0: Nearest-neighbor 1: Bi-linear (default) 2: Bi-quadratic 3: Bi-cubic 4: Bi-quartic 5: Bi-quintic
Returns
warped, double ndarray
Transform input image contrast
tefla.da.data.contrast_transform (img, contrast_min=0.8, contrast_max=1.2)
Transform the input image contrast by a factor returned by a unifrom
distribution with contarst_min
and contarst_max
as params
Args
- img:
ndarray
, input image - contrast_min: float, minimum contrast for transformation
- contrast_max: float, maximum contrast for transformation
Returns
ndarray
, contrast enhanced image
Transform input image brightness
tefla.da.data.brightness_transform (img, brightness_min=0.93, brightness_max=1.4)
Transform the input image brightness by a factor returned by a unifrom
distribution with brightness_min
and brightness_max
as params
Args
- img:
ndarray
, input image - brightness_min: float, minimum contrast for transformation
- brightness_max: float, maximum contrast for transformation
Returns
ndarray
, brightness transformed image
Rescale Transform
tefla.da.data.build_rescale_transform_slow (downscale_factor, image_shape, target_shape)
This mimics the skimage.transform.resize function. The resulting image is centered.
Args
- downscale_factor: float, >1
- image_shape: tuple(rows, cols), input image shape
- target_shape: tuple(rows, cols), output image shape
Returns
rescaled centered image transform instance
Rescale Transform
tefla.da.data.build_rescale_transform_fast (downscale_factor, image_shape, target_shape)
estimating the correct rescaling transform is slow, so just use the downscale_factor to define a transform directly. This probably isn't 100% correct, but it shouldn't matter much in practice. The resulting image is centered.
Args
- downscale_factor: float, >1
- image_shape: tuple(rows, cols), input image shape
- target_shape: tuple(rows, cols), output image shape
Returns
rescaled and centering transform instance
Image cetering transform
tefla.da.data.build_centering_transform (image_shape, target_shape)
Args
- image_shape: tuple(rows, cols), input image shape
- target_shape: tuple(rows, cols), output image shape
Returns
a centering transform instance
Center Unceter transform
tefla.da.data.build_center_uncenter_transforms (image_shape)
These are used to ensure that zooming and rotation happens around the center of the image. Use these transforms to center and uncenter the image around such a transform.
Args
- image_shape: tuple(rows, cols), input image shape
Returns
a center and an uncenter transform instance
Augmentation transform
tefla.da.data.build_augmentation_transform (zoom= (1.0, 1.0), rotation=0, shear=0, translation= (0, 0), flip=False)
It performs zooming, rotation, shear, translation and flip operation Affine Transformation on the input image
Args
- zoom: a tuple(zoom_rows, zoom_cols)
- rotation: float, Rotation angle in counter-clockwise direction as radians.
- shear: float, shear angle in counter-clockwise direction as radians
- translation: tuple(trans_rows, trans_cols)
- flip: bool, flip an image
Returns
augment tranform instance
Random perturbation
tefla.da.data.random_perturbation_transform (zoom_range, rotation_range, shear_range, translation_range, do_flip=True, allow_stretch=False, rng=
It perturbs the image randomly
Args
- zoom_range: a tuple(min_zoom, max_zoom) e.g.: (1/1.15, 1.15)
- rotation_range: a tuple(min_angle, max_angle) e.g.: (0. 360)
- shear_range: a tuple(min_shear, max_shear) e.g.: (0, 15)
- translation_range: a tuple(min_shift, max_shift) e.g.: (-15, 15)
- do_flip: bool, flip an image
- allow_stretch: bool, stretch an image
- rng: an instance
Returns
augment transform instance
crop an image
tefla.da.data.definite_crop (img, bbox)
Args
- img:
ndarray
, input image - bbox: list, with crop co-ordinates and width and height e.g.: [x, y, width, height]
Returns
returns cropped image
Perturb image
tefla.da.data.perturb (img, augmentation_params, target_shape, rng=
It perturbs an image with augmentation transform
Args
- img: a
ndarray
, input image - augmentation_paras: a dict, with augmentation name as keys and values as params
- target_shape: a tuple(rows, cols), output image shape
- rng: an instance for random number generation
- mode: mode for transformation
available modes: {
constant
,edge
,symmetric
,reflect
,wrap
} - mode_cval: float, Used in conjunction with mode
constant
, the value outside the image boundaries
Returns
a ndarray
of transformed image
Perturb image rescaled
tefla.da.data.perturb_rescaled (img, scale, augmentation_params, target_shape= (224, 224), rng=
It perturbs an image with augmentation transform
Args
- img: a
ndarray
, input image - scale: float, >1, downscaling factor.
- augmentation_paras: a dict, with augmentation name as keys and values as params
- target_shape: a tuple(rows, cols), output image shape
- rng: an instance for random number generation
- mode: mode for transformation
available modes: {
constant
,edge
,symmetric
,reflect
,wrap
} - mode_cval: float, Used in conjunction with mode
constant
, the value outside the image boundaries
Returns
a ndarray
of transformed image
Perturb image Determinastic
tefla.da.data.perturb_fixed (img, tform_augment, target_shape= (50, 50), mode='constant', mode_cval=0)
It perturbs an image with augmentation transform with determinastic params used for validation/testing data
Args
- img: a
ndarray
, input image - augmentation_paras: a dict, with augmentation name as keys and values as params
- target_shape: a tuple(rows, cols), output image shape
- mode: mode for transformation
available modes: {
constant
,edge
,symmetric
,reflect
,wrap
} - mode_cval: float, Used in conjunction with mode
constant
, the value outside the image boundaries
Returns
a ndarray
of transformed image
Load augmented image with output shape (w, h)
tefla.da.data.load_augment (fname, preprocessor, w, h, is_training, aug_params={'zoom_range':(1.0, 1.0), 'translation_range':(0, 0), 'shear_range':(0, 0), 'do_flip': False, 'allow_stretch': False, 'rotation_range':(0, 0)}, transform=None, bbox=None, fill_mode='constant', fill_mode_cval=0, standardizer=None, save_to_dir=None)
Default arguments return non augmented image of shape (w, h). To apply a fixed transform (color augmentation) specify transform (color_vec). To generate a random augmentation specify aug_params and sigma.
Args
- fname: string, image filename
- preprocessor: real-time image processing/crop
- w: int, width of target image
- h: int, height of target image
- is_training: bool, if True then training else validation
- aug_params: a dict, augmentation params
- transform: transform instance
- bbox: object bounding box
- fll_mode: mode for transformation
available modes: {
constant
,edge
,symmetric
,reflect
,wrap
} - fill_mode_cval: float, Used in conjunction with mode
constant
, the value outside the image boundaries - standardizer: image standardizer, zero mean, unit variance image e.g.: samplewise standardized each image based on its own value
- save_to_dir: a string, path to save image, save output image to a dir
Returns
augmented image
Open Image
tefla.da.data.image_no_preprocessing (fname)
Args
- fname: Image filename
Returns
PIL formatted image
Load batch of images
tefla.da.data.load_images (imgs, preprocessor=
Args
- imgs: a list of image filenames
- preprocessor: image processing function
Returns
a ndarray
with a batch of images
Load image
tefla.da.data.load_image (img, preprocessor=
Args
- img: a image filename
- preprocessor: image processing function
Returns
a processed image
Save image
tefla.da.data.save_image (x, fname)
Args
- x: input array
- fname: filename of the output image
Data balancing utility
tefla.da.data.balance_per_class_indices (y, weights)
Args
- y: class labels
- weights: sampling weights per class
Returns
balanced batch as per weights