Binary Operators¶
Affine Intensity Filter¶
-
class
AffineIntensity
(similarity, dim=2, init_affine=None, init_translation=None, device='cpu', dtype=torch.float32)[source]¶ -
static
Create
(similarity, dim=2, init_affine=None, init_translation=None, device='cpu', dtype=torch.float32)[source]¶ Object for registering two structured grids with an affine transformation. The affine and translation are optimized independently. This Affine Intensity filter must be on the same device as the target and moving structured grids. The affine and translation attributes have requires_grad=True so they can be added to a torch optimizer and updated with autograd functions.
- Parameters
similarity (
Filter
) – This is the similiarty filter used to compare the two structured grids to be registered. This filter is usually a Binary Operator (ie. L2 Image Similarity)dim (int) – Dimensionality of the structured grids to be registered (not including channels).
init_affine (tensor, optional) – Initial affine to apply to the moving structured grid.
init_translation (tensor, optional) – Initial translation to apply to the moving structured grid.
device (str) – Memory location - one of ‘cpu’, ‘cuda’, or ‘cuda:X’ where X specifies the device identifier. Default: ‘cpu’
dtype (str) – Data type for the attributes. Specified from torch memory types. Default: ‘torch.float32’
- Returns
Affine Intensity Filter Object
-
forward
(target, moving)[source]¶ Apply the forward affine operation applied to the moving image and calculate the resulting similarity measure between the target and moving images. The gradients on the affine and translation attributes are tracked through this forward operation so that the gradient update can be applied to update the affine and translation. This function is meant to be used iteratively in the registration process.
- Parameters
target (
StructuredGrid
) – Target structured grid. Does not get updated or changed.moving (
StructuredGrid
) – Moving structured grid. Affine and translation are applied this structured grid before the similarity calculation.
- Returns
Energy from the similarity evaluation (usually a single float).
-
static
Compose Grids Filter¶
-
class
ComposeGrids
(padding_mode='border', device='cpu', dtype=torch.float32)[source]¶ -
static
Create
(padding_mode='border', device='cpu', dtype=torch.float32)[source]¶ Object to compose
StructuredGrid
look-up table fields into one grid.- Parameters
pad_mode (str) – padding mode for outside grid values - one of ‘zeros’, ‘border’, or ‘reflection’. Default: ‘zeros’
device (str) – Memory location - one of ‘cpu’, ‘cuda’, or ‘cuda:X’ where X specifies the device identifier. Default: ‘cpu’
dtype (str) – Data type for the attributes. Specified from torch memory types. Default: ‘torch.float32’
- Returns
Object to compose a list of look-up tables.
-
forward
(L)[source]¶ Given a list of
StructuredGrid
look-up tables L = [L0, L1, L2] returns a composed look-up table comp_field = L2(L1(L0(x))) of typeStructuredGrid
.- Parameters
L (list, tuple) – List of look-up tables. All fields in the list must be on the same memory device.
- Returns
Composed look-up tables Comp_filed
-
static
L2 Image Similarity¶
-
class
L2Similarity
(dim=2, device='cpu', dtype=torch.float32)[source]¶ -
static
Create
(dim=2, device='cpu', dtype=torch.float32)[source]¶ Compare two
StructuredGrid
objects using an L2 similarity metric.- Parameters
dim (int) – Dimensionality of the
StructuredGrid
to be compared (not including channels).device (str) – Memory location - one of ‘cpu’, ‘cuda’, or ‘cuda:X’ where X specifies the device identifier. Default: ‘cpu’
dtype (str) – Data type for the attributes. Specified from torch memory types. Default: ‘torch.float32’
- Returns
L2 comparision object.
-
c1
(target, moving, grads)[source]¶ First derivative of the L2 similarity metric.
- Parameters
target (
StructuredGrid
) – Structured Grid 1moving (
StructuredGrid
) – Structured Grid 2grads (
StructuredGrid
) – Gradients of the moving image.
- Returns
-
forward
(target, moving)[source]¶ Compare two
StructuredGrid
with L2 similarity metric. This is often used for registration so the variables are labeled as target and moving. This function preserves the dimensionality of the original grids.- Parameters
target (
StructuredGrid
) – Structured Grid 1moving (
StructuredGrid
) – Structured Grid 2
- Returns
L2 similarity as
StructuredGrid
-
static
Normalized Cross Correlation Filter¶
-
class
NormalizedCrossCorrelation
(grid, window=5, device='cpu', dtype=torch.float32)[source]¶ -
-
forward
(target, moving)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-