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 tf.data.Dataset when constructing a TF graph. Sampler read the data specifications and fill the placeholder/dataset.

__init__(shapes, dtypes)[source]
Parameters:
  • 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
names

a tuple of output modality names

Type:return
shapes

a dictionary of image window and location shapes

Type:return
tf_shapes

a dictionary of sampler output tensor shapes

Type:return
tf_dtypes

tensorflow dtypes of the window.

Type:return
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:

source_names={
    'image': (u'modality1', u'modality2'),
    'label': (u'modality3',)},
image_shapes={
    'image': (192, 160, 192, 1, 2),
    'label': (192, 160, 192, 1, 1)},
image_dtypes={
    'image': tf.float32,
    'label': tf.float32},
window_sizes={
    'image': (10, 10, 2),
    'label': (10, 10, 2)}

the window_sizes can also be:

window_sizes={
    'modality1': (10, 10, 2),
    'modality3': (10, 10, 2)}

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

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

see niftynet.io.ImageReader for more details.

Parameters:
  • 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.
Returns:

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.

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

placeholders_dict(n_samples=1)[source]

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
coordinates_placeholder(name)[source]

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
image_data_placeholder(name)[source]

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

Parameters:name – input name string
Returns:image placeholder
match_image_shapes(image_shapes)[source]

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

Parameters:image_shapes
Returns:dict of fully specified window shapes