niftynet.contrib.csv_reader.sampler_uniform_v2_csv module

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

class UniformSamplerCSV(reader, csv_reader, window_sizes, batch_size=1, windows_per_image=1, queue_length=10, num_threads=4, smaller_final_batch_mode='drop', name='uniform_sampler_v2')[source]

Bases: niftynet.contrib.csv_reader.sampler_csv_rows.ImageWindowDatasetCSV

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.


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.

  • 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)

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