Skip to content

Transforms

Source

Transforms that are used to augment the data.

Compose

A class chaining transforms together.

Parameters:

Name Type Description Default
transform_list list[TransformConfig]

A list of dictionaries where each dictionary contains the name of a transform and its parameters.

required

Attributes:

Name Type Description
_callable_transforms Callable

A callable that applies the transforms to the input data.

transform_with_additional_arrays(patch, target=None, **additional_arrays)

Apply the transforms to the input data, including additional arrays.

Parameters:

Name Type Description Default
patch ndarray

The input data.

required
target Optional[ndarray]

Target data, by default None.

None
**additional_arrays NDArray

Additional arrays that will be transformed identically to patch and target.

{}

Returns:

Type Description
NDArray

The transformed patch.

NDArray | None

The transformed target.

dict of {str, NDArray}

Transformed additional arrays. Keys correspond to the keyword argument names.

Denormalize

Denormalize an image.

Denormalization is performed expecting a zero mean and unit variance input. This transform expects C(Z)YX dimensions.

Note that an epsilon value of 1e-6 is added to the standard deviation to avoid division by zero during the normalization step, which is taken into account during denormalization.

Parameters:

Name Type Description Default
image_means list or tuple of float

Mean value per channel.

required
image_stds list or tuple of float

Standard deviation value per channel.

required

ImageRestorationTTA

Test-time augmentation for image restoration tasks.

The augmentation is performed using all 90 deg rotations and their flipped version, as well as the original image flipped.

Tensors should be of shape SC(Z)YX.

This transformation is used in the LightningModule in order to perform test-time augmentation.

backward(x)

Undo the test-time augmentation.

Parameters:

Name Type Description Default
x Any

List of augmented tensors of shape SC(Z)YX.

required

Returns:

Type Description
Any

Original tensor.

forward(input_tensor)

Apply test-time augmentation to the input tensor.

Parameters:

Name Type Description Default
input_tensor Tensor

Input tensor, shape SC(Z)YX.

required

Returns:

Type Description
list of torch.Tensor

List of augmented tensors.

N2VManipulate

Bases: Transform

Default augmentation for the N2V model.

This transform expects C(Z)YX dimensions.

Parameters:

Name Type Description Default
roi_size int

Size of the replacement area, by default 11.

11
masked_pixel_percentage float

Percentage of pixels to mask, by default 0.2.

0.2
strategy Literal['uniform', 'median']

Replaccement strategy, uniform or median, by default uniform.

value
remove_center bool

Whether to remove central pixel from patch, by default True.

True
struct_mask_axis Literal['horizontal', 'vertical', 'none']

StructN2V mask axis, by default "none".

'none'
struct_mask_span int

StructN2V mask span, by default 5.

5
seed Optional[int]

Random seed, by default None.

None

Attributes:

Name Type Description
masked_pixel_percentage float

Percentage of pixels to mask.

roi_size int

Size of the replacement area.

strategy Literal['uniform', 'median']

Replaccement strategy, uniform or median.

remove_center bool

Whether to remove central pixel from patch.

struct_mask Optional[StructMaskParameters]

StructN2V mask parameters.

rng Generator

Random number generator.

N2VManipulateTorch

Default augmentation for the N2V model.

This transform expects C(Z)YX dimensions.

Parameters:

Name Type Description Default
n2v_manipulate_config N2VManipulateConfig

N2V manipulation configuration.

required
device str

The device on which operations take place, e.g. "cuda", "cpu" or "mps".

None

Attributes:

Name Type Description
masked_pixel_percentage float

Percentage of pixels to mask.

roi_size int

Size of the replacement area.

strategy Literal[uniform, median]

Replacement strategy, uniform or median.

remove_center bool

Whether to remove central pixel from patch.

struct_mask Optional[StructMaskParameters]

StructN2V mask parameters.

rng Generator

Random number generator.

Normalize

Bases: Transform

Normalize an image or image patch.

Normalization is a zero mean and unit variance. This transform expects C(Z)YX dimensions.

Not that an epsilon value of 1e-6 is added to the standard deviation to avoid division by zero and that it returns a float32 image.

Parameters:

Name Type Description Default
image_means list of float

Mean value per channel.

required
image_stds list of float

Standard deviation value per channel.

required
target_means list of float

Target mean value per channel, by default None.

None
target_stds list of float

Target standard deviation value per channel, by default None.

None

Attributes:

Name Type Description
image_means list of float

Mean value per channel.

image_stds list of float

Standard deviation value per channel.

target_means list of float, optional

Target mean value per channel, by default None.

target_stds list of float, optional

Target standard deviation value per channel, by default None.

TrainDenormalize

Denormalize an image tensor for training-time tensors.

This class mirrors Denormalize but operates on torch tensors. It expects the input tensor to have shape BC(Z)YX with the channel dimension at index 1.

Parameters:

Name Type Description Default
image_means list or tuple of float

Mean value per channel.

required
image_stds list or tuple of float

Standard deviation value per channel.

required

XYFlip

Bases: Transform

Flip image along X and Y axis, one at a time.

This transform randomly flips one of the last two axes.

This transform expects C(Z)YX dimensions.

Attributes:

Name Type Description
axis_indices List[int]

Indices of the axes that can be flipped.

rng Generator

Random number generator.

p float

Probability of applying the transform.

seed Optional[int]

Random seed.

Parameters:

Name Type Description Default
flip_x bool

Whether to flip along the X axis, by default True.

True
flip_y bool

Whether to flip along the Y axis, by default True.

True
p float

Probability of applying the transform, by default 0.5.

0.5
seed Optional[int]

Random seed, by default None.

None

XYRandomRotate90

Bases: Transform

Applies random 90 degree rotations to the YX axis.

This transform expects C(Z)YX dimensions.

Attributes:

Name Type Description
rng Generator

Random number generator.

p float

Probability of applying the transform.

seed Optional[int]

Random seed.

Parameters:

Name Type Description Default
p float

Probability of applying the transform, by default 0.5.

0.5
seed Optional[int]

Random seed, by default None.

None

get_all_transforms()

Return all the transforms accepted by CAREamics.

Returns:

Type Description
dict

A dictionary with all the transforms accepted by CAREamics, where the keys are the transform names and the values are the transform classes.