niftynet.layer.spatial_transformer module¶
“Implementation of Spatial Transformer networks core components.
-
class
niftynet.layer.spatial_transformer.
AffineGridWarperLayer
(source_shape, output_shape, constraints=None, name='affine_grid_warper')¶ Bases:
niftynet.layer.spatial_transformer.GridWarperLayer
Affine Grid Warper class.
The affine grid warper generates a reference grid of n-dimensional points and warps it via an affine transormation model determined by an input parameter Tensor. Some of the transformation parameters can be fixed at construction time via an AffineWarpConstraints object.
-
constraints
¶
-
inverse
(name=None)¶ Returns a sonnet module to compute inverse affine transforms.
The function first assembles a network that given the constraints of the current AffineGridWarper and a set of input parameters, retrieves the coefficients of the corresponding inverse affine transform, then feeds its output into a new AffineGridWarper setup to correctly warp the output space into the source space.- Args:
- name: Name of module implementing the inverse grid transformation.
- Returns:
- A sonnet module performing the inverse affine transform of a reference grid of points via an AffineGridWarper module.
- Raises:
- tf.errors.UnimplementedError: If the function is called on a non 2D
- instance of AffineGridWarper.
-
layer_op
(inputs)¶ Assembles the module network and adds it to the graph.
The internal computation graph is assembled according to the set of constraints provided at construction time.
- Args:
- inputs: Tensor containing a batch of transformation parameters.
- Returns:
- A batch of warped grids.
- Raises:
- Error: If the input tensor size is not consistent with the constraints
- passed at construction time.
-
-
class
niftynet.layer.spatial_transformer.
AffineWarpConstraints
(constraints=((None, None, None), (None, None, None)))¶ Bases:
object
Affine warp contraints class.
AffineWarpConstraints allow for very succinct definitions of constraints on the values of entries in affine transform matrices.
-
combine_with
(additional_constraints)¶ Combines two sets of constraints into a coherent single set.
-
constraints
¶
-
mask
¶
-
classmethod
no_constraints
(num_dim=2)¶ Empty set of constraints for a num_dim-ensional affine transform.
-
classmethod
no_shear_2d
()¶
-
classmethod
no_shear_3d
()¶ Assigns contraints on shear components of affine transform in 3d.
-
num_dim
¶
-
num_free_params
¶
-
classmethod
scale_2d
(x=None, y=None)¶ Assigns contraints on scaling components of affine transform in 2d.
-
classmethod
scale_3d
(x=None, y=None, z=None)¶ Assigns contraints on scaling components of affine transform in 3d.
-
classmethod
shear_2d
(x=None, y=None)¶ Assigns contraints on shear components of affine transform in 2d.
-
classmethod
translation_2d
(x=None, y=None)¶ Assign contraints on translation components of affine transform in 2d.
-
classmethod
translation_3d
(x=None, y=None, z=None)¶ Assign contraints on translation components of affine transform in 3d.
-
-
class
niftynet.layer.spatial_transformer.
BSplineFieldImageGridWarperLayer
(source_shape, output_shape, knot_spacing, name='interpolated_spline_grid_warper_layer')¶ Bases:
niftynet.layer.spatial_transformer.GridWarperLayer
- The fast BSpline Grid Warper defines a grid based on
- sampling coordinate values from a spatially varying displacement field (passed as a tensor input) along a regular cartesian grid pattern aligned with the field. Specifically,
- this class defines a grid based on BSpline smoothing, as described by Rueckert et al.
To ensure that it can be done efficiently, several assumptions are made: 1) The grid is a cartesian grid aligned with the field. 2) Knots occur every M,N,O grid points (in X,Y,Z) This allows the
smoothing to be represented as a 4x4x4 convolutional kernel with MxNxO channels
-
layer_op
(field)¶
-
class
niftynet.layer.spatial_transformer.
GridWarperLayer
(source_shape, output_shape, coeff_shape, name, **kwargs)¶ Bases:
niftynet.layer.base_layer.Layer
Grid warper interface class.
An object implementing the GridWarper interface generates a reference grid of feature points at construction time, and warps it via a parametric transformation model, specified at run time by an input parameter Tensor. Grid warpers must then implement a create_features function used to generate the reference grid to be warped in the forward pass (according to a determined warping model).
-
coeff_shape
¶ Returns number of coefficients of warping function.
-
output_shape
¶ Returns a tuple containing the shape of the output grid.
-
psi
¶ Returns a list of features used to compute the grid warp.
-
source_shape
¶ Returns a tuple containing the shape of the source signal.
-
-
class
niftynet.layer.spatial_transformer.
ResampledFieldGridWarperLayer
(source_shape, output_shape, coeff_shape, field_transform=None, resampler=None, name='resampling_interpolated_spline_grid_warper')¶ Bases:
niftynet.layer.spatial_transformer.GridWarperLayer
The resampled field grid warper defines a grid based on sampling coordinate values from a spatially varying displacement field (passed as a tensor input) along an affine grid pattern in the field. This enables grids representing small patches of a larger transform, as well as the composition of multiple transforms before sampling.
-
layer_op
(field)¶ Assembles the module network and adds it to the graph.
The internal computation graph is assembled according to the set of constraints provided at construction time.
- Args:
- field: Tensor containing a batch of transformation parameters.
- Returns:
- A batch of warped grids.
- Raises:
- Error: If the input tensor size is not consistent with the constraints
- passed at construction time.
-
-
class
niftynet.layer.spatial_transformer.
ResamplerLayer
(interpolation='LINEAR', boundary='REPLICATE', name='resampler')¶ Bases:
niftynet.layer.base_layer.Layer
Resampler class
Takes an input tensor and a sampling definition (e.g. a list of grid points) at run-time and returns one or more values for each grid location
-
boundary_circular
(sample_coords, input_size)¶
-
boundary_replicate
(sample_coords, input_size)¶
-
boundary_symmetric
(sample_coords, input_size)¶
-
layer_op
(inputs, sample_coords)¶
-
resample_bspline
(inputs, sample_coords)¶
-
resample_linear
(inputs, sample_coords)¶
-
resample_nearest
(inputs, sample_coords)¶
-
-
class
niftynet.layer.spatial_transformer.
RescaledFieldImageGridWarperLayer
(source_shape, output_shape, coeff_shape, interpolation=2, name='rescaling_interpolated_spline_grid_warper_layer')¶ Bases:
niftynet.layer.spatial_transformer.GridWarperLayer
The rescaled field grid warper defines a grid based on sampling coordinate values from a spatially varying displacement field (passed as a tensor input) along a regular cartesian grid pattern aligned with the field. Specifically, this class defines a grid by resampling the field (using tf.rescale_images with align_corners=False) to the output_shape.
-
layer_op
(field)¶
-