Unary Operators¶
Affine Transform Filter¶
-
class
AffineTransform
(target_landmarks=None, source_landmarks=None, affine=None, rigid=False, interp_mode='bilinear', device='cpu', dtype=torch.float32)[source]¶ Bases:
camp.StructuredGridOperators.UnaryOperators._UnaryFilter.Filter
-
static
Create
(target_landmarks=None, source_landmarks=None, affine=None, rigid=False, interp_mode='bilinear', device='cpu', dtype=torch.float32)[source]¶ Returns an Affine Transform Filter that can be applied to type
StructuredGrid
. This can be initiated using a pair of landmarks (target and source) or with a pre-defined affine transformation (affine). Either both target and source landmarks must be provided OR a pre-defined affine.- Parameters
target_landmarks (tensor, optional) – Target or unmoving landmarks selected in the target space. This tensor should be of size Nxdim where N is the number of landmarks and dim is the dimensionality of the
StructuredGrid
the affine will be applied to.source_landmarks (tensor, optional) – Source or moving landmarks selected in the source space. This tensor should be of size Nxdim where N is the number of landmarks and dim is the dimensionality of the
StructuredGrid
the affine will be applied to.affine (tensor, optional) – Pre-defined affine. This should be of shape (dim + 1)x(dim + 1) where the added dimension stores the translation.
rigid (bool) – If the affine should be reduced to rigid transform only. Default is False.
interp_mode (str) – Resampling interpolation mode to be used when applying the defromation - one of ‘bilinear’ or ‘nearest’. Default: ‘bilinear’
device (str) – Memory location for the created filter - one of ‘cpu’, ‘cuda’, or ‘cuda:X’ where X specifies the device identifier. Default: ‘cpu’
dtype (str) – Data type for the filter attributes. Specified from torch memory types. Default: ‘torch.float32’
Note
When mode=’bilinear’ and the input is 5-D, the interpolation mode used internally will actually be trilinear. However, when the input is 4-D, the interpolation mode will legitimately be bilinear.
- Returns
Affine transform filter object with the specified parameters.
-
forward
(x, out_grid=None, xyz_affine=False)[source]¶ Resamples the
Core.StructuredGrid
through the affine attribute onto the same grid or the out_grid if out_grid is provided.- Parameters
x (
Core.StructuredGrid
) –StructuredGrid
to be transformed by the affine attribute.out_grid (
Core.StructuredGrid
, optional) – An optional additional grid that specifies the output grid. If not specified, the output grid will be the same as the input grid (x).xyz_affine (bool, optional) – Is affine xyz ordered instead of zyx?
- Returns
Affine transformed
StructredGrid
-
static
Apply Grid Filter¶
-
class
ApplyGrid
(grid, interp_mode='bilinear', pad_mode='zeros', device='cpu', dtype=torch.float32)[source]¶ Bases:
camp.StructuredGridOperators.UnaryOperators._UnaryFilter.Filter
-
static
Create
(grid, interp_mode='bilinear', pad_mode='zeros', device='cpu', dtype=torch.float32)[source]¶ Returns an Apply Grid Filter that contained a deformation field that can be applied to type
StructuredGrid
and adds all attributes to the appropriate memory device.- Parameters
grid (
StructuredGrid
) – The deformation field to be applied by the Apply Grid Filter. This is assumed to be in real-world coordinates relative to the spacing and origin of the grid.interp_mode (str) – Resampling interpolation mode to be used when applying the defromation - one of ‘bilinear’ or ‘nearest’. Default: ‘bilinear’
pad_mode (str) – padding mode for outside grid values - one of ‘zeros’, ‘border’, or ‘reflection’. Default: ‘zeros’
device (str) – Memory location for the created Apply Grid Filter - one of ‘cpu’, ‘cuda’, or ‘cuda:X’ where X specifies the device identifier. Default: ‘cpu’
dtype (str) – Data type for the Apply Grid Filter attributes. Specified from torch memory types. Default: ‘torch.float32’
Note
When mode=’bilinear’ and the input is 5-D, the interpolation mode used internally will actually be trilinear. However, when the input is 4-D, the interpolation mode will legitimately be bilinear.
- Returns
Apply Grid Filter with the specified parameters.
-
forward
(in_grid, out_grid=None)[source]¶ Apply the grid attribute to in_grid.
- Parameters
in_grid (
StructuredGrid
) – The :class:’StructuredGrid’ to apply the grid attribute to.out_grid (
StructuredGrid
, optional) – An optional additional grid that specifies the output grid. If not specified, the output grid will be the same as the input grid.
- Returns
Returns in_grid resampled through the grid attribute onto the out_grid.
-
static
Divergence Filter¶
-
class
Divergence
(dim=2, device='cpu', dtype=torch.float32)[source]¶ -
static
Create
(dim=2, device='cpu', dtype=torch.float32)[source]¶ Create a object to calculate the divergence of a look-up table field
StructuredGrid
.- Parameters
dim (int) – Dimension of the
StructuredGrid
the filter will be applied to (not including channels).device (str) – Memory location for the created filter - one of ‘cpu’, ‘cuda’, or ‘cuda:X’ where X specifies the device identifier. Default: ‘cpu’
dtype (str) – Data type for the filter attributes. Specified from torch memory types. Default: ‘torch.float32’
- Returns
Divergence filter object with the specified parameters.
-
forward
(x)[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.
-
static
Fluid Kernel Filter¶
-
class
FluidKernel
(grid, alpha=1.0, beta=0.0, gamma=0.001, device='cpu', dtype=torch.float32)[source]¶ -
-
forward
(x, inverse)[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.
-
Gaussian Filter¶
-
class
Gaussian
(channels, kernel_size, sigma, dim=2, device='cpu', dtype=torch.float32)[source]¶ Bases:
camp.StructuredGridOperators.UnaryOperators._UnaryFilter.Filter
-
static
Create
(channels, kernel_size, sigma, dim=2, device='cpu', dtype=torch.float32)[source]¶ Create a filter to gaussian blur a
StructuredGrid
with the specified number of channels.- Parameters
channels (int) – Number of channels in the
StructuredGrid
to be blurred.kernel_size (int) – Size of the kernel to use.
sigma (int) – Sigma of the gaussian kernel.
dim (int) – Number of dimensions in the
StructuredGrid
the filter will be applied to (not including channels).device (str) – Memory location for the created filter - one of ‘cpu’, ‘cuda’, or ‘cuda:X’ where X specifies the device identifier. Default: ‘cpu’
dtype (str) – Data type for the filter attributes. Specified from torch memory types. Default: ‘torch.float32’
- Returns
Gaussian filter object with the specified parameters.
-
static
Gradient Filter¶
-
class
Gradient
(dim=2, device='cpu', dtype=torch.float32)[source]¶ Bases:
camp.StructuredGridOperators.UnaryOperators._UnaryFilter.Filter
-
static
Create
(dim=2, device='cpu', dtype=torch.float32)[source]¶ Create a filter to calculate the central difference of a
StructuredGrid
.- Parameters
dim (int) – Number of dimensions in the
StructuredGrid
the filter will be applied to (not including channels).device (str) – Memory location for the created filter - one of ‘cpu’, ‘cuda’, or ‘cuda:X’ where X specifies the device identifier. Default: ‘cpu’
dtype (str) – Data type for the filter attributes. Specified from torch memory types. Default: ‘torch.float32’
- Returns
Gaussian filter object with the specified parameters.
-
static
Gradient Regularizer¶
-
class
NormGradient
(weight, dim=2, device='cpu', dtype=torch.float32)[source]¶ -
-
forward
(vector_field)[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.
-
Jacobian Determinant Filter¶
-
class
JacobianDeterminant
(dim=2, device='cpu', dtype=torch.float32)[source]¶ -
static
Create
(dim=2, device='cpu', dtype=torch.float32)[source]¶ Create a filter to calculate the Jacobian determinant of a look-up table
StructuredGrid
.- Parameters
dim (int) – Number of dimensions in the
StructuredGrid
the filter will be applied to (not including channels).device (str) – Memory location for the created filter - one of ‘cpu’, ‘cuda’, or ‘cuda:X’ where X specifies the device identifier. Default: ‘cpu’
dtype (str) – Data type for the filter attributes. Specified from torch memory types. Default: ‘torch.float32’
- Returns
Jacobian determinant filter object.
-
static
Radial Basis Filter¶
Resample World Filter¶
-
class
ResampleWorld
(grid, interp_mode='bilinear', pad_mode='zeros', device='cpu', dtype=torch.float32)[source]¶ -
static
Create
(grid, interp_mode='bilinear', pad_mode='zeros', device='cpu', dtype=torch.float32)[source]¶
-
forward
(x)[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.
-
static
Variance Equalize Filter¶
-
class
VarianceEqualize
(kernel_size=11, sigma=2.0, eps=0.001, device='cpu', dtype=torch.float32)[source]¶ Takes an Image and gives the variance equalized version.
I_out, Im: PyCA Image3Ds sigma: (scalar) gaussian filter parameter eps: (scalar) division regularizer
sigma is the width (in voxels) of the gaussian kernel eps is the regularizer
for a gaussian kernel k, we have
I_ve = I’/sqrt(k * I’^2) where I’ = I - k*I
-
forward
(x)[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.
-