niftynet.layer.spatial_transformer module¶
“Implementation of Spatial Transformer networks core components.
-
class
BSplineFieldImageGridWarperLayer
(source_shape, output_shape, knot_spacing, name='interpolated_spline_grid_warper_layer')[source]¶ Bases:
niftynet.layer.grid_warper.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
-
__init__
(source_shape, output_shape, knot_spacing, name='interpolated_spline_grid_warper_layer')[source]¶ Constructs an BSplineFieldImageGridWarperLayer. :param source_shape: Iterable of integers determining the size of the source
signal domain.Parameters: - output_shape – Iterable of integers determining the size of the destination resampled signal domain.
- knot_spacing – List of intervals (in voxels) in each dimension where displacements are defined in the field.
- interpolation – type_str of interpolation as used by tf.image.resize_images
- name – Name of Module.
-
class
RescaledFieldImageGridWarperLayer
(source_shape, output_shape, coeff_shape, interpolation=2, name='rescaling_interpolated_spline_grid_warper_layer')[source]¶ Bases:
niftynet.layer.grid_warper.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.
-
__init__
(source_shape, output_shape, coeff_shape, interpolation=2, name='rescaling_interpolated_spline_grid_warper_layer')[source]¶ Constructs an RescaledFieldImageGridWarperLayer. :param source_shape: Iterable of integers determining the size of the source
signal domain.Parameters: - output_shape – Iterable of integers determining the size of the destination resampled signal domain.
- coeff_shape – Shape of displacement field.
- interpolation – type_str of interpolation as used by tf.image.resize_images
- name – Name of Module.
-
-
class
ResampledFieldGridWarperLayer
(source_shape, output_shape, coeff_shape, field_transform=None, resampler=None, name='resampling_interpolated_spline_grid_warper')[source]¶ Bases:
niftynet.layer.grid_warper.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.
-
__init__
(source_shape, output_shape, coeff_shape, field_transform=None, resampler=None, name='resampling_interpolated_spline_grid_warper')[source]¶ Constructs an ResampledFieldingGridWarperLayer. :param source_shape: Iterable of integers determining the size of the source
signal domain.Parameters: - output_shape – Iterable of integers determining the size of the destination resampled signal domain.
- coeff_shape – Shape of displacement field.
- interpolation – type_str of interpolation as used by tf.image.resize_images
- name – Name of Module.
- field_transform –
an object defining the spatial relationship between the output_grid and the field. batch_size x4x4 tensor: per-image transform matrix from output coords to field coords None (default): corners of output map to corners of field with an allowance for
interpolation (1 for bspline, 0 for linear) - resampler – a ResamplerLayer used to interpolate the deformation field
- name – Name of module.
Raises: TypeError
– If output_shape and source_shape are not both iterable.
-
layer_op
(field)[source]¶ 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.
Parameters: 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.
-