trw.transforms.resample
¶
Module Contents¶
Functions¶
|
Multiply all matrices |
|
Calculate a grid that maps a fixed geometry to a transformed moving geometry. |
|
Apply an affine transformation to a given (moving) volume into a given geometry (fixed) |
|
Resample a portion of a 3D volume (z, y, x) to a specified spacing/bounding box. |
|
- trw.transforms.resample.mm_list(matrices: List[torch.Tensor])¶
Multiply all matrices
- trw.transforms.resample.affine_grid_fixed_to_moving(geometry_moving: trw.transforms.spatial_info.SpatialInfo, geometry_fixed: trw.transforms.spatial_info.SpatialInfo, tfm: torch.Tensor, align_corners: bool = False) torch.Tensor ¶
Calculate a grid that maps a fixed geometry to a transformed moving geometry.
This can be used to resampled a volume to a different geometry / transformation.
- Parameters
geometry_moving – the moving geometry. This geometry will have an affine transformation tfm applied (e.g., translation, scaling)
geometry_fixed – the fixed geometry
tfm – a linear transformation that will move moving_volume
align_corners – should be false
- Returns
a N x D x C x H x W x dim grid
- trw.transforms.resample.resample_spatial_info(geometry_moving: trw.transforms.spatial_info.SpatialInfo, moving_volume: trw.basic_typing.TorchTensorNCX, geometry_fixed: trw.transforms.spatial_info.SpatialInfo, tfm: torch.Tensor, interpolation: typing_extensions.Literal[linear, nearest] = 'linear', padding_mode: typing_extensions.Literal[zeros, border, reflection] = 'zeros', align_corners: bool = False) trw.basic_typing.TorchTensorNCX ¶
Apply an affine transformation to a given (moving) volume into a given geometry (fixed)
- Parameters
geometry_moving – Defines the geometric space of the moving volume
moving_volume – the moving volume (2D or 3D)
geometry_fixed – define the geometric space to be resampled
tfm – an (dim + 1) x (dim + 1) affine transformation matrix that moves the moving volume
interpolation – how to interpolate the moving volume
padding_mode – defines how to handle missing (moving) data
align_corners – specifies how to align the voxel grids
- Returns
a volume with geometric space geometry_fixed. The content is the moving_volume moved by tfm
Notes
the gradient will be propagated through the transform
- trw.transforms.resample.resample_np_volume_3d(np_volume: trw.basic_typing.NumpyTensorX, np_volume_spacing: trw.basic_typing.Length, np_volume_origin: trw.basic_typing.Length, min_bb_mm: trw.basic_typing.Length, max_bb_mm: trw.basic_typing.Length, resampled_spacing: trw.basic_typing.Length, mode: typing_extensions.Literal[reflect, constant, nearest, mirror, wrap] = 'constant', constant_value: trw.basic_typing.Numeric = 0.0, order=1) trw.basic_typing.NumpyTensorX ¶
Resample a portion of a 3D volume (z, y, x) to a specified spacing/bounding box.
- Parameters
np_volume – a 3D volume
np_volume_spacing – the spacing [sz, sy, sx] of the input volume
np_volume_origin – the origin [z, y, x] of the input volume
min_bb_mm – the min position [z, y, x] of the input volume to be resampled
max_bb_mm – the max position [z, y, x] of the input volume to be resampled
resampled_spacing – the spacing of the resampled volume
mode – specifies how to handle the boundary. See
scipy.ndimage.affine_transform()
constant_value – if mode == constant, use constant_value as background value
order – interpolation order [0..5]
- Returns
resampled volume
Deprecated since version 0.0.2: Use resample_3d instead! This is just for comparison
- trw.transforms.resample.resample_3d(volume: trw.basic_typing.TensorX, np_volume_spacing: trw.basic_typing.Length, np_volume_origin: trw.basic_typing.Length, min_bb_mm: trw.basic_typing.Length, max_bb_mm: trw.basic_typing.Length, resampled_spacing: trw.basic_typing.Length, interpolation_mode: typing_extensions.Literal[linear, nearest] = 'linear', padding_mode: typing_extensions.Literal[zeros, border, reflection] = 'zeros', align_corners=False) trw.basic_typing.TensorX ¶