Affine
Bases: Spatial
Apply a random or fixed affine transform.
Convenience wrapper around Spatial exposing
only the affine parameters. The affine matrix data structure is
available as AffineMatrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scales
|
TypeParameterValue
|
See |
1.0
|
degrees
|
TypeParameterValue
|
See |
0.0
|
translation
|
TypeParameterValue
|
See |
0.0
|
isotropic
|
bool
|
See |
False
|
center
|
TypeCenter
|
See |
'image'
|
default_pad_value
|
TypePadValue | float
|
See |
'minimum'
|
default_pad_label
|
int | float
|
See |
0
|
image_interpolation
|
TypeImageInterpolation | int
|
See |
'linear'
|
label_interpolation
|
TypeLabelInterpolation | int
|
See |
'nearest'
|
one_hot_label_interpolation
|
TypeImageInterpolation | int
|
See |
'linear'
|
**kwargs
|
Any
|
See |
{}
|
Examples:
>>> import torchio as tio
>>> transform = tio.Affine(degrees=(-15, 15))
>>> transform = tio.Affine(scales=1.0, degrees=(0, 0, 90))
Source code in src/torchio/transforms/spatial/spatial.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
make_params(batch)
Sample random parameters and resolve the output space.
Scales, degrees, translation, and control-point displacements are sampled per batch element when per-instance augmentation is active (the default for batches), and once otherwise.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict of serializable parameters for |
dict[str, Any]
|
history replay. |
Source code in src/torchio/transforms/spatial/spatial.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
apply_transform(batch, params)
Apply the spatial mapping to every selected image in batch.
One sampling grid is built per batch element when per-instance parameters are present, and a single shared grid otherwise.
Source code in src/torchio/transforms/spatial/spatial.py
inverse(params)
Build the inverse transform from recorded parameters.
The affine component is inverted exactly. The elastic component
is approximated by negating the sampled displacement field. The
affine_first flag is flipped so that the inverse operations
run in the opposite order. Per-instance parameters are inverted
element by element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict[str, Any]
|
The parameter dict produced by |
required |
Returns:
| Type | Description |
|---|---|
_SpatialInverse
|
A |
Source code in src/torchio/transforms/spatial/spatial.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 |