niftynet.contrib.csv_reader.sampler_csvpatch module

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

class CSVPatchSampler(reader, csv_reader, window_sizes, batch_size=1, windows_per_image=1, queue_length=10, mode_correction='pad', name='csv_patchsampler_v2')[source]

Bases: niftynet.contrib.csv_reader.sampler_csv_rows.ImageWindowDatasetCSV

This class generates samples using the coordinates of the centre as extracted from a csv file

This layer can be considered as a “guided cropping” layer of the input image based on preselected input.


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

It first find the appropriate indices from the data frame in which the centre samples are stored and extract information about the windows to draw on the data. The final dictionary is filled according to the appropriate samples. Different modes on how to take care of unsuitable centres (too big patch size for instance are implemented)

Returns:output data dictionary {image_modality: data_array, image_location: n_samples * 7}
csvcenter_spatial_coordinates(subject_id, data, img_sizes, win_sizes, mode_correction='pad', n_samples=1)[source]

Generate spatial coordinates for sampling.

Values in win_sizes could be different – for example in a segmentation network win_sizes could be ``{‘training_image_spatial_window’: (32, 32, 10),

‘Manual_label_spatial_window’: (16, 16, 10)}``

(the network reduces x-y plane spatial resolution).

This function handles this situation by first find the largest window across these window definitions, and generate the coordinates. These coordinates are then adjusted for each of the smaller window sizes (the output windows are almost concentric) This function provide the appropriate sampled coordinates modified according to knowledge of the reader constraints on resolution and orientation.

transform_centres(subject_id, img_sizes, windows_centres)[source]
check_csv_sampler_valid(subject_id, img_sizes, win_sizes)[source]
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