HistogramStandardization
Bases: IntensityTransform
Apply piecewise-linear histogram standardization.
Implementation of Nyúl and Udupa (1999).
Landmarks must be precomputed using
[compute_histogram_landmarks][torchio.transforms.histogram_standardization.compute_histogram_landmarks]
and are passed directly to this transform. Each instance targets
one modality; for multi-modal subjects, compose multiple
instances with the include parameter:
tio.Compose([
tio.HistogramStandardization(t1_landmarks, include=["t1"]),
tio.HistogramStandardization(t2_landmarks, include=["t2"]),
])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
Tensor | Path | str
|
1-D tensor (or path to a |
required |
cutoff
|
tuple[float, float]
|
Lower and upper quantile bounds. |
DEFAULT_CUTOFF
|
**kwargs
|
Any
|
See |
{}
|
Examples:
>>> import torchio as tio
>>> landmarks = torch.linspace(0, 100, 13)
>>> transform = tio.HistogramStandardization(landmarks)
Source code in src/torchio/transforms/intensity/histogram_standardization.py
supports_per_instance_params
property
Whether this transform can sample parameters per batch element.
Defaults to False. Transforms that implement per-instance
parameter sampling override this to return True. When False,
the transform always uses batch-shared parameters regardless of
the per_instance flag, preserving the legacy behavior.
supports_per_instance_p
property
Whether this transform can gate each batch element independently.
Defaults to False. Shape-preserving transforms that implement
per-element probability override this to return True.
Shape-changing transforms must leave it False because masked
and unmasked elements would have incompatible shapes.
invertible
property
Whether this transform can be inverted.
forward(data)
Apply the transform.
The output type always matches the input type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Input data to transform. |
required |
Source code in src/torchio/transforms/transform.py
inverse(params)
Return a transform that undoes this one.
Override in invertible subclasses. The returned transform, when applied, reverses the effect of the forward pass with the given parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict[str, Any]
|
The parameters recorded in the forward pass. |
required |
Returns:
| Type | Description |
|---|---|
Transform
|
A new |
Source code in src/torchio/transforms/transform.py
to_hydra()
Export as a Hydra-compatible config dict.
Returns a dict with _target_ set to the fully qualified
class name and only non-default field values included.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict suitable for |
Source code in src/torchio/transforms/transform.py
make_params(batch)
apply_transform(batch, params)
Apply histogram standardization to each selected image.
Source code in src/torchio/transforms/intensity/histogram_standardization.py
Landmark computation
compute_histogram_landmarks(images, *, quantiles=None, cutoff=DEFAULT_CUTOFF, masking_method=None)
Compute average histogram landmarks from training images.
Implements the training phase of
Nyúl and Udupa (1999) <https://ieeexplore.ieee.org/document/836373>_.
The returned landmarks tensor can be passed directly to
HistogramStandardization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
Sequence[ScalarImage | Path | str]
|
Training images. Each element can be a
|
required |
quantiles
|
Sequence[float] | None
|
Quantile positions in |
None
|
cutoff
|
tuple[float, float]
|
Lower and upper quantile bounds for the intensity
range of interest. Defaults to |
DEFAULT_CUTOFF
|
masking_method
|
Callable[[Tensor], Tensor] | None
|
Optional callable that takes a 4-D tensor
|
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
1-D tensor of landmark values, one per quantile. |
Examples:
>>> import torchio as tio
>>> from torchio.transforms.histogram_standardization import (
... compute_histogram_landmarks,
... )
>>> landmarks = compute_histogram_landmarks([
... tio.ScalarImage("subject_a_t1.nii"),
... tio.ScalarImage("subject_b_t1.nii"),
... ])