RemapLabels
Bases: Transform
Reassign label values in label maps.
Each key in the remapping dict is replaced by its value. Labels not mentioned in the dict are left unchanged.
Only LabelMap images are affected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remapping
|
dict[int, int]
|
Dictionary mapping old labels to new labels. |
required |
**kwargs
|
Any
|
See |
{}
|
Examples:
>>> import torchio as tio
>>> # Merge labels 2 and 3 into label 1
>>> transform = tio.RemapLabels({2: 1, 3: 1})
>>> # Swap labels 1 and 2
>>> transform = tio.RemapLabels({1: 2, 2: 1})
Source code in src/torchio/transforms/label/remap_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 |
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)
Remap labels in each label map.
Source code in src/torchio/transforms/label/remap_labels.py
inverse(params)
Invert by swapping keys and values.