Menu

Deep learning for NeuroImaging in Python.

Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the gallery for the big picture.

class nidl.transforms.Transform(p: float | None = None)[source]

Bases: ABC

Abstract class for all nidl transformations.

The general logic for any transformation when called is:

  1. calling to parse_data() for parsing the input data, a numpy.ndarray or torch.Tensor, and validate its dimension. The output should be formatted with verified shape and type.

  2. (optional) calling to random.random() to know whether the transformation is applied or not (depending on a probability p).

  3. calling to apply_transform() for applying the transformation on the formatted data. This abstract method should be implemented in every subclass to specify the actual transformation.

Transformations in nidl are compliant with torchvision.transforms module and it can be used in conjonction.

Spatial augmentation currently implemented (change geometry):
  • RandomErasing (3d)

  • RandomResizedCrop (3d)

  • RandomFlip (3d-array)

  • RandomRotation (3d)

Intensity augmentations currently implemented (change voxel values):
  • RandomGaussianBlur (3d)

  • RandomGaussianNoise (nd)

  • Gamma (TODO)

  • RandomBrightness (TODO)

  • Biasfield (TODO)

Intensity preprocessing:
  • ZNormalization (3d)

  • RobustRescaling (3d)

Spatial preprocessing:
  • Resample (3d)

  • Resize (3d)

  • CropOrPad (3d)

Parameters:

p : float or None, default=None

Probability to apply the transformation. If float, it should be between 0 and 1 (included). If None (default), the transformation is always applied.

abstract apply_transform(data_parsed: Any, *args, **kwargs) Any[source]

Apply the transformation on the data parsed by parse_data(). This should be implemented in all subclasses.

Parameters:

data_parsed : Any

Input data with type and shape already checked.

*args : Any

Additional positional arguments.

**kwargs : dict

Additional keyword arguments.

Returns:

data : Any

The transformed data.

parse_data(data: ndarray | Tensor) Any[source]

Parse the input data and returns formatted data.

Input data must be a numpy.ndarray or torch.Tensor.

Parameters:

data : TypeTransformInput

Input data to be transformed.

Returns:

data : Any

The formatted data.

Raises:

ValueError

If the input data is not numpy.ndarray or torch.Tensor

static parse_probability(probability: float | None) float[source]

Check if the probability is correct.

In details, it checks whether it is a scalar (int or float) between 0 and 1 (included).

Parameters:

probability : float or None

Probability to check. None value is accepted.

Raises:

ValueError

If probability value is not supported.

Follow us

© 2025, nidl developers