Note

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

nidl.transforms.volume.preprocessing.CropForeground

class nidl.transforms.volume.preprocessing.CropForeground(threshold=0.0, **kwargs)[source]

Bases: VolumeTransform

Crop a 3d volume to the bounding box of its foreground (voxels above threshold in any channel).

Reimplementation of MONAI’s CropForeground [1] (Apache-2.0).

Parameters:
threshold: float, default=0.0

Voxels strictly above this value are foreground.

kwargs: dict

Keyword arguments.

References

[1]

Cardoso, M. J., et al., “MONAI: An open-source framework for deep learning in healthcare.” arXiv, 2022. https://arxiv.org/abs/2211.02701

__init__(threshold=0.0, **kwargs)[source]
apply_transform(data)[source]

Crop to the foreground (unchanged if there is none).

Parameters:
data: np.ndarray or torch.Tensor

The input volume.

Returns:
data: np.ndarray or torch.Tensor

Cropped volume (a copy), same type as the input.