CornucopiaAdapter
Bases: Transform
Wrap a Cornucopia transform for use in TorchIO pipelines.
Cornucopia <https://cornucopia.readthedocs.io/>_ transforms
operate on (C, I, J, K) tensors and support passing multiple
tensors to share spatial parameters (e.g., the same elastic
deformation is applied to an image and its segmentation).
The adapter extracts image tensors from the subject, passes them to the Cornucopia transform as positional arguments (scalar images first, then label maps), and writes the results back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cornucopia_transform
|
Callable
|
A Cornucopia transform (any callable
accepting one or more |
required |
**kwargs
|
Any
|
See |
{}
|
Examples:
>>> import torchio as tio
>>> import cornucopia as cc
>>> adapter = tio.CornucopiaAdapter(
... cc.ElasticTransform(),
... )
>>> result = adapter(subject)
Note
CornucopiaAdapter does not record itself in the
subject's transform history, because Cornucopia transform
objects are not guaranteed to be serializable.
Source code in src/torchio/transforms/cornucopia_adapter.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
Cornucopia transforms are not invertible through TorchIO.
make_params(batch)
Sample random parameters for this transform.
Override in subclasses that have random behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
SubjectsBatch
|
A |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict of sampled parameters. |
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
forward(data)
Apply without recording history.
Source code in src/torchio/transforms/cornucopia_adapter.py
apply_transform(batch, params)
Not used: CornucopiaAdapter overrides forward directly.