trw.transforms.transforms_random_crop_pad
¶
Module Contents¶
Classes¶
Add padding on a numpy array of samples and random crop to original size |
Functions¶
|
Add a specified padding to the image and randomly crop it so that we have the same shape as the original |
- trw.transforms.transforms_random_crop_pad._transform_random_crop_pad(features_names, batch, padding, mode='edge', constant_value=0, shape=None)¶
Add a specified padding to the image and randomly crop it so that we have the same shape as the original image
This support joint padding & cropping of multiple arrays (e.g., to support segmentation maps)
- Parameters
features_names – the name of the features to be jointly random cropped
batch – the batch to transform
padding – a sequence of shape len(array.shape)-1 indicating the width of the padding to be added at the beginning and at the end of each dimension (except for dimension 0)
mode – numpy.pad mode. Currently supported are (‘constant’, ‘edge’, ‘symmetric’)
shape – if None, the image will be cropped to the original shape, else it must be a list of the shape to crop for each dimension except for dimension 0
- Returns
a padded and cropped image to original shape
- class trw.transforms.transforms_random_crop_pad.TransformRandomCropPad(padding: Optional[trw.basic_typing.ShapeCX], criteria_fn: Optional[trw.transforms.transforms.CriteriaFn] = None, mode: typing_extensions.Literal[constant, edge, symmetric] = 'constant', constant_value: trw.basic_typing.Numeric = 0, shape: Optional[trw.basic_typing.ShapeCX] = None)¶
Bases:
trw.transforms.transforms.TransformBatchWithCriteria
Add padding on a numpy array of samples and random crop to original size
- Parameters
padding – a sequence of size len(array.shape)-1 indicating the width of the padding to be added at the beginning and at the end of each dimension (except for dimension 0). If None, no padding added
criteria_fn – function applied on each feature. If satisfied, the feature will be transformed, if not the original feature is returned
mode – numpy.pad mode. Currently supported are (‘constant’, ‘edge’, ‘symmetric’)
shape – the size of the cropped image. If None, same size as input image
- Returns
a randomly cropped batch