clinicadl.transforms.TransformsHandler¶
- class clinicadl.transforms.TransformsHandler(extraction: Extraction | None = None, image_transforms: Sequence[Callable[[DataPointT], DataPointT] | TransformConfig] = (), sample_transforms: Sequence[Callable[[DataPointT], DataPointT] | TransformConfig] = (), augmentations: Sequence[Callable[[DataPointT], DataPointT] | TransformConfig] = ())[source]¶
Handles the transformation pipeline applied to images.
ClinicaDLdefines 4 types of transforms:extraction: defines on what type of elements of the image one wants to work (the whole image, patches or slices).image_transforms: transforms applied on the whole image, before the potential extraction is applied. This is typically where you want to do normalization (to normalize on the whole image and not only on a patch or a slice).sample_transforms: transforms applied on a sample (a patch or a slice), after extraction. This is typically where you want to resize your sample so that it fits in your network.augmentations: transforms applied afterimage_transforms,extractionandsample_transforms, only during training.
For
image_transforms,sample_transformsandaugmentations, the transforms must be passed as sequences.TransformsHandlerwill compose the transforms in these sequences. So, the order in the sequences is important.- Parameters:
extraction (Optional[Extraction], default=None) – The extraction applied. See
clinicadl.transforms.extraction. IfNone,Imageis used (which is equivalent to no extraction).image_transforms (Sequence[TransformOrConfig], default=()) – A sequence of transforms to apply on the whole image, before extraction. Passed as callables that take as input and return a
DataPoint, orconfiguration class.sample_transforms (Sequence[TransformOrConfig], default=()) – A sequence of transforms to apply on samples (patches or slices). Passed as callables that take as input and return a
DataPoint, orconfiguration class.augmentations (Sequence[TransformOrConfig], default=()) – A sequence of augmentation transforms, to apply on samples, only during training. Passed as callables that take as input and return a
DataPoint, orconfiguration class.
Examples
>>> from clinicadl.transforms import TransformsHandler >>> from clinicadl.transforms.extraction import Patch >>> from clinicadl.transforms.config import ZNormalizationConfig, RandomFlipConfig >>> import torchio >>> transforms = TransformsHandler( extraction=Patch(patch_size=32, stride=32), image_transforms=[ZNormalizationConfig(), torchio.CropOrPad(64)], sample_transforms=[], augmentations=[RandomFlipConfig(flip_probability=0.3)], )
- apply_image_transforms(datapoint: DataPointT) DataPointT[source]¶
Applies the transforms passed in
image_transformsand returns the output.- Parameters:
datapoint (DataPoint) – The input
DataPoint.- Returns:
DataPoint – The transformed
DataPoint.
- extract_sample(datapoint: DataPointT, sample_index: int) DataPointT[source]¶
Extracts the sample.
See:
clinicadl.transforms.extraction.Extraction.