Skip to content

Clamp

Clamp

Bases: IntensityTransform

Clamp intensity values into a range \([a, b]\).

For more information, see torch.clamp().

Parameters:

Name Type Description Default
out_min float | None

Minimum value \(a\) of the output image. If None, the minimum of the image is used.

None
out_max float | None

Maximum value \(b\) of the output image. If None, the maximum of the image is used.

None

Examples:

>>> import torchio as tio
>>> ct = tio.datasets.Slicer('CTChest').CT_chest
>>> HOUNSFIELD_AIR, HOUNSFIELD_BONE = -1000, 1000
>>> clamp = tio.Clamp(out_min=HOUNSFIELD_AIR, out_max=HOUNSFIELD_BONE)
>>> ct_clamped = clamp(ct)

__call__(data)

__call__(data: Subject) -> Subject
__call__(data: ImageT) -> ImageT
__call__(data: torch.Tensor) -> torch.Tensor
__call__(data: np.ndarray) -> np.ndarray
__call__(data: sitk.Image) -> sitk.Image
__call__(data: dict[str, object]) -> dict[str, object]
__call__(data: nib.Nifti1Image) -> nib.Nifti1Image

Transform data and return a result of the same type.

Parameters:

Name Type Description Default
data TypeTransformInput

Instance of torchio.Subject, 4D torch.Tensor or numpy.ndarray with dimensions \((C, W, H, D)\), where \(C\) is the number of channels and \(W, H, D\) are the spatial dimensions. If the input is a tensor, the affine matrix will be set to identity. Other valid input types are a SimpleITK image, a torchio.Image, a NiBabel Nifti1 image or a dict. The output type is the same as the input type.

required

to_hydra_config()

Return a dictionary representation of the transform for Hydra instantiation.

arguments_are_dict()

Check if main arguments are dict.

Return True if the type of all attributes specified in the args_names have dict type.

plot

Source code
import torchio as tio
subject = tio.datasets.Slicer('CTChest')
ct = subject.CT_chest
HOUNSFIELD_AIR, HOUNSFIELD_BONE = -1000, 1000
clamp = tio.Clamp(out_min=HOUNSFIELD_AIR, out_max=HOUNSFIELD_BONE)
ct_clamped = clamp(ct)
subject.add_image(ct_clamped, 'Clamped')
subject.plot()