niftynet.engine.sampler_uniform_v2 module

Generating uniformly distributed image window from input image This can also be considered as a “random cropping” layer of the input image.

class UniformSampler(reader, window_sizes, batch_size=1, windows_per_image=1, queue_length=10, name='uniform_sampler_v2')[source]

Bases: niftynet.engine.image_window_dataset.ImageWindowDataset

This class generates samples by uniformly sampling each input volume currently the coordinates are randomised for spatial dims only, i.e., the first three dims of image.

This layer can be considered as a “random cropping” layer of the input image.

layer_op(idx=None)[source]

This function generates sampling windows to the input buffer image data are from self.reader()

It first completes window shapes based on image data, then finds random coordinates based on the window shapes finally extract window with the coordinates and output a dictionary (required by input buffer).

Returns:output data dictionary {image_modality: data_array, image_location: n_samples * 7}
rand_spatial_coordinates(n_samples, img_spatial_size, win_spatial_size, sampler_map)[source]

Generate spatial coordinates from a discrete uniform distribution.

Parameters:
  • n_samples – number of random coordinates to generate
  • img_spatial_size – input image size
  • win_spatial_size – input window size
  • sampler_map – sampling prior map (not in use)
Returns:

(n_samples, N_SPATIAL) coordinates representing sampling window centres relative to img_spatial_size