Transpose
Bases: SpatialTransform
Swap the first and last spatial dimensions.
Transforms an image of shape \((C, I, J, K)\) into \((C, K, J, I)\). The affine matrix is updated to reflect the reordering so that world coordinates remain consistent.
This is the v2 equivalent of v1's Transpose, which reversed
the orientation string. The transform is its own inverse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
See |
{}
|
Examples:
Source code in src/torchio/transforms/spatial/transpose.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
Transpose is its own inverse.
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)
apply_transform(batch, params)
Swap first and last spatial axes for all images.