niftynet.engine.image_window module

This module provides an interface for data elements to be generated by an image sampler.

class ImageWindow(shapes, dtypes)[source]

Bases: object

Each window is associated with a tuple of coordinates. These data properties are used to create TF placeholders or when constructing a TF graph. Sampler read the data specifications and fill the placeholder/dataset.

__init__(shapes, dtypes)[source]
  • shapes – A nested structure of tuple corresponding to size of each image window
  • dtypes – A nested structure of tf.DType objects corresponding to each image window

return – a tuple of output modality names


return – a dictionary of image window and location shapes


return – a dictionary of sampler output tensor shapes


return – tensorflow dtypes of the window.

classmethod from_data_reader_properties(source_names, image_shapes, image_dtypes, window_sizes=None, allow_dynamic=False)[source]

Create a window instance with input data properties each property is grouped into dict, with pairs of image_name: data_value. Some input images is a concatenated data array from multiple data sources. example of input:

    'image': (u'modality1', u'modality2'),
    'label': (u'modality3',)},
    'image': (192, 160, 192, 1, 2),
    'label': (192, 160, 192, 1, 1)},
    'image': tf.float32,
    'label': tf.float32},
    'image': (10, 10, 2),
    'label': (10, 10, 2)}

the window_sizes can also be:

    'modality1': (10, 10, 2),
    'modality3': (10, 10, 2)}

or using a nested dictionary with ‘spatial_window_size’ (deprecating):

    'modality1': {'spatial_window_size': (10, 10, 2)},
    'modality2': {'spatial_window_size': (10, 10, 2)},
    'modality3': {'spatial_window_size': (5, 5, 1)}}

see for more details.

  • source_names – input image names
  • image_shapes – tuple of image window shapes
  • image_dtypes – tuple of image window data types
  • window_sizes – window sizes for the image image
  • allow_dynamic – if True, window_sizes negative or 0 indicates dynamic window sizes; . Otherwise the dynamic sizes will be fixed as the image shapes; this assumes the same image size across the dataset.

an ImageWindow instance

set_spatial_shape(spatial_window, source_names=None)[source]

Set all spatial window of the window.

spatial_window should be a dictionary of window sizes tuples or single window size tuple. In the latter case the size will be used by all output image windows.

  • spatial_window – tuple of integers specifying new shape
  • source_names – list/dictionary of input source names


This function create a dictionary with items of {name: placeholders} name should match the queue input names placeholders corresponds to the image window data for each of these items an additional {location_name: placeholders} is created to hold the spatial location of the image window. Used in the queue-based tensorflow APIs.

Parameters:n_samples – specifies the number of image windows
Returns:a dictionary with window data and locations placeholders

Get coordinates placeholder, location name is formed using LOCATION_FORMAT. Used in the queue-based tensorflow APIs.

Parameters:name – input name string
Returns:coordinates placeholder

Get the image data placeholder by name. Used in the queue-based tensorflow APIs.

Parameters:name – input name string
Returns:image placeholder

If the window has dynamic shapes, this function infers the fully specified shape from the image_shapes.

Returns:dict of fully specified window shapes