solt.transforms

class solt.transforms.Flip(p=0.5, axis=1, data_indices=None)[source]

Random Flipping transform.

Parameters:
  • p (float) – Probability of flip
  • axis (int) – Flipping axis. 0 - vertical, 1 - horizontal, etc. -1 - all axes.
serializable_name = 'flip'

How the class should be stored in the registry

class solt.transforms.Rotate(angle_range=None, interpolation='bilinear', padding='z', p=0.5, ignore_state=True, ignore_fast_mode=False)[source]

Random rotation around the center clockwise

Parameters:
  • angle_range (tuple or float or None) – Range of rotation. If float, then (-angle_range, angle_range) will be used for transformation sampling. if None, then angle_range=(0,0).
  • interpolation (str or tuple or None) – Interpolation type. Check the allowed interpolation types.
  • padding (str or tuple or None) – Padding mode. Check the allowed padding modes.
  • p (float) – Probability of using this transform
  • ignore_state (bool) – Whether to ignore the state. See details in the docs for MatrixTransform.
sample_transform_matrix(data)[source]

Samples random rotation within specified range and saves it as an object state.

serializable_name = 'rotate'

How the class should be stored in the registry

class solt.transforms.Shear(range_x=None, range_y=None, interpolation='bilinear', padding='z', p=0.5, ignore_state=True, ignore_fast_mode=False)[source]

Random shear around the center.

Parameters:
  • range_x (tuple or float or None) – Shearing range along X-axis. If float, then (-range_x, range_x) will be used. If None, then range_x=(0, 0)
  • range_y (tuple or float or None) – Shearing range along Y-axis. If float, then (-range_y, range_y) will be used. If None, then range_y=(0, 0)
  • interpolation (str or tuple or None or tuple or None) – Interpolation type. Check the allowed interpolation types.
  • padding (str) – Padding mode. Check the allowed padding modes.
  • p (float) – Probability of using this transform
  • ignore_state (bool) – Whether to ignore the state. See details in the docs for MatrixTransform.
sample_transform_matrix(data)[source]

Method that is called to sample the transform matrix

serializable_name = 'shear'

How the class should be stored in the registry

class solt.transforms.Scale(range_x=None, range_y=None, same=True, interpolation='bilinear', p=0.5, ignore_state=True, padding=None, ignore_fast_mode=False)[source]

Random scale transform.

Parameters:
  • range_x (tuple or float or None) – Scaling range along X-axis. If float, then (min(1, range_x), max(1, range_x)) will be used. If None, then range_x =(1,1) by default.
  • range_y (tuple or float) – Scaling range along Y-axis. If float, then (min(1, range_y), max(1, range_y)) will be used. If None, then range_y=(1,1) by default.
  • same (bool) – Indicates whether to use the same scaling factor for width and height.
  • interpolation (str or tuple or None) – Interpolation type. Check the allowed interpolation types. one indicates default behavior - the bilinear mode.
  • padding (str) – z (zero pad) or r - reflective pad.
  • p (float) – Probability of using this transform
  • ignore_state (bool) – Whether to ignore the state. See details in the docs for MatrixTransform.
sample_transform_matrix(data)[source]

Method that is called to sample the transform matrix

serializable_name = 'scale'

How the class should be stored in the registry

class solt.transforms.Translate(range_x=None, range_y=None, interpolation='bilinear', padding='z', p=0.5, ignore_state=True, ignore_fast_mode=False)[source]

Random Translate transform..

Parameters:
  • range_x (tuple or int or None) – Translation range along the horizontal axis. If int, then range_x=(-range_x, range_x). If None, then range_x=(0,0).
  • range_y (tuple or int or None) – Translation range along the vertical axis. If int, then range_y=(-range_y, range_y). If None, then range_y=(0,0).
  • interpolation (str) – Interpolation type. See allowed_interpolations in constants.
  • padding (str) – Padding mode. See allowed_paddings in constants
  • p (float) – probability of applying this transform.
sample_transform_matrix(data)[source]

Method that is called to sample the transform matrix

serializable_name = 'translate'

How the class should be stored in the registry

class solt.transforms.Projection(affine_transforms=None, v_range=None, interpolation='bilinear', padding='z', p=0.5, ignore_state=True, ignore_fast_mode=False)[source]

Random Projective transform.

Takes a set of affine transforms.

Parameters:
  • affine_transforms (Stream or None) – Stream object, which has a parameterized Affine Transform. If None, then a zero degrees rotation matrix is instantiated.
  • v_range (tuple or None) – Projective parameters range. If None, then v_range = (0, 0)
  • p (float) – Probability of using this transform.
sample_transform_matrix(data)[source]

Method that is called to sample the transform matrix

serializable_name = 'projection'

How the class should be stored in the registry

class solt.transforms.Pad(pad_to=None, padding=None)[source]

Pads the input to a given size.

Parameters:
  • pad_to (tuple or int or None) –

    Target size (new_height, new_width, ...). Trailing channel dimension is kept unchanged and the corresponding padding must be excluded. The padding is computed using the following equations:

    pre_pad[k] = (pad_to[k] - shape_in[k]) // 2 post_pad[k] = pad_to[k] - shape_in[k] - pre_pad[k]

  • padding (str) – Padding type.

See also

solt.constants.allowed_paddings

serializable_name = 'pad'

How the class should be stored in the registry

class solt.transforms.Crop(crop_to=None, crop_mode='c')[source]

Center / Random crop transform.

Object performs center or random cropping depending on the parameters.

Parameters:
  • crop_to (tuple or int or None) – Size of the crop (height_new, width_new, ...). If int, then a square crop will be made.
  • crop_mode (str) – Crop mode. Can be either 'c' - center or 'r' - random.

See also

solt.constants.ALLOWED_CROPS

serializable_name = 'crop'

How the class should be stored in the registry

class solt.transforms.Noise(p=0.5, gain_range=0.1, data_indices=None)[source]

Adds noise to an image. Other types of data than the image are ignored.

Parameters:
  • p (float) – Probability of applying this transform,
  • gain_range (tuple or float or None) – Gain of the noise. Final image is created as (1-gain)*img + gain*noise. If float, then gain_range = (0, gain_range). If None, then gain_range=(0, 0).
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.
serializable_name = 'noise'

How the class should be stored in the registry

class solt.transforms.GammaCorrection(p=0.5, gamma_range=0.1, data_indices=None)[source]

Transform applies random gamma correction

Parameters:
  • p (float) – Probability of applying this transform,
  • gamma_range (tuple or float or None) – Gain of the noise. Indicates percentage of indices, which will be changed. If float, then gain_range = (1-gamma_range, 1+gamma_range).
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.
serializable_name = 'gamma_correction'

How the class should be stored in the registry

class solt.transforms.SaltAndPepper(p=0.5, gain_range=0.1, salt_p=0.5, data_indices=None)[source]

Adds salt and pepper noise to an image. Other types of data than the image are ignored.

Parameters:
  • p (float) – Probability of applying this transform,
  • gain_range (tuple or float or None) – Gain of the noise. Indicates percentage of indices, which will be changed. If float, then gain_range = (0, gain_range).
  • salt_p (float or tuple or None) – Percentage of salt. Percentage of pepper is 1-salt_p. If tuple, then salt_p is chosen uniformly from the given range.
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.
serializable_name = 'salt_and_pepper'

How the class should be stored in the registry

class solt.transforms.Blur(p=0.5, blur_type='g', k_size=3, gaussian_sigma=None, data_indices=None)[source]

Transform blurs an image

Parameters:
  • p (float) – Probability of applying this transform,
  • blur_type (str) – Blur type. See allowed blurs in solt.constants
  • k_size (int or tuple) – Kernel sizes of the blur. if int, then sampled from (k_size, k_size). If tuple, then sampled from the whole tuple. All the values here must be odd.
  • gaussian_sigma (int or float or tuple) – Gaussian sigma value. Used for both X and Y axes. If None, then gaussian_sigma=1.
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.

See also

solt.constants.ALLOWED_BLURS

serializable_name = 'blur'

How the class should be stored in the registry

class solt.transforms.HSV(h_range=None, s_range=None, v_range=None, data_indices=None, p=0.5)[source]

Performs a random HSV color shift.

Parameters:
  • h_range (tuple or None) – Hue shift range. If None, than h_range=(0, 0).
  • s_range (tuple or None) – Saturation shift range. If None, then s_range=(0, 0).
  • v_range (tuple or None) – Value shift range. If None, then v_range=(0, 0).
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.
  • p (float) – Probability of applying this transform,
serializable_name = 'hsv'

How the class should be stored in the registry

class solt.transforms.IntensityRemap(kernel_size=9, data_indices=None, p=0.5)[source]

Performs random intensity remapping [1].

Parameters:
  • p (float) – Probability of applying this transform,
  • kernel_size (int) – Size of medial filter kernel used during the generation of intensity mapping. Higher value yield more monotonic mapping.
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.

References

[1]Hesse, L. S., Kuling, G., Veta, M., & Martel, A. L. (2019). Intensity augmentation for domain transfer of whole breast segmentation in MRI. https://arxiv.org/abs/1909.02642
serializable_name = 'intensity_remap'

How the class should be stored in the registry

class solt.transforms.CvtColor(mode=None, keep_dim=True, data_indices=None, p=1)[source]

RGB to grayscale or grayscale to RGB image conversion.

If converting from grayscale to RGB, then the gs channel is simply clonned. If converting from RGB to grayscale, then opencv is used.

Parameters:
  • mode (str or None) – Color conversion mode. If None, then no conversion happens and mode=none. If mode == 'rgb2gs' and the image is already grayscale, then nothing happens. If mode == 'gs2rgb' and the image is already RGB, then also nothing happens.
  • keep_dim (bool) – Whether to enforce having three channels when performing rgb to grayscale conversion
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.
  • p (float) – Probability of the transform’s use. 1 by default

See also

solt.constants.ALLOWED_COLOR_CONVERSIONS

serializable_name = 'cvt_color'

How the class should be stored in the registry

class solt.transforms.Resize(resize_to=None, interpolation='bilinear')[source]

Transformation, which resizes the input to a given size

Parameters:
  • resize_to (tuple or int or None) – Target size (height_new, width_new).
  • interpolation – Interpolation type.

See also

solt.constants.allowed_interpolations

serializable_name = 'resize'

How the class should be stored in the registry

class solt.transforms.Contrast(p=0.5, contrast_range=0.1, data_indices=None)[source]

Transform randomly changes the contrast

Parameters:
  • p (float) – Probability of applying this transform,
  • contrast_range (tuple or float or None) – Gain of the noise. Indicates percentage of indices, which will be changed. If float, then gain_range = (1-contrast_range, 1+contrast_range).
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.
serializable_name = 'contrast'

How the class should be stored in the registry

class solt.transforms.Brightness(brightness_range=None, data_indices=None, p=0.5)[source]

Performs a random brightness augmentation

Parameters:
  • p (float) – Probability of applying this transform,
  • brightness_range (tuple or None) – brightness_range shift range. If None, then brightness_range=(0, 0).
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.
serializable_name = 'brightness'

How the class should be stored in the registry

class solt.transforms.Rotate90(k=0, p=0.5, ignore_fast_mode=False)[source]

Random rotation around the center by 90 degrees.

Parameters:
  • k (int) – How many times to rotate the data. If positive, indicates the clockwise direction. Zero by default.
  • p (float) – Probability of using this transform
serializable_name = 'rotate_90'

How the class should be stored in the registry

class solt.transforms.CutOut(cutout_size=2, data_indices=None, p=0.5)[source]

Does cutout augmentation.

https://arxiv.org/abs/1708.04552

Parameters:
  • cutout_size (tuple or int or float or None) – The size of the cutout. If None, then it is equal to 2.
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.
  • p (float) – Probability of applying this transform.
serializable_name = 'cutout'

How the class should be stored in the registry

class solt.transforms.KeypointsJitter(p=0.5, dx_range=None, dy_range=None)[source]

Applies the jittering to the keypoints in X- and Y-durections

Parameters:
  • p (float) – Probability of applying the transform
  • dx_range (None or float or tuple of float) – Jittering across X-axis. Valid range is (-1, 1)
  • dy_range (None or float or tuple of float) – Jittering across Y-axis. Valid range is (-1, 1)
serializable_name = 'keypoints_jitter'

How the class should be stored in the registry

class solt.transforms.JPEGCompression(p=0.5, quality_range=None, data_indices=None)[source]

Performs random JPEG-based worsening of images.

Parameters:
  • quality_range (float or tuple of int or int or None) –

    If float, then the lower bound to sample the quality is between (quality_range*100%, 100%).

    If tuple of int, then it directly sets the quality range.

    If tuple of float, then the quality is sampled from [quality_range[0]*100%, quality_range[1]*100%].

    If int, then the quality is sampled from [quality_range, 100]. . If None, that the quality range is [100, 100].

  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.
serializable_name = 'jpeg_compression'

How the class should be stored in the registry

class solt.transforms.GridMask(d_range=None, ratio=0.6, rotate=0, mode=None, data_indices=None, p=0.5)[source]

Performs a GridMask augmentation.

https://arxiv.org/abs/2001.04086

Parameters:
  • d_range (int or tuple or None) – The range of parameter d. If tuple, then the d is chosen between (d_range[0], d_range[1]). If none, then the d is chosen between (1, 2).
  • ratio (float) – The value of parameter ratio, defines the distance between GridMask squares.
  • rotate (int or tuple or None) – If int, then the angle of grid mask rotation is between (-rotate, rotate). If tuple, then the angle of grid mask rotation is between (rotate[0], rotate[1]).
  • mode (str or None) – GridMask mode. If 'crop', then the default GridMask is applied. If 'crop', the inversed GridMask is applied.
  • data_indices (tuple or None) – Indices of the images within the data container to which this transform needs to be applied. Every element within the tuple must be integer numbers. If None, then the transform will be applied to all the images withing the DataContainer.
  • p (float) – Probability of applying this transform.
serializable_name = 'gridmask'

How the class should be stored in the registry