niftynet.engine.sampler_weighted module

Generating image window by weighted sampling map from input image This can also be considered as a “weighted random cropping” layer of the input image.

class WeightedSampler(reader, data_param, batch_size, windows_per_image, queue_length=10)[source]

Bases: niftynet.engine.sampler_uniform.UniformSampler

This class generators samples from a user provided frequency map for each input volume The sampling likelihood of each voxel (and window around) is proportional to its frequency

This is implemented in a closed form using cumulative histograms for efficiency purposes i.e., the first three dims of image.

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

weighted_spatial_coordinates(subject_id, data, img_sizes, win_sizes, n_samples=1)[source]

This is the function that actually does the cumulative histogram and sampling.

also, note that win_sizes could be different (for example in segmentation network input image window size is 32x32x10, training label window is 16x16x10 – 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 concentric).