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', ival: float = 0, mval: float = 0, ignore_index: float | None = None, keep_all: bool = False, min_volume: float | None = None, min_percentage: float | None = None, always_apply: bool = False, p: float = 1)[source]
Bases:
DualTransformAffine 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. The image is rotated around its center.
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). All values must be positive; values <=0 will be ignored and the respective axis will not be scaled.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
nearestinterpolation is always used.Defaults to
linear.ival (float, optional) –
Value of image voxels outside the image domain. Only applied when
border_mode = 'constant'.Defaults to
0.mval (float, optional) –
Value of mask and float_mask voxels outside 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'andmval = ignore_index.If
None, this argument is ignored.Defaults to
None.keep_all (bool, optional) –
When true, ALL keypoints and bounding boxes will be kept, even when they fully lie outside the image domain. Overrides min_volume and min_percentage.
Defaults to
False.min_volume (float, optional) –
Volume threshold below which bounding boxes will be removed. Is mutually exclusive with min_percentage.
Defaults to
Nonemin_percentage (float, optional) –
Percentage threshold below which bounding boxes will be removed. Value between 0.0 and 1.0. Is mutually exclusive with min_volume.
Defaults to
Nonealways_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
- 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, keep_all: bool = False, min_volume: float | None = None, min_percentage: float | None = None, always_apply: bool = False, p: float = 1.0)[source]
Bases:
DualTransformCrop the central region of the given size from the input.
Unlike
CenterCropfrom Albumentations, this transform pads the input in dimensions where the input is smaller than theshapewithnumpy.pad. Theborder_mode,ivalandmvalarguments are forwarded tonumpy.padif padding is necessary. More details at: https://numpy.org/doc/stable/reference/generated/numpy.pad.html.- Parameters:
shape (Tuple[int]) –
The desired output shape.
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 the image domain. Only applied when
border_mode = 'constant'orborder_mode = 'linear_ramp'.Defaults to
(0, 0).mval (float | Sequence, optional) –
Values of mask voxels outside the mask domain. Only applied when
border_mode = 'constant'orborder_mode = 'linear_ramp'.Defaults to
(0, 0).ignore_index (float | None, optional) –
If specified, then transformation of mask is done with
border_mode = 'constant'andmval = ignore_index.If
None, this argument is ignored.Defaults to
None.keep_all (bool, optional) –
When true, ALL keypoints and bounding boxes will be kept, even when they fully lie outside the image domain. Overrides min_volume and min_percentage.
Defaults to
False.min_volume (float, optional) –
Volume threshold below which bounding boxes will be removed. Is mutually exclusive with min_percentage.
Defaults to
None.min_percentage (float, optional) –
Percentage threshold below which bounding boxes will be removed. Value between 0.0 and 1.0. Is mutually exclusive with min_volume.
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
- class src.bio_volumentations.augmentations.transforms.Flip(axes: List[int] | None = None, always_apply: bool = False, p: float = 1)[source]
Bases:
DualTransformFlip input along the specified spatial axes.
- Parameters:
axes (List[int], optional) –
List of axes along which is flip done. Recognised axis symbols are
1for Z,2for Y, and3for X. IfNone, 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
- 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:
ImageOnlyTransformPerform Gaussian blurring of an image. In case of a multi-channel image, individual channels are blured separately.
Internally, the
scipy.ndimage.gaussian_filterfunction is used. Theborder_modeandcvalarguments 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
- 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:
ImageOnlyTransformAdd 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
- class src.bio_volumentations.augmentations.transforms.HistogramEqualization(bins: int = 256, always_apply: bool = False, p: float = 1)[source]
Bases:
ImageOnlyTransformEqualize 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
- class src.bio_volumentations.augmentations.transforms.Normalize(mean: float | List[float] | Tuple[float] = 0, std: float | List[float] | Tuple[float] = 1, always_apply: bool = False, p: float = 1.0)[source]
Bases:
ImageOnlyTransformChange 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
False.p (float, optional) –
Probability of applying this transformation in composition.
Defaults to
1.
- Targets:
image
- class src.bio_volumentations.augmentations.transforms.NormalizeMeanStd(mean: tuple | float, std: tuple | float, always_apply: bool = False, p: float = 1.0)[source]
Bases:
ImageOnlyTransformNormalize image values to mean 0 and standard deviation 1, given the channel 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
False.p (float, optional) –
Probability of applying this transformation in composition.
Defaults to
1.
- Targets:
image
- 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 = False, p: float = 1)[source]
Bases:
DualTransformPad the input.
Internally, the
numpy.padfunction is used. Theborder_mode,ivalandmvalarguments 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. Negative padding values are ignored.
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 the image domain. Only applied when
border_mode = 'constant'orborder_mode = 'linear_ramp'.Defaults to
0.mval (float | Sequence, optional) –
Values of mask voxels outside the mask domain. Only applied when
border_mode = 'constant'orborder_mode = 'linear_ramp'.Defaults to
0.ignore_index (float | None, optional) –
If specified, then transformation of mask is done with
border_mode = 'constant'andmval = 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
- class src.bio_volumentations.augmentations.transforms.PoissonNoise(always_apply: bool = False, p: float = 0.5)[source]
Bases:
ImageOnlyTransformAdd Poisson noise to the image.
- Parameters:
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
- 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', ival: float = 0, mval: float = 0, ignore_index: float | None = None, keep_all: bool = False, min_volume: float | None = None, min_percentage: float | None = None, always_apply: bool = False, p: float = 0.5)[source]
Bases:
DualTransformAffine 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). All values must be positive; values <=0 will be ignored and the respective axis will not be scaled.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), orNone.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
nearestinterpolation is always used.Defaults to
linear.ival (float, optional) –
Value of image voxels outside the image domain. Only applied when
border_mode = 'constant'.Defaults to
0.mval (float, optional) –
Value of mask and float_mask voxels outside 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'andmval = ignore_index.If
None, this argument is ignored.Defaults to
None.keep_all (bool, optional) –
When true, ALL keypoints and bounding boxes will be kept, even when they fully lie outside the image domain. Overrides min_volume and min_percentage.
Defaults to
False.min_volume (float, optional) –
Volume threshold below which bounding boxes will be removed. Is mutually exclusive with min_percentage.
Defaults to
None.min_percentage (float, optional) –
Percentage threshold below which bounding boxes will be removed. Value between 0.0 and 1.0. Is mutually exclusive with min_volume.
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
- 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:
ImageOnlyTransformRandomly change brightness and contrast of the input image.
Unlike
RandomBrightnessContrastfrom 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
- 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, keep_all: bool = False, min_volume: float | None = None, min_percentage: float | None = None, always_apply: bool = False, p: float = 1.0)[source]
Bases:
DualTransformRandomly crop a region of the given size from the input.
Unlike
RandomCropfrom Albumentations, this transform pads the input in dimensions where the input is smaller than theshapewithnumpy.pad. Theborder_mode,ivalandmvalarguments are forwarded tonumpy.padif padding is necessary. More details at: https://numpy.org/doc/stable/reference/generated/numpy.pad.html.- Parameters:
shape (Tuple[int]) –
The desired output shape.
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 the image domain. Only applied when
border_mode = 'constant'orborder_mode = 'linear_ramp'.Defaults to
(0, 0).mval (float | Sequence, optional) –
Values of mask voxels outside the mask domain. Only applied when
border_mode = 'constant'orborder_mode = 'linear_ramp'.Defaults to
(0, 0).ignore_index (float | None, optional) –
If specified, then transformation of mask is done with
border_mode = 'constant'andmval = ignore_index.If
None, this argument is ignored.Defaults to
None.keep_all (bool, optional) –
When true, ALL keypoints and bounding boxes will be kept, even when they fully lie outside the image domain. Overrides min_volume and min_percentage.
Defaults to
False.min_volume (float, optional) –
Volume threshold below which bounding boxes will be removed. Is mutually exclusive with min_percentage.
Defaults to
None.min_percentage (float, optional) –
Percentage threshold below which bounding boxes will be removed. Value between 0.0 and 1.0. Is mutually exclusive with min_volume.
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
- class src.bio_volumentations.augmentations.transforms.RandomFlip(axes_to_choose: None | List[int] | Tuple[int] = None, always_apply: bool = False, p: float = 0.5)[source]
Bases:
DualTransformFlip input along 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
1for Z,2for Y, and3for X. The image will be flipped along the chosen axes.If
None, a random subset of spatial axes is chosen, corresponding to inputting[1, 2, 3].If an empty list or an empty tuple, the transformation takes no effect.
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
- 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:
ImageOnlyTransformPerform 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
- 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:
ImageOnlyTransformPerform 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_sigmafor each channel and dimension.Internally, the
scipy.ndimage.gaussian_filterfunction is used. Theborder_modeandcvalarguments 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
- class src.bio_volumentations.augmentations.transforms.RandomRotate90(axes: List[int] | None = None, shuffle_axis: bool = False, factor: int | List[int] | None = None, always_apply: bool = False, p: float = 0.5)[source]
Bases:
DualTransformRotation of input by 0, 90, 180, or 270 degrees around the specified spatial axes.
Note
This transformation assumes the data is isotropic.
- Parameters:
axes (List[int], optional) –
List of axes around which the input is rotated. Recognised axis symbols are
1for Z,2for Y, and3for X. A single axis can occur multiple times in the list. Ifshuffle_axis = False, the order of axes determines the order of transformations. IfNone, 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. Only non-negative integer factors are supported. If
None, the factor will be chosen randomly from the interval [0, 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
- 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, ival: float = 0, mval: float = 0, ignore_index: float | None = None, keep_all: bool = False, min_volume: float | None = None, min_percentage: float | None = None, always_apply: bool = False, p: float = 0.5)[source]
Bases:
DualTransformRandomly 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). All values must be positive; values <=0 will be ignored and the respective axis will not be scaled.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
nearestinterpolation 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), orNone.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.ival (float, optional) –
Value of image voxels outside the image domain. Only applied when
border_mode = 'constant'.Defaults to
0.mval (float, optional) –
Value of mask and float_mask voxels outside 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'andmval = ignore_index.If
None, this argument is ignored.Defaults to
None.keep_all (bool, optional) –
When true, ALL keypoints and bounding boxes will be kept, even when they fully lie outside the image domain. Overrides min_volume and min_percentage.
Defaults to
False.min_volume (float, optional) –
Volume threshold below which bounding boxes will be removed. Is mutually exclusive with min_percentage.
Defaults to
Nonemin_percentage (float, optional) –
Percentage threshold below which bounding boxes will be removed. Value between 0.0 and 1.0. Is mutually exclusive with min_volume.
Defaults to
Nonealways_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
- 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 = False, p: float = 1.0)[source]
Bases:
ImageOnlyTransformRemove 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_filterfunction is used. Theborder_modeandcvalarguments 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
False.p (float, optional) –
Probability of applying this transformation in composition.
Defaults to
1.0.
- Targets:
image
- 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 = False, p: float = 1)[source]
Bases:
DualTransformRescale the input and change its shape accordingly.
Internally, the
skimage.transform.resizefunction is used. Theinterpolation,border_mode,ival,mval, andanti_aliasing_downsamplearguments 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]. All values must be positive; values <=0 will be ignored and the respective axis will not be scaled.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 the image domain. Only applied when
border_mode = 'constant'.Defaults to
0.mval (float, optional) –
Value of mask and float_mask voxels outside the domain. Only applied when
border_mode = 'constant'.Defaults to
0.anti_aliasing_downsample (bool, optional) –
Apply the Gaussian filter before down-sampling. Recommended.
Defaults to
True.ignore_index (float | None, optional) –
If specified, then transformation of mask is done with
border_mode = 'constant'andmval = 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
- 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:
DualTransformResize input to the given shape.
Internally, the
skimage.transform.resizefunction is used. Theinterpolation,border_mode,ival,mval, andanti_aliasing_downsamplearguments 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. If the shape is invalid (i.e., it contains negative numbers or zero), the transformation takes no effect.
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 the image domain. Only applied when
border_mode = 'constant'.Defaults to
0.mval (float, optional) –
Value of mask and float_mask voxels outside the domain. Only applied when
border_mode = 'constant'.Defaults to
0.anti_aliasing_downsample (bool, optional) –
Apply the Gaussian filter before down-sampling. Recommended.
Defaults to
True.ignore_index (float | None, optional) –
If specified, then transformation of mask is done with
border_mode = 'constant'andmval = 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
- 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, ival: float = 0, mval: float = 0, ignore_index: float | None = None, keep_all: bool = False, min_volume: float | None = None, min_percentage: float | None = None, always_apply: bool = False, p: float = 1)[source]
Bases:
DualTransformRescale 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]. All values must be positive; values <=0 will be ignored and the respective axis will not be scaled.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
nearestinterpolation 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), orNone.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.ival (float, optional) –
Value of image voxels outside the image domain. Only applied when
border_mode = 'constant'.Defaults to
0.mval (float, optional) –
Value of mask and float_mask voxels outside 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'andmval = ignore_index.If
None, this argument is ignored.Defaults to
None.keep_all (bool, optional) –
When true, ALL keypoints and bounding boxes will be kept, even when they fully lie outside the image domain. Overrides min_volume and min_percentage.
Defaults to
False.min_volume (float, optional) –
Volume threshold below which bounding boxes will be removed. Is mutually exclusive with min_percentage.
Defaults to
Nonemin_percentage (float, optional) –
Percentage threshold below which bounding boxes will be removed. Value between 0.0 and 1.0. Is mutually exclusive with min_volume.
Defaults to
Nonealways_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