Bio-Volumentations Package
Transforms Module
- class 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: int = 1, 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.
- Parameters:
angles (Tuple[float], optional) –
Angles of rotation 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 (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
'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 voxels outside of the mask domain. Only applied when
border_mode = 'constant'
.Defaults to
0
.ignore_index (float | None, optional) –
If a float, 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) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image, mask, float_mask
- class bio_volumentations.augmentations.transforms.CenterCrop(shape: Tuple[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
Crops the central region of the input of given size.
Unlike
CenterCrop
from Albumentations, this transform pads the input in dimensions where the input is smaller than theshape
withnumpy.pad
. Theborder_mode
,ival
andmval
arguments are forwarded tonumpy.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 either of:
[Z, Y, X]
or[Z, Y, X, T]
.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'
orborder_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'
orborder_mode = 'linear_ramp'
.Defaults to
(0, 0)
.ignore_index (float | None, optional) –
If a float, 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) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image, mask, float_mask
- class 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) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image, mask, float_mask
- class 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, and3
for X.Defaults to
[1,2,3]
.always_apply (bool, optional) –
Always apply this transformation in composition.
Defaults to
False
.p (float, optional) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image, mask, float_mask
- class bio_volumentations.augmentations.transforms.Float(always_apply: bool = True, p: float = 1.0)[source]
Bases:
DualTransform
Change datatype to
np.float32
without changing intensities.- Parameters:
always_apply (bool, optional) –
Always apply this transformation in composition.
Defaults to
True
.p (float, optional) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image, mask, float_mask
- class bio_volumentations.augmentations.transforms.GaussianBlur(sigma: float | Tuple[float] | List[Tuple[float] | float] = 0.8, border_mode: str = 'reflect', cval: float = 0, always_apply: bool = False, p: float = 0.5)[source]
Bases:
ImageOnlyTransform
Performs Gaussian blurring of the image. In case of a multi-channel image, individual channels are blured separately.
Internally, the
scipy.ndimage.gaussian_filter
function is used. Theborder_mode
andcval
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) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image
- class bio_volumentations.augmentations.transforms.GaussianNoise(var_limit: tuple = (0.001, 0.1), mean: float = 0, always_apply: bool = False, p: float = 0.5)[source]
Bases:
ImageOnlyTransform
Adds 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) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image
- class bio_volumentations.augmentations.transforms.HistogramEqualization(bins: int = 256, always_apply: bool = False, p: float = 1)[source]
Bases:
ImageOnlyTransform
Performs equalization of histogram. The equalization is done channel-wise, meaning that each channel is equalized separately.
Warning! Images are normalized over both spatial and temporal domains together. The output is in the 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) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image
- class 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
,[M_1, M_2, ..., M_C]
.Defaults to
0
.std (float | List[float], optional) –
The desired channel-wise standard deviations.
Must be either of:
S
,[S_1, S_2, ..., S_C]
.Defaults to
1
.always_apply (bool, optional) –
Always apply this transformation in composition.
Defaults to
True
.p (float, optional) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image
- class bio_volumentations.augmentations.transforms.NormalizeMeanStd(mean: List[float] | float, std: List[float] | float, always_apply: bool = True, p: float = 1.0)[source]
Bases:
ImageOnlyTransform
Normalize image values to have mean 0 and standard deviation 1, given 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 previous 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
,(M_1, M_2, ..., M_C)
.std (float | List[float]) –
Channel-wise image standard deviation.
Must be either of:
S
,(S_1, S_2, ..., S_C)
.always_apply (bool, optional) –
Always apply this transformation in composition.
Defaults to
True
.p (float, optional) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image
- class bio_volumentations.augmentations.transforms.Pad(pad_size: int | Tuple[int] | List[int | Tuple[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
Pads the input.
- Parameters:
pad_size (int | Tuple[int] | List[int | Tuple[int]]) –
Number of pixels padded to the edges of each axis.
Must be either of:
P
,(P1, P2)
,[P_Z, P_Y, P_X]
,[P_Z, P_Y, P_X, P_T]
,[(P_Z1, P_Z2), (P_Y1, P_Y2), (P_X1, P_X2)]
, or[(P_Z1, P_Z2), (P_Y1, P_Y2), (P_X1, P_X2), (P_T1, P_T2)]
.If an integer, it is equivalent to
[(P, P), (P, P), (P, P)]
.If a tuple, it is equivalent to
[(P1, P2), (P1, P2), (P1, P2)]
.If a list, it must specify padding for all spatial dimensions and possibly also for the time dimension.
The unspecified dimensions (C and possibly 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'
orborder_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'
orborder_mode = 'linear_ramp'
.Defaults to
0
.ignore_index (float | None, optional) –
If a float, 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
True
.p (float, optional) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image, mask, float_mask
- class bio_volumentations.augmentations.transforms.PoissonNoise(intensity_limit=(1, 10), always_apply: bool = False, p: float = 0.5)[source]
Bases:
ImageOnlyTransform
Adds Poisson noise to the image.
- Parameters:
intensity_limit (tuple) –
Range to sample the expected intensity of Poisson noise.
Defaults to
(1, 10)
.always_apply (bool, optional) –
Always apply this transformation in composition.
Defaults to
False
.p (float, optional) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image
- class bio_volumentations.augmentations.transforms.RandomAffineTransform(angle_limit: float | Tuple[float, float] | Tuple[float, float, float, float, float, float] = (15, 15, 15), translation_limit: float | Tuple[float, float] | Tuple[float, float, float, float, float, float] = (0, 0, 0), scaling_limit: float | Tuple[float, float] | Tuple[float, float, float, float, float, float] = (0.2, 0.2, 0.2), spacing: float | Tuple[float, float, float] | None = None, change_to_isotropic: bool = False, interpolation: int = 1, 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.
- 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)
, 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 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[int] | int | None, optional) –
Intervals from which the translation parameters for the spatial axes are chosen.
Must be either of:
T
,(T1, T2)
, or(T_Z1, T_Z2, T_Y1, T_Y2, T_X1, T_X2)
.If a float, equivalent to
(-T, T, -T, T, -T, T)
.If a tuple with 2 items, equivalent to
(T1, T2, T1, T2, T1, T2)
.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)
, or(S_Z1, S_Z2, S_Y1, S_Y2, S_X1, S_X2)
.If a float, equivalent to
(1-S, 1+S, 1-S, 1+S, 1-S, 1+S)
.If a tuple with 2 items, equivalent to
(S1, S2, S1, S2, S1, S2)
.If a tuple with 6 items, the scale is randomly chosen from an interval [S_a1, S_a2] for each spatial axis.
Defaults to
(0.2, 0.2, 0.2)
.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 (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
'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 voxels outside of the mask domain. Only applied when
border_mode = 'constant'
.Defaults to
0
.ignore_index (float | None, optional) –
If a float, 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) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image, mask, float_mask
- class bio_volumentations.augmentations.transforms.RandomBrightnessContrast(brightness_limit=0.2, contrast_limit=0.2, always_apply=False, p=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) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image
- class bio_volumentations.augmentations.transforms.RandomCrop(shape: tuple, 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 crops a region of given size from the input.
Unlike
RandomCrop
from Albumentations, this transform pads the input in dimensions where the input is smaller than theshape
withnumpy.pad
. Theborder_mode
,ival
andmval
arguments are forwarded tonumpy.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 either of:
[Z, Y, X]
or[Z, Y, X, T]
.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'
orborder_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'
orborder_mode = 'linear_ramp'
.Defaults to
(0, 0)
.ignore_index (float | None, optional) –
If a float, 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) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image, mask, float_mask
- class bio_volumentations.augmentations.transforms.RandomFlip(axes_to_choose: None | List[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[Tuple[int]] or None, optional) –
List of axis combinations from which one option is randomly chosen. Recognised axis symbols are
1
for Z,2
for Y, and3
for X. The image will be flipped around all axes in the chosen combination.If
None
, a random subset of spatial axes is chosen, corresponding to inputting[(1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
.Defaults to
None
.always_apply (bool, optional) –
Always apply this transformation in composition.
Defaults to
False
.p (float, optional) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image, mask, float_mask
- class bio_volumentations.augmentations.transforms.RandomGamma(gamma_limit: Tuple[float] = (0.8, 1.2), always_apply: bool = False, p: float = 0.5)[source]
Bases:
ImageOnlyTransform
Performs the gamma transformation with a randomly chosen gamma. 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) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image
- class bio_volumentations.augmentations.transforms.RandomGaussianBlur(max_sigma: float | Tuple[float, float, 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
Performs Gaussian blur on the image with a random strength blurring. 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. Theborder_mode
andcval
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) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image
- class bio_volumentations.augmentations.transforms.RandomRotate90(axes: List[int] | None = None, shuffle_axis: bool = False, 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, and3
for X. A single axis can occur multiple times in the list. Ifshuffle_axis = False
, the order of axes determines the order of transformations.Defaults to
[1, 2, 3]
.shuffle_axis (bool, optional) –
If set to
True
, the order of rotations is random.Defaults to
False
.always_apply (bool, optional) –
Always apply this transformation in composition.
Defaults to
False
.p (float, optional) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image, mask, float_mask
- class 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: int = 1, 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 input.
- Parameters:
scaling_limit (float | Tuple[float] | List[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, 1+S] (equivalent to inputting(1-S, 1+S, 1-S, 1+S, 1-S, 1+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, 1+S_a] is constructed for each spatial dimension and the scale is randomly drawn from it (equivalent to inputting
(1-S_Z, 1+S_Z, 1-S_Y, 1+S_Y, 1-S_X, 1+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
(0.9, 1.1)
.interpolation (int, optional) –
Order of spline interpolation.
Defaults to
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
.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 voxels outside of the mask domain. Only applied when
border_mode = 'constant'
.Defaults to
0
.ignore_index (float | None, optional) –
If a float, 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) –
Chance of applying this transformation in composition.
Defaults to
0.5
.
- Targets:
image, mask, float_mask
- class bio_volumentations.augmentations.transforms.Resize(shape: tuple, 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. Theinterpolation
,border_mode
,ival
,mval
, andanti_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 of either of:
(Z, Y, X)
or(Z, Y, X, T)
.The unspecified dimensions (C and possibly 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 voxels outside of the mask domain. Only applied when
border_mode = 'constant'
.Defaults to
0
.anti_aliasing_downsample (bool, optional) –
Controls if the Gaussian filter should be applied before downsampling. Recommended.
Defaults to
True
.ignore_index (float | None, optional) –
If a float, 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) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image, mask, float_mask
- class bio_volumentations.augmentations.transforms.Scale(scales: float | Tuple[float, float, float] = 1, interpolation: int = 1, 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 input by the given scale.
- 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]
, or[S_Z, S_Y, S_X, S_T]
.If a float, then all spatial dimensions are scaled by it (equivalent to
[S, S, S]
).The unspecified dimensions (C and possibly T) are not affected.
Defaults to
1
.interpolation (int, optional) –
Order of spline interpolation.
Defaults to
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
.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 voxels outside of the mask domain. Only applied when
border_mode = 'constant'
.Defaults to
0
.ignore_index (float | None, optional) –
If a float, 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) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image, mask, float_mask
Conversion Module
- class bio_volumentations.conversion.transforms.ConversionToFormat(always_apply: bool = True, p: float = 1)[source]
Bases:
DualTransform
Check the very basic assumptions about the input images.
Adds channel dimension to the 3D images without it. Checks that shapes of individual target types are consistent (to some extent).
- Parameters:
always_apply (bool, optional) –
Always apply this transformation in composition.
Defaults to
True
.p (float, optional) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image, mask
- class bio_volumentations.conversion.transforms.NoConversion(always_apply: bool = True, p: float = 1)[source]
Bases:
DualTransform
An identity transform.
- Parameters:
always_apply (bool, optional) –
Always apply this transformation in composition.
Defaults to
True
.p (float, optional) –
Chance of applying this transformation in composition.
Defaults to
1
.
- Targets:
image, mask
Composition Module
- class bio_volumentations.core.composition.Compose(transforms, p=1.0, targets=(['image'], ['mask'], ['float_mask']), conversion=None)[source]
Bases:
object
Compose a list of transformations into a callable transformation pipeline.
It is strongly recommended to use
Compose
to define and use the transformation pipeline.In addition, basic input image checks and conversions are performed. Optionally, datatype conversion (e.g. from
numpy.ndarray
totorch.Tensor
) is performed.- Parameters:
transforms (List[Transform]) – List of transforms (objects of type
Transform
).p (float, optional) –
Chance of applying the whole pipeline.
Defaults to
1
.targets (Tuple[List[str]] | List[List[str]], optional) –
List of targets.
Defaults to
(['image'], ['mask'], ['float_mask'])
.conversion (Transform | None, optional) –
Image datatype conversion transform, applied after the transformations.
Defaults to
None
.
Transforms Interface Module
- class bio_volumentations.core.transforms_interface.DualTransform(always_apply=False, p=0.5)[source]
Bases:
Transform
The base class of transformations applied to all target types.
- Targets:
image, mask
- class bio_volumentations.core.transforms_interface.ImageOnlyTransform(always_apply=False, p=0.5)[source]
Bases:
Transform
The base class of transformations applied to the image target only.
- Targets:
image
- property targets
- class bio_volumentations.core.transforms_interface.Transform(always_apply=False, p=0.5)[source]
Bases:
object
The base class for transformations.
- Parameters:
always_apply (bool, optional) –
Always apply this transformation.
Defaults to
False
.p (float, optional) –
Chance of applying this transformation.
Defaults to
0.5
.