Swap
Bases: IntensityTransform
Randomly swap patches within an image.
This is typically used in context restoration for self-supervised learning. Pairs of same-sized patches are selected at random and their contents are exchanged.
Warning
This transform is intended for self-supervised or
unsupervised workflows. Because the spatial content is
rearranged, aligned label maps become inconsistent with the
swapped image. A warning is emitted if LabelMap images
are present in the subject.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patch_size
|
int | tuple[int, int, int]
|
Spatial size of the patches to swap. A single integer \(n\) means \((n, n, n)\). |
15
|
num_iterations
|
int | tuple[int, int]
|
Number of patch pairs to swap. A 2-tuple \((a, b)\) samples \(n \sim \mathcal{U}(a, b)\). |
100
|
**kwargs
|
Any
|
See |
{}
|
Examples:
Source code in src/torchio/transforms/intensity/swap.py
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)
Sample swap locations for each image.
Source code in src/torchio/transforms/intensity/swap.py
apply_transform(batch, params)
Swap patches in each selected image.