SequentialLabels
Bases: Transform
Renumber labels in label maps to consecutive integers starting from 0.
For example, if a label map has values {0, 5, 10}, this
transform remaps them to {0, 1, 2}.
Only LabelMap images are affected.
Note
The background (label 0) is always mapped to 0. Even if there are no zeros in the input, zero will appear in the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
See |
{}
|
Examples:
Source code in src/torchio/transforms/label/sequential_labels.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 |
apply_with_params(data, params)
Apply an exact parameter set without sampling.
This method bypasses the transform probability and
make_params(), but otherwise
follows the normal transform lifecycle: copy handling, input
wrapping, output-type restoration, and history recording.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Input data to transform. |
required |
params
|
dict[str, Any]
|
Exact parameters accepted by |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Transformed data with the same type as the input. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
NotImplementedError
|
If the transform does not expose one exact-parameter kernel. |
ValueError
|
If per-instance parameter dimensions do not match the input batch. |
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)
Compute the remapping from the first sample's labels.
Source code in src/torchio/transforms/label/sequential_labels.py
apply_transform(batch, params)
Apply sequential renumbering.
Source code in src/torchio/transforms/label/sequential_labels.py
inverse(params)
Invert by restoring original label values.