Augmentation Module

class src.bio_volumentations.augmentations.transforms.AffineTransform(angles: Tuple[float, float, float] = (0, 0, 0), translation: Tuple[float, float, float] = (0, 0, 0), scale: Tuple[float, float, float] = (1, 1, 1), spacing: Tuple[float, float, float] = (1, 1, 1), change_to_isotropic: bool = False, interpolation: str = 'linear', border_mode: str = 'constant', ival: float = 0, mval: float = 0, ignore_index: float | None = None, always_apply: bool = False, p: float = 0.5)[source]

Bases: DualTransform

Affine transformation of the input image with given parameters. Image shape remains unchanged.

Parameters:
  • angles (Tuple[float], optional) –

    Angles of rotation (in degrees) for the spatial axes.

    Must be: (A_Z, A_Y, A_X).

    Defaults to (0, 0, 0).

  • translation (Tuple[float], optional) –

    Translation vector for the spatial axes.

    Must be: (T_Z, T_Y, T_X).

    Defaults to (0, 0, 0).

  • scale (Tuple[float], optional) –

    Scales for the spatial axes.

    Must be: (S_Z, S_Y, S_X).

    Defaults to (1, 1, 1).

  • spacing (Tuple[float, float, float], optional) –

    Voxel spacing for individual spatial dimensions.

    Must be: (S1, S2, S3) (a scale for each spatial dimension must be given).

    Defaults to (1, 1, 1).

  • change_to_isotropic (bool, optional) –

    Change data from anisotropic to isotropic.

    Defaults to False.

  • interpolation (str, optional) –

    SimpleITK interpolation type for image and float_mask.

    Must be one of linear, nearest, bspline, gaussian.

    For mask, the nearest interpolation is always used.

    Defaults to linear.

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'constant'.

  • ival (float, optional) –

    Value of image voxels outside of the image domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • mval (float, optional) –

    Value of mask and float_mask voxels outside of the domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • ignore_index (float | None, optional) –

    If specified, then transformation of mask is done with border_mode = 'constant' and mval = ignore_index.

    If None, this argument is ignored.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_float_mask(mask, **params)[source]
