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 (float | Tuple[float, float, float] | None, optional) – voxel spacing for individual spatial dimensions. Must be: (S1, S2, S3). Defaults to (1, 1, 1).
change_to_isotropic (bool, optional) – Change data from anisotropic to isotropic. Defaults to False.
interpolation (Int, optional) – The order of spline interpolation. Defaults to 1.
border_mode (str, optional) – The mode parameter determines how the input array is extended beyond its boundaries. Defaults to ‘constant’.
ival (float, optional) – Value to fill past edges of image if mode is ‘constant’. Defaults to 0.
mval (float, optional) – Value to fill past edges of mask if mode is ‘constant’. Defaults to 0.
ignore_index (float | None, optional) – If ignore_index is float, then transformation of mask is done with border_mode = “constant” and mval = ignore_index. If ignore_index is None, then it does nothing. Defaults to None.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 0.5.
- Targets:
image, mask
- Image types:
float32
- 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 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 either of: [Z, Y, X] or [Z, Y, X, T].
border_mode (str, optional) – border mode used for numpy.pad. Defaults to “reflect”.
ival (Tuple[float], optional) – values used for ‘constant’ or ‘linear_ramp’ for image. Defaults to (0, 0).
mval (Tuple[float], optional) – values used for ‘constant’ or ‘linear_ramp’ for mask. Defaults to (0, 0).
ignore_index (float | None, optional) – if ignore_index is a float, then transformation of mask is done with border_mode = “constant” and mval = ignore_index. If ignore_index is None, then it does nothing. Defaults to None.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 1.
- Targets:
image, mask
- Image types:
float32
- class bio_volumentations.augmentations.transforms.Contiguous(always_apply=False, p=0.5)[source]
Bases:
DualTransform
Transform the image data to a contiguous array.
- 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, and 3 for X). Defaults to [1,2,3].
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 1.
- Targets:
image, mask
- Image types:
float32
- class bio_volumentations.augmentations.transforms.Float(always_apply=False, p=0.5)[source]
Bases:
DualTransform
Change datatype to np.float32 without changing the image values.
- 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 blur on the image. In case of a multi-channel image, individual channels are blured separately.
- Internally, the scipy 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 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.
border_mode (str, optional) – The mode parameter determines how the input array is extended beyond its boundaries. Defaults to “reflect”.
cval (float, optional) – Value to fill past edges of image if mode is ‘constant’. Defaults to 0.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 0.5.
- Targets:
image
- Image types:
float32
- 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 transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 0.5.
- Targets:
image
- Image types:
float32
- 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 transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 1.
- Targets:
image
- Image types:
float32
- 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 transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 1.
- Targets:
image
- Image types:
float32
- 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 transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 1.
- Targets:
image
- Image types:
float32
- 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 = False, p: float = 1)[source]
Bases:
DualTransform
Pads the input based on pad_size.
If pad_size is a single number, all spatial axes are padded on both sides with this number. If it is tuple, then it has same behaviour as pad_size except sides are padded with different number of pixels. If it is List, then it must have 3 items, which define padding for each spatial dimension separately (in either of the ways described above). If the List is shorter, remaining axes are padded with 0.
For other parameters check https://numpy.org/doc/stable/reference/generated/numpy.pad.html
- 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) – numpy.pad parameter . Defaults to ‘constant’.
ival (float | Sequence, optional) – value for image if needed by chosen border_mode. Defaults to 0.
mval (float | Sequence, optional) – value for mask if needed by chosen border_mode. Defaults to 0.
ignore_index (float | None, optional) – If ignore_index is float, then transformation of mask is done with border_mode = “constant” and mval = ignore_index. If ignore_index is None, then it does nothing. Defaults to None.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 0.5.
- Targets:
image, mask
- Image types:
float32
- 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 expected intensity of added poisson noise. Defaults to (1, 10).
- 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), or None. If None, equivalent to (1, 1, 1). If a float S, equivalent to (S, S, S). If a tuple with 3 items, the scale is (S1, S2, S3). Defaults to None.
change_to_isotropic (bool, optional) – Change data from anisotropic to isotropic. Defaults to False.
interpolation (Int, optional) – The order of spline interpolation. Defaults to 1.
border_mode (str, optional) – The mode parameter determines how the input array is extended beyond its boundaries. Defaults to ‘constant’.
ival (float, optional) – Value to fill past edges of image if mode is ‘constant’. Defaults to 0.
mval (float, optional) – Value to fill past edges of mask if mode is ‘constant’. Defaults to 0.
ignore_index (float | None, optional) – If ignore_index is float, then transformation of mask is done with border_mode = “constant” and mval = ignore_index. If ignore_index is None, then it does nothing. Defaults to None.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 0.5.
- Targets:
image, mask
- Image types:
float32
- 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. Must be either of: B, (B1, B2). If a float, the interval will be (-B, B). If the change in brightness is 0, the brightness will not change. Defaults to 0.2.
contrast_limit ((float, float) | float, optional) – interval from which the change in contrast is randomly drawn. Must be either of: C, (C1, C2). If a float, the interval will be (-C, C). If the change in contrast is 1, the contrast will not change. Defaults to 0.2.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 0.5.
- Targets:
image
- Image types:
float32
- 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 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 either of: [Z, Y, X] or [Z, Y, X, T].
border_mode (str, optional) – border mode used for numpy.pad. Defaults to “reflect”.
ival (Tuple[float], optional) – values used for ‘constant’ or ‘linear_ramp’ for image. Defaults to (0, 0).
mval (Tuple[float], optional) – values used for ‘constant’ or ‘linear_ramp’ for mask. Defaults to (0, 0).
ignore_index (float | None, optional) – if ignore_index is a float, then transformation of mask is done with border_mode = “constant” and mval = ignore_index. If ignore_index is None, then it does nothing. Defaults to None.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 1.
- Targets:
image, mask
- Image types:
float32
- 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) – a list of axis combinations from which one option is randomly chosen (recognised axis symbols are 1 for Z, 2 for Y, and 3 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 transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 0.5.
- Targets:
image, mask
- Image types:
float32
- 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 transform with a randomly chosen gamma. If image values (in any channel) are outside the [0,1] interval, this transformation is skipped.
- Parameters:
gamma_limit (Tuple(float), optional) – interval from which gamma is selected. Defaults to (0.8, 1.2).
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 0.5.
- Targets:
image
- Image types:
float32
- 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 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. It is the same for all channels and dimensions. Defaults to 0.
border_mode (str, optional) – The mode parameter determines how the input array is extended beyond its boundaries. Defaults to “reflect”.
cval (float, optional) – Value to fill past edges of image if mode is ‘constant’. Defaults to 0.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 0.5.
- Targets:
image
- Image types:
float32
- 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, and 3 for X). A single axis can occur multiple times in the list. If shuffle_axis is False, the order of axes determines the order of transformations. Defaults to [1, 2, 3].
shuffle_axis (bool, optional) – If set to True, order of rotations is random. Defaults to False.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 0.5.
- Targets:
image, mask
- Image types:
float32
- 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 it is 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 it is a tuple of 2 numbers, 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 it is a tuple of 3 numbers, 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 it is a tuple of 6 numbers, 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 for the image.
Defaults to
1
.spacing (TripleFloats | float | None) –
TBA
Defaults to
None
.border_mode (str, optional) –
Values outside image domain are filled according to the mode.
Defaults to
'constant'
.ival (float, optional) –
Value outside of image when the border_mode is chosen to be
'constant'
.Defaults to
0
.mval (float, optional) –
Value outside of mask when the border_mode is chosen to be “constant”.
Defaults to
0
.ignore_index (float | None, optional) –
If
ignore_index
is float, then transformation of mask is done withborder_mode = 'constant'
andmval = ignore_index
. Ifignore_index
isNone
, then it does nothing.Defaults to
None
.always_apply (bool, optional) –
Always apply transformation in composition.
Defaults to
False
.p (float, optional) –
Chance of applying transformation in composition.
Defaults to
0.5
.
- Targets:
image, mask
- Image types:
float32
- 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 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 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 for image. Defaults to 1.
border_mode (string, optional) – points outside image are filled according to this mode. Defaults to ‘reflect’.
ival (float, optional) – value outside of image when the border_mode is chosen to be “constant”. Defaults to 0.
mval (float, optional) – value outside of mask when the border_mode is chosen to be “constant”. Defaults to 0.
anti_aliasing_downsample (bool, optional) – controls if the gaussian filter should be used on image before downsampling, recommended. Defaults to True.
ignore_index (float | None, optional) – If ignore_index is float, then transformation of mask is done with border_mode = “constant” and mval = ignore_index. If ignore_index is None, then it does nothing. Defaults to None.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 1.
- Targets:
image, mask
- Image types:
float32
- 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 it is a float, then all spatial dimensions are scaled by it (S is 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 for image. Defaults to 1.
border_mode (str, optional) – points outside image are filled according to this mode. Defaults to ‘constant’.
ival (float, optional) – value outside of image when the border_mode is chosen to be “constant”. Defaults to 0.
mval (float, optional) – value outside of mask when the border_mode is chosen to be “constant”. Defaults to 0.
ignore_index (float | None, optional) – If ignore_index is float, then transformation of mask is done with border_mode = “constant” and mval = ignore_index. If ignore_index is None, then it does nothing. Defaults to None.
always_apply (bool, optional) – always apply transformation in composition. Defaults to False.
p (float, optional) – chance of applying transformation in composition. Defaults to 1.
- Targets:
image, mask
- Image types:
float32
Conversion Module
- class bio_volumentations.conversion.transforms.ConversionToFormat(always_apply: bool = False, 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).
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 transforms into a callable 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]) – a list of transforms.
p (float, optional) – chance of applying the whole pipeline. Defaults to 1.
targets (Tuple[List[str]] | List[List[str]], optional) – a 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 transforms applied to all target types.