niftynet.contrib.csv_reader.sampler_grid_v2_csv module¶
Sampling image by a sliding window.
-
class
GridSamplerCSV
(reader, csv_reader, window_sizes, batch_size=1, spatial_window_size=None, window_border=None, queue_length=10, smaller_final_batch_mode='pad', name='grid_sampler')[source]¶ Bases:
niftynet.contrib.csv_reader.sampler_csv_rows.ImageWindowDatasetCSV
This class generators ND image samples with a sliding window.
-
layer_op
(idx=None)[source]¶ Generating each image as a window. Overriding this function to create new image sampling strategies.
This function should either yield a dictionary (for single window per image):
yield a dictionary { 'image_name': a numpy array, 'image_name_location': (image_id, x_start, y_start, z_start, x_end, y_end, z_end) }
or return a dictionary (for multiple windows per image):
return a dictionary: { 'image_name': a numpy array, 'image_name_location': [n_samples, 7] }
where the 7-element location vector encode the image_id, starting and ending coordinates of the image window.
Following the same notation, the dictionary can be extended to multiple modalities; the keys will be:
{'image_name_1', 'image_name_location_1', 'image_name_2', 'image_name_location_2', ...}
Parameters: idx – image_id used to load the image at the i-th row of the input Returns: a image data dictionary
-
-
grid_spatial_coordinates
(subject_id, img_sizes, win_sizes, border_size)[source]¶ This function generates all coordinates of feasible windows, with step sizes specified in grid_size parameter.
The border size changes the sampling locations but not the corresponding window sizes of the coordinates.
Parameters: - subject_id – integer value indicates the position of of this
image in
image_reader.file_list
- img_sizes – a dictionary of image shapes,
{input_name: shape}
- win_sizes – a dictionary of window shapes,
{input_name: shape}
- border_size – size of padding on both sides of each dim
Returns: - subject_id – integer value indicates the position of of this
image in