niftynet.engine.sampler_weighted_v2 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, window_sizes, batch_size=1, windows_per_image=1, queue_length=10, name='weighted_sampler')[source]¶ Bases:
niftynet.engine.sampler_uniform_v2.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
(n_samples, img_spatial_size, win_spatial_size, sampler_map)[source]¶ Weighted sampling from a map. This function uses a cumulative histogram for fast sampling.
see also sampler_uniform.rand_spatial_coordinates
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, it’s spatial shape should be consistent with img_spatial_size
Returns: (n_samples, N_SPATIAL) coordinates representing sampling window centres relative to img_spatial_size
-
crop_sampling_map
(input_map, win_spatial_size)[source]¶ Utility function for generating a cropped version of the input sampling prior map (the input weight map where the centre of the window might be). If the centre of the window was outside of this crop area, the patch would be outside of the field of view
Parameters: - input_map – the input weight map where the centre of the window might be
- win_spatial_size – size of the borders to be cropped
Returns: cropped sampling map