apply_to_keypoints(keypoints, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.CenterCrop(shape: Tuple[int, int, int], border_mode: str = 'reflect', ival: Sequence[float] | float = (0, 0), mval: Sequence[float] | float = (0, 0), ignore_index: float | None = None, always_apply: bool = False, p: float = 1.0)[source]

Bases: DualTransform

Crop the central region of the given size from the input .

Unlike CenterCrop from Albumentations, this transform pads the input in dimensions where the input is smaller than the shape with numpy.pad. The border_mode, ival and mval arguments are forwarded to numpy.pad if padding is necessary. More details at: https://numpy.org/doc/stable/reference/generated/numpy.pad.html.

Parameters:
  • shape (Tuple[int]) –

    The desired shape of input.

    Must be [Z, Y, X].

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'reflect'.

  • ival (float | Sequence, optional) –

    Values of image voxels outside of the image domain. Only applied when border_mode = 'constant' or border_mode = 'linear_ramp'.

    Defaults to (0, 0).

  • mval (float | Sequence, optional) –

    Values of mask voxels outside of the mask domain. Only applied when border_mode = 'constant' or border_mode = 'linear_ramp'.

    Defaults to (0, 0).

  • ignore_index (float | None, optional) –

    If specified, then transformation of mask is done with border_mode = 'constant' and mval = ignore_index.

    If None, this argument is ignored.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_keypoints(keypoints, keep_all=False, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.Contiguous(always_apply: bool = True, p: float = 1.0)[source]

Bases: DualTransform

Transform the image data to a contiguous array.

Parameters:
  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to True.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image, mask, float mask

apply(image, **params)[source]
apply_to_mask(mask, **params)[source]
class src.bio_volumentations.augmentations.transforms.Flip(axes: List[int] | None = None, always_apply=False, p=1)[source]

Bases: DualTransform

Flip input around the specified spatial axes.

Parameters:
  • axes (List[int], optional) –

    List of axes around which is flip done. Recognised axis symbols are 1 for Z, 2 for Y, and 3 for X. If None, will be flipped around all spatial axes.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_keypoints(keypoints, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.GaussianBlur(sigma: float | tuple | List[tuple | float] = 0.8, border_mode: str = 'reflect', cval: float = 0, always_apply: bool = False, p: float = 0.5)[source]

Bases: ImageOnlyTransform

Perform Gaussian blurring of an image. In case of a multi-channel image, individual channels are blured separately.

Internally, the scipy.ndimage.gaussian_filter function is used. The border_mode and cval arguments are forwarded to it. More details at: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html.

Parameters:
  • sigma (float, Tuple(float), List[Tuple(float) | float] , optional) –

    Gaussian sigma.

    Must be either of: S, (S_Z, S_Y, S_X), (S_Z, S_Y, S_X, S_T), [S_1, S_2, ..., S_C], [(S_Z1, S_Y1, S_X1), (S_Z2, S_Y2, S_X2), ..., (S_ZC, S_YC, S_XC)], or [(S_Z1, S_Y1, S_X1, S_T1), (S_Z2, S_Y2, S_X2, S_T2), ..., (S_ZC, S_YC, S_XC, S_TC)].

    If a float, the spatial dimensions are blurred with the same strength (equivalent to (S, S, S)).

    If a tuple, the sigmas for spatial dimensions and possibly the time dimension must be specified.

    If a list, sigmas for each channel must be specified either as a single number or as a tuple.

    Defaults to 0.8.

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'reflect'.

  • cval (float, optional) –

    Value to fill past edges of image. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image

apply(img, **params)[source]
class src.bio_volumentations.augmentations.transforms.GaussianNoise(var_limit: Tuple[float, float] = (0.001, 0.1), mean: float = 0, always_apply: bool = False, p: float = 0.5)[source]

Bases: ImageOnlyTransform

Add Gaussian noise to the image. The noise is drawn from normal distribution with given parameters.

Parameters:
  • var_limit (tuple, optional) –

    Variance of normal distribution is randomly chosen from this interval.

    Defaults to (0.001, 0.1).

  • mean (float, optional) –

    Mean of normal distribution.

    Defaults to 0.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image

apply(img, **params)[source]
get_params(targets, **params)[source]
class src.bio_volumentations.augmentations.transforms.HistogramEqualization(bins: int = 256, always_apply: bool = False, p: float = 1)[source]

Bases: ImageOnlyTransform

Equalize image histogram. The equalization is done channel-wise, meaning that each channel is equalized separately.

Note

Warning! Images are normalized over the spatial and temporal axes together. The output is in range [0, 1].

Parameters:
  • bins (int, optional) –

    Number of bins for image histogram.

    Defaults to 256.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image

apply(img, **params)[source]
class src.bio_volumentations.augmentations.transforms.Normalize(mean: float | List[float] = 0, std: float | List[float] = 1, always_apply: bool = True, p: float = 1.0)[source]

Bases: ImageOnlyTransform

Change image mean and standard deviation to the given values (channel-wise).

Parameters:
  • mean (float | List[float], optional) –

    The desired channel-wise means.

    Must be either of: M (for single-channel images), [M_1, M_2, ..., M_C] (for multi-channel images).

    Defaults to 0.

  • std (float | List[float], optional) –

    The desired channel-wise standard deviations.

    Must be either of: S (for single-channel images), [S_1, S_2, ..., S_C] (for multi-channel images).

    Defaults to 1.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to True.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image

apply(img, **params)[source]
class src.bio_volumentations.augmentations.transforms.NormalizeMeanStd(mean: tuple | float, std: tuple | float, always_apply: bool = True, p: float = 1.0)[source]

Bases: ImageOnlyTransform

Normalize image values to mean 0 and standard deviation 1, given the channel-wise means and standard deviations.

For a single-channel image, the normalization is applied by the formula: \(img = (img - mean) / std\). If the image contains more channels, then the formula is used for each channel separately.

It is recommended to input dataset-wide means and standard deviations.

Parameters:
  • mean (float | List[float]) –

    Channel-wise image mean.

    Must be either of: M (for single-channel images), (M_1, M_2, ..., M_C) (for multi-channel images).

  • std (float | List[float]) –

    Channel-wise image standard deviation.

    Must be either of: S (for single-channel images), (S_1, S_2, ..., S_C) (for multi-channel images).

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to True.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image

apply(image, **params)[source]
class src.bio_volumentations.augmentations.transforms.Pad(pad_size: int | Tuple[int, int] | Tuple[int, int, int, int, int, int], border_mode: str = 'constant', ival: float | Sequence = 0, mval: float | Sequence = 0, ignore_index: float | None = None, always_apply: bool = True, p: float = 1)[source]

Bases: DualTransform

Pad the input.

Internally, the numpy.pad function is used. The border_mode, ival and mval arguments are forwarded to it. More details at: https://numpy.org/doc/stable/reference/generated/numpy.pad.html.

Parameters:
  • pad_size (int | Tuple[int]) –

    Number of pixels padded to the edges of each axis.

    Must be either of: P, (P1, P2), or (P_Z1, P_Z2, P_Y1, P_Y2, P_X1, P_X2).

    If an integer, it is equivalent to (P, P, P, P, P, P).

    If a tuple of two numbers, it is equivalent to (P1, P2, P1, P2, P1, P2).

    Otherwise, it must specify padding for all spatial dimensions.

    The unspecified dimensions (C and T) are not affected.

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'constant'.

  • ival (float | Sequence, optional) –

    Values of image voxels outside of the image domain. Only applied when border_mode = 'constant' or border_mode = 'linear_ramp'.

    Defaults to 0.

  • mval (float | Sequence, optional) –

    Values of mask voxels outside of the mask domain. Only applied when border_mode = 'constant' or border_mode = 'linear_ramp'.

    Defaults to 0.

  • ignore_index (float | None, optional) –

    If specified, then transformation of mask is done with border_mode = 'constant' and mval = ignore_index.

    If None, this argument is ignored.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to True.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_keypoints(keypoints, **params)[source]
apply_to_mask(mask, **params)[source]
class src.bio_volumentations.augmentations.transforms.PoissonNoise(peak_limit: Tuple[float, float] = (0.1, 0.5), always_apply: bool = False, p: float = 0.5)[source]

Bases: ImageOnlyTransform

Add Poisson noise to the image.

Parameters:
  • peak_limit (tuple) –

    Range to sample the expected intensity of Poisson noise.

    Defaults to (0.1, 0.5).

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image

apply(img, **params)[source]
get_params(targets, **params)[source]
class src.bio_volumentations.augmentations.transforms.RandomAffineTransform(angle_limit: float | Tuple[float, float] | Tuple[float, float, float] | Tuple[float, float, float, float, float, float] = (15.0, 15.0, 15.0), translation_limit: float | Tuple[float, float] | Tuple[float, float, float] | Tuple[float, float, float, float, float, float] = (0.0, 0.0, 0.0), scaling_limit: float | Tuple[float, float] | Tuple[float, float, float] | Tuple[float, float, float, float, float, float] = (1.0, 1.0, 1.0), spacing: float | Tuple[float, float, float] | None = None, change_to_isotropic: bool = False, interpolation: str = 'linear', border_mode: str = 'constant', ival: float = 0, mval: float = 0, ignore_index: float | None = None, always_apply: bool = False, p: float = 0.5)[source]

Bases: DualTransform

Affine transformation of the input image with randomly chosen parameters. Image shape remains unchanged.

Parameters:
  • angle_limit (Tuple[float] | float, optional) –

    Intervals (in degrees) from which angles of rotation for the spatial axes are chosen.

    Must be either of: A, (A1, A2), (A1, A2, A3), or (A_Z1, A_Z2, A_Y1, A_Y2, A_X1, A_X2).

    If a float, equivalent to (-A, A, -A, A, -A, A).

    If a tuple with 2 items, equivalent to (A1, A2, A1, A2, A1, A2).

    If a tuple with 3 items, equivalent to (-A1, A1, -A2, A2, -A3, A3).

    If a tuple with 6 items, angle of rotation is randomly chosen from an interval [A_a1, A_a2] for each spatial axis.

    Defaults to (15, 15, 15).

  • translation_limit (Tuple[float] | float | None, optional) –

    Intervals from which the translation parameters for the spatial axes are chosen.

    Must be either of: T, (T1, T2), (T1, T2, T3), or (T_Z1, T_Z2, T_Y1, T_Y2, T_X1, T_X2).

    If a float, equivalent to (2-T, T, 2-T, T, 2-T, T).

    If a tuple with 2 items, equivalent to (T1, T2, T1, T2, T1, T2).

    If a tuple with 3 items, equivalent to (2-T1, T1, 2-T2, T2, 2-T3, T3).

    If a tuple with 6 items, the translation parameter is randomly chosen from an interval [T_a1, T_a2] for each spatial axis.

    Defaults to (0, 0, 0).

  • scaling_limit (Tuple[float] | float, optional) –

    Intervals from which the scales for the spatial axes are chosen.

    Must be either of: S, (S1, S2), (S1, S2, S3), or (S_Z1, S_Z2, S_Y1, S_Y2, S_X1, S_X2).

    If a float, equivalent to (1/S, S, 1/S, S, 1/S, S).

    If a tuple with 2 items, equivalent to (S1, S2, S1, S2, S1, S2).

    If a tuple with 3 items, equivalent to (1/S1, S1, 1/S2, S2, 1/S3, S3).

    If a tuple with 6 items, the scale is randomly chosen from an interval [S_a1, S_a2] for each spatial axis.

    Defaults to (1., 1., 1.).

  • spacing (float | Tuple[float, float, float] | None, optional) –

    Voxel spacing for individual spatial dimensions.

    Must be either of: S, (S1, S2, S3), or None.

    If None, equivalent to (1, 1, 1).

    If a float S, equivalent to (S, S, S).

    Otherwise, a scale for each spatial dimension must be given.

    Defaults to None.

  • change_to_isotropic (bool, optional) –

    Change data from anisotropic to isotropic.

    Defaults to False.

  • interpolation (str, optional) –

    SimpleITK interpolation type for image and float_mask.

    Must be one of linear, nearest, bspline, gaussian.

    For mask, the nearest interpolation is always used.

    Defaults to linear.

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'constant'.

  • ival (float, optional) –

    Value of image voxels outside of the image domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • mval (float, optional) –

    Value of mask and float_mask voxels outside of the domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • ignore_index (float | None, optional) –

    If specified, then transformation of mask is done with border_mode = 'constant' and mval = ignore_index.

    If None, this argument is ignored.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_float_mask(mask, **params)[source]
apply_to_keypoints(keypoints, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.RandomBrightnessContrast(brightness_limit: float | Tuple[float, float] = 0.2, contrast_limit: float | Tuple[float, float] = 0.2, always_apply: bool = False, p: float = 0.5)[source]

Bases: ImageOnlyTransform

Randomly change brightness and contrast of the input image.

Unlike RandomBrightnessContrast from Albumentations, this transform is using the formula \(f(a) = (c+1) * a + b\), where \(c\) is contrast and \(b\) is brightness.

Parameters:
  • brightness_limit ((float, float) | float, optional) –

    Interval from which the change in brightness is randomly drawn. If the change in brightness is 0, the brightness will not change.

    Must be either of: B, (B1, B2).

    If a float, the interval will be (-B, B).

    Defaults to 0.2.

  • contrast_limit ((float, float) | float, optional) –

    Interval from which the change in contrast is randomly drawn. If the change in contrast is 1, the contrast will not change.

    Must be either of: C, (C1, C2).

    If a float, the interval will be (-C, C).

    Defaults to 0.2.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image

apply(img, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.RandomCrop(shape: Tuple[int, int, int], border_mode: str = 'reflect', ival: Sequence[float] | float = (0, 0), mval: Sequence[float] | float = (0, 0), ignore_index: float | None = None, always_apply: bool = False, p: float = 1.0)[source]

Bases: DualTransform

Randomly crop a region of the given size from the input.

Unlike RandomCrop from Albumentations, this transform pads the input in dimensions where the input is smaller than the shape with numpy.pad. The border_mode, ival and mval arguments are forwarded to numpy.pad if padding is necessary. More details at: https://numpy.org/doc/stable/reference/generated/numpy.pad.html.

Parameters:
  • shape (Tuple[int]) –

    The desired shape of input.

    Must be [Z, Y, X].

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'reflect'.

  • ival (float | Sequence, optional) –

    Values of image voxels outside of the image domain. Only applied when border_mode = 'constant' or border_mode = 'linear_ramp'.

    Defaults to (0, 0).

  • mval (float | Sequence, optional) –

    Values of mask voxels outside of the mask domain. Only applied when border_mode = 'constant' or border_mode = 'linear_ramp'.

    Defaults to (0, 0).

  • ignore_index (float | None, optional) –

    If specified, then transformation of mask is done with border_mode = 'constant' and mval = ignore_index.

    If None, this argument is ignored.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_keypoints(keypoints, keep_all=False, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.RandomFlip(axes_to_choose: None | List[int] | Tuple[int] = None, always_apply=False, p=0.5)[source]

Bases: DualTransform

Flip input around a set of axes randomly chosen from the input list of axis combinations.

Parameters:
  • axes_to_choose (List[int], Tuple[int], or None, optional) –

    List of axis indices from which some are randomly chosen. Recognised axis symbols are 1 for Z, 2 for Y, and 3 for X. The image will be flipped around the chosen axes.

    If None, a random subset of spatial axes is chosen, corresponding to inputting [1, 2, 3].

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_keypoints(keypoints, keep_all=False, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.RandomGamma(gamma_limit: Tuple[float, float] = (0.8, 1.2), always_apply: bool = False, p: float = 0.5)[source]

Bases: ImageOnlyTransform

Perform the gamma transformation with a randomly chosen gamma.

Note

If image values (in any channel) are outside the [0,1] interval, this transformation is not performed.

Parameters:
  • gamma_limit (Tuple(float), optional) –

    Interval from which gamma is selected.

    Defaults to (0.8, 1.2).

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image

apply(img, gamma=1, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.RandomGaussianBlur(max_sigma: float | tuple | List[tuple | float] = 0.8, min_sigma: float = 0, border_mode: str = 'reflect', cval: float = 0, always_apply: bool = False, p: float = 0.5)[source]

Bases: ImageOnlyTransform

Perform Gaussian blurring of an image with a random blurring strength. In case of a multi-channel image, individual channels are blured separately.

Behaves similarly to GaussianBlur. The Gaussian sigma is randomly drawn from the interval [min_sigma, s] for the respective s from max_sigma for each channel and dimension.

Internally, the scipy.ndimage.gaussian_filter function is used. The border_mode and cval arguments are forwarded to it. More details at: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html.

Parameters:
  • max_sigma (float, Tuple(float), List[Tuple(float) | float] , optional) –

    Maximum Gaussian sigma.

    Must be either of: S, (S_Z, S_Y, S_X), (S_Z, S_Y, S_X, S_T), [S_1, S_2, ..., S_C], [(S_Z1, S_Y1, S_X1), (S_Z2, S_Y2, S_X2), ..., (S_ZC, S_YC, S_XC)], or [(S_Z1, S_Y1, S_X1, S_T1), (S_Z2, S_Y2, S_X2, S_T2), ..., (S_ZC, S_YC, S_XC, S_TC)].

    If a float, the spatial dimensions are blurred equivalently (equivalent to (S, S, S)).

    If a tuple, the sigmas for spatial dimensions and possibly the time dimension must be specified.

    If a list, sigmas for each channel must be specified either as a single number or as a tuple.

    Defaults to 0.8.

  • min_sigma (float, optional) –

    Minimum Gaussian sigma for all channels and dimensions.

    Defaults to 0.

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'reflect'.

  • cval (float, optional) –

    Value to fill past edges of image. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image

apply(img, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.RandomRotate90(axes: List[int] | None = None, shuffle_axis: bool = False, factor: int | None = None, always_apply: bool = False, p: float = 0.5)[source]

Bases: DualTransform

Rotation of input by 0, 90, 180, or 270 degrees around the specified spatial axes.

Parameters:
  • axes (List[int], optional) –

    List of axes around which the input is rotated. Recognised axis symbols are 1 for Z, 2 for Y, and 3 for X. A single axis can occur multiple times in the list. If shuffle_axis = False, the order of axes determines the order of transformations. If None, will be rotated around all spatial axes.

    Defaults to None.

  • shuffle_axis (bool, optional) –

    If set to True, the order of rotations is random.

    Defaults to False.

  • factor (int, optional) –

    The number of times the array is rotated by 90 degrees. If None, will be chosen randomly.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_keypoints(keypoints, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.RandomScale(scaling_limit: float | Tuple[float, float] | Tuple[float, float, float] | Tuple[float, float, float, float, float, float] = (0.9, 1.1), interpolation: str = 'linear', spacing: float | Tuple[float, float, float] | None = None, border_mode: str = 'constant', ival: float = 0, mval: float = 0, ignore_index: float | None = None, always_apply: bool = False, p: float = 0.5)[source]

Bases: DualTransform

Randomly rescale the input image content by the given scale. The image shape remains unchanged.

Parameters:
  • scaling_limit (float | Tuple[float], optional) –

    Limits of scaling factors.

    Must be either of: S, (S1, S2), (S_Z, S_Y, S_X), or (S_Z1, S_Z2, S_Y1, S_Y2, S_X1, S_X2).

    If a float S, then all spatial dimensions are scaled by a random number drawn uniformly from the interval [1/S, S] (equivalent to inputting (1/S, S, 1/S, S, 1/S, S)).

    If a tuple of 2 floats, then all spatial dimensions are scaled by a random number drawn uniformly from the interval [S1, S2] (equivalent to inputting (S1, S2, S1, S2, S1, S2)).

    If a tuple of 3 floats, then an interval [1/S_a, S_a] is constructed for each spatial dimension and the scale is randomly drawn from it (equivalent to inputting (1/S_Z, S_Z, 1/S_Y, S_Y, 1/S_X, S_X)).

    If a tuple of 6 floats, the scales for individual spatial dimensions are randomly drawn from the respective intervals [S_Z1, S_Z2], [S_Y1, S_Y2], [S_X1, S_X2].

    The unspecified dimensions (C and T) are not affected.

    Defaults to (1.1).

  • interpolation (str, optional) –

    SimpleITK interpolation type for image and float_mask.

    Must be one of linear, nearest, bspline, gaussian.

    For mask, the nearest interpolation is always used.

    Defaults to linear.

  • spacing (float | Tuple[float, float, float] | None, optional) –

    Voxel spacing for individual spatial dimensions.

    Must be either of: S, (S1, S2, S3), or None.

    If None, equivalent to (1, 1, 1).

    If a float S, equivalent to (S, S, S).

    Otherwise, a scale for each spatial dimension must be given.

    Defaults to None.

  • border_mode (str, optional) –

    Values outside image domain are filled according to the mode.

    Defaults to 'constant'.

  • ival (float, optional) –

    Value of image voxels outside of the image domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • mval (float, optional) –

    Value of mask and float_mask voxels outside of the domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • ignore_index (float | None, optional) –

    If specified, then transformation of mask is done with border_mode = 'constant' and mval = ignore_index.

    If None, this argument is ignored.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 0.5.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_float_mask(mask, **params)[source]
apply_to_keypoints(keypoints, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.RemoveBackgroundGaussian(sigma: float | tuple | List[tuple | float] = 10, mode: str = 'default', border_mode: str = 'reflect', cval: float = 0, always_apply: bool = True, p: float = 1.0)[source]

Bases: ImageOnlyTransform

Remove background from the input image by subtracting a blurred image from the original image.

The background image is created using Gaussian blurring. In case of a multi-channel image, individual channels are blured separately.

Internally, the scipy.ndimage.gaussian_filter function is used. The border_mode and cval arguments are forwarded to it. More details at: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html.

Parameters:
  • sigma (float, Tuple(float), List[Tuple(float) | float] , optional) –

    Gaussian sigma.

    Must be either of: S, (S_Z, S_Y, S_X), (S_Z, S_Y, S_X, S_T), [S_1, S_2, ..., S_C], [(S_Z1, S_Y1, S_X1), (S_Z2, S_Y2, S_X2), ..., (S_ZC, S_YC, S_XC)], or [(S_Z1, S_Y1, S_X1, S_T1), (S_Z2, S_Y2, S_X2, S_T2), ..., (S_ZC, S_YC, S_XC, S_TC)].

    If a float, the spatial dimensions are blurred with the same strength (equivalent to (S, S, S)).

    If a tuple, the sigmas for spatial dimensions and possibly the time dimension must be specified.

    If a list, sigmas for each channel must be specified either as a single number or as a tuple.

    Defaults to 10.

  • mode (str, optional) –

    Mode of background removal. Possible values: 'default' (subtract blurred image from the input image), 'bright_objects' (subtract the point-wise minimum of (blurred image, input image) from the input image), 'dark_objects' (subtract the input image from the point-wise maximum of (blurred image, input image)).

    Defaults to 'default'.

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'reflect'.

  • cval (float, optional) –

    Value to fill past edges of image. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to True.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.0.

Targets:

image

apply(img, **params)[source]
class src.bio_volumentations.augmentations.transforms.Rescale(scales=1, interpolation: int = 1, border_mode: str = 'reflect', ival: float = 0, mval: float = 0, anti_aliasing_downsample: bool = True, ignore_index=None, always_apply: bool = True, p: float = 1, **kwargs)[source]

Bases: DualTransform

Rescale the input and change its shape accordingly.

Internally, the skimage.transform.resize function is used. The interpolation, border_mode, ival, mval, and anti_aliasing_downsample arguments are forwarded to it. More details at: https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.resize.

Parameters:
  • scales (float|List[float], optional) –

    Value by which the input should be scaled.

    Must be either of: S, [S_Z, S_Y, S_X].

    If a float, then all spatial dimensions are scaled by it (equivalent to [S, S, S]).

    The unspecified dimensions (C and T) are not affected.

    Defaults to 1.

  • interpolation (int, optional) –

    Order of spline interpolation.

    Defaults to 1.

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'reflect'.

  • ival (float, optional) –

    Value of image voxels outside of the image domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • mval (float, optional) –

    Value of mask and float_mask voxels outside of the domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • anti_aliasing_downsample (bool, optional) –

    Apply the Gaussian filter before downsampling. Recommended.

    Defaults to True.

  • ignore_index (float | None, optional) –

    If specified, then transformation of mask is done with border_mode = 'constant' and mval = ignore_index.

    If None, this argument is ignored.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to True.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_float_mask(mask, **params)[source]
apply_to_keypoints(keypoints, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.Resize(shape: Tuple[int, int, int], interpolation: int = 1, border_mode: str = 'reflect', ival: float = 0, mval: float = 0, anti_aliasing_downsample: bool = True, ignore_index: float | None = None, always_apply: bool = False, p: float = 1)[source]

Bases: DualTransform

Resize input to the given shape.

Internally, the skimage.transform.resize function is used. The interpolation, border_mode, ival, mval, and anti_aliasing_downsample arguments are forwarded to it. More details at: https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.resize.

Parameters:
  • shape (tuple of ints) –

    The desired image shape.

    Must be (Z, Y, X).

    The unspecified dimensions (C and T) are not affected.

  • interpolation (int, optional) –

    Order of spline interpolation.

    Defaults to 1.

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'reflect'.

  • ival (float, optional) –

    Value of image voxels outside of the image domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • mval (float, optional) –

    Value of mask and float_mask voxels outside of the domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • anti_aliasing_downsample (bool, optional) –

    Apply the Gaussian filter before downsampling. Recommended.

    Defaults to True.

  • ignore_index (float | None, optional) –

    If specified, then transformation of mask is done with border_mode = 'constant' and mval = ignore_index.

    If None, this argument is ignored.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_float_mask(mask, **params)[source]
apply_to_keypoints(keypoints, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.Scale(scales: float | Tuple[float, float, float] = 1, interpolation: str = 'linear', spacing: float | Tuple[float, float, float] | None = None, border_mode: str = 'constant', ival: float = 0, mval: float = 0, ignore_index: float | None = None, always_apply: bool = False, p: float = 1)[source]

Bases: DualTransform

Rescale the input image content by the given scale. The image shape remains unchanged.

Parameters:
  • scales (float|List[float], optional) –

    Value by which the input should be scaled.

    Must be either of: S, [S_Z, S_Y, S_X].

    If a float, then all spatial dimensions are scaled by it (equivalent to [S, S, S]).

    The unspecified dimensions (C and T) are not affected.

    Defaults to 1.

  • interpolation (str, optional) –

    SimpleITK interpolation type for image and float_mask.

    Must be one of linear, nearest, bspline, gaussian.

    For mask, the nearest interpolation is always used.

    Defaults to linear.

  • spacing (float | Tuple[float, float, float] | None, optional) –

    Voxel spacing for individual spatial dimensions.

    Must be either of: S, (S1, S2, S3), or None.

    If None, equivalent to (1, 1, 1).

    If a float S, equivalent to (S, S, S).

    Otherwise, a scale for each spatial dimension must be given.

    Defaults to None.

  • border_mode (str, optional) –

    Values outside image domain are filled according to this mode.

    Defaults to 'constant'.

  • ival (float, optional) –

    Value of image voxels outside of the image domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • mval (float, optional) –

    Value of mask and float_mask voxels outside of the domain. Only applied when border_mode = 'constant'.

    Defaults to 0.

  • ignore_index (float | None, optional) –

    If specified, then transformation of mask is done with border_mode = 'constant' and mval = ignore_index.

    If None, this argument is ignored.

    Defaults to None.

  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to False.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image, mask, float mask, key points, bounding boxes

apply(img, **params)[source]
apply_to_float_mask(mask, **params)[source]
apply_to_keypoints(keypoints, **params)[source]
apply_to_mask(mask, **params)[source]
get_params(targets, **data)[source]
class src.bio_volumentations.augmentations.transforms.StandardizeDatatype(always_apply: bool = True, p: float = 1.0)[source]

Bases: DualTransform

Change image and float_mask datatype to np.float32 without changing the intensities. Change mask datatype to np.int32.

Parameters:
  • always_apply (bool, optional) –

    Always apply this transformation in composition.

    Defaults to True.

  • p (float, optional) –

    Probability of applying this transformation in composition.

    Defaults to 1.

Targets:

image, mask, float mask

apply(image, **params)[source]
apply_to_float_mask(mask, **params)[source]
apply_to_mask(mask, **params)[source]