niftynet.layer.resampler module

Resampler layer initially implemented in https://github.com/niftk/NiftyNet/blob/v0.2.0.post1/niftynet/layer/spatial_transformer.py

class ResamplerLayer(interpolation='LINEAR', boundary='REPLICATE', name='resampler', implementation='Fast')[source]

Bases: niftynet.layer.base_layer.Layer

resample inputs according to sample_coords

layer_op(inputs, sample_coords)[source]

This layer resamples 2D or 3D data given the coordinates.

In terms of 3D inputs,

when the shape of inputs is [batch, x, y, z, num_channels], the shape of sample_coords can be [1, d0, d1, ..., 3] or [batch, d0, d1, ..., 3].

The output shape would be [batch, d0, d1, ..., num_channels].

Similarly, in 2D,

when the shape of inputs is [batch, x, y, num_channels], the shape of sample_coords can be [1, d0, d1, ..., 2] or [batch, d0, d1, ..., 2].

The output shape would be [batch, d0, d1, ... num_channels]

(If the shape of inputs is not fully specified, sample_coords must be checked before using this function, to make sure the coordinates are pointing to locations within the inputs.)

(Resampling 2D inputs is implemented by calling tf.contrib.resampler.resampler. The interpretaion of coordinates is different in between this function and tf.contrib.resampler.resampler: using self.layer_op(inputs, sample_coords) for 2D data is equivalent to (apart from the batch size broadcasting feature):

tf.contrib.resampler.resampler(
    tf.transpose(inputs, [0, 2, 1, 3]), sample_coords)
(No gradient is computed for NEAREST method, and
some of the padding modes.)