dltk.core.io package

dltk.core.io.augmentation module

dltk.core.io.augmentation.elastic_transform(image, alpha, sigma)[source]

Elastic deformation of images as described in [Simard2003]. .. [Simard2003] Simard, Steinkraus and Platt, “Best Practices for

Convolutional Neural Networks applied to Visual Document Analysis”, in Proc. of the International Conference on Document Analysis and Recognition, 2003. Based on gist https://gist.github.com/erniejunior/601cdf56d2b424757de5
Parameters:
  • image (np.ndarray) – image to be deformed
  • alpha (list) – scale of transformation for each dimension larger values have more deformation
  • sigma (list) – Gaussian window of deformation for each dimension smaller values have more localised deformation
Returns:

deformed image

Return type:

np.ndarray

dltk.core.io.augmentation.extract_class_balanced_example_array(image, label, example_size=[1, 64, 64], n_examples=1, classes=2, class_weights=None)[source]

Extract training examples from an image (and corresponding label) subject to class balancing. Returns an image example array and the corresponding label array.

Parameters:
  • image (np.ndarray) – image to extract class-balanced patches from
  • label (np.ndarray) – labels to use for balancing the classes
  • example_size (list or tuple) – shape of the patches to extract
  • n_examples (int) – number of patches to extract in total
  • classes (int or list or tuple) – number of classes or list of classes to extract
Returns:

class-balanced patches extracted from bigger images with shape [batch, example_size..., image_channels]

Return type:

ex_imgs, ex_lbls

dltk.core.io.augmentation.extract_random_example_array(image_list, example_size=[1, 64, 64], n_examples=1)[source]

Randomly extract training examples from image (and corresponding label). Returns an image example array and the corresponding label array.

Parameters:
  • image_list (np.ndarray or list or tuple) – image(s) to extract random patches from
  • example_size (list or tuple) – shape of the patches to extract
  • n_examples (int) – number of patches to extract in total
Returns:

random patches extracted from bigger images with same type as image_list with of shape [batch, example_size..., image_channels]

Return type:

examples

dltk.core.io.augmentation.flip(imglist, axis=1)[source]

Randomly flip spatial dimensions

Parameters:
  • imglist (np.ndarray or list or tuple) – image(s) to be flipped
  • axis (int) – axis along which to flip the images
Returns:

same as imglist but randomly flipped along axis

Return type:

np.ndarray or list or tuple

dltk.core.io.augmentation.gaussian_noise(img, sigma=0.05)[source]

Add Gaussian noise to an image

Parameters:
  • img (np.ndarray) – image to add noise to
  • sigma (float) – stddev for normal distribution to generate noise from
Returns:

same as image but with added noise

Return type:

np.ndarray

dltk.core.io.augmentation.gaussian_offset(img, sigma=0.1)[source]

Add Gaussian offset to an image

Adds the offset to each channel independently

Parameters:
  • img (np.ndarray) – image to add noise to
  • sigma (float) – stddev for normal distribution to generate noise from
Returns:

same as image but with added offset to each channel

Return type:

np.ndarray

dltk.core.io.preprocessing module

dltk.core.io.preprocessing.normalise_one_one(image)[source]

Image normalisation

Normalises image to fit [-1, 1] range

Parameters:image (np.ndarray) – image to be normalised
Returns:normalised image
Return type:np.ndarray
dltk.core.io.preprocessing.normalise_zero_one(image)[source]

Image normalisation

Normalises image to fit [0, 1] range

Parameters:image (np.ndarray) – image to be normalised
Returns:normalised image
Return type:np.ndarray
dltk.core.io.preprocessing.resize_image_with_crop_or_pad(image, img_size=[64, 64, 64], **kwargs)[source]

Image resizing

Resizes image by cropping or padding dimension to fit specified size.

Parameters:
  • image (np.ndarray) – image to be resized
  • img_size (list or tuple) – new image size
  • kwargs – additional arguments to be passed to np.pad
Returns:

resized image

Return type:

np.ndarray

dltk.core.io.preprocessing.whitening(image)[source]

Whitening

Normalises image to zero mean and unit variance

Parameters:image (np.ndarray) – image to be whitened
Returns:whitened image
Return type:np.ndarray

dltk.core.io.reader module

class dltk.core.io.reader.AbstractReader(dtypes, dshapes, name='reader')[source]

Bases: object

Abstract reader

Abstract reader class for data I/O. Provides the queue handling and wraps the specific reader functions to adapt given data types.

class dltk.core.io.reader.SimpleSITKReader(dtypes, dshapes, name='simplesitkreader')[source]

Bases: dltk.core.io.reader.AbstractReader

Simple reader class to read sitk files by file path

dltk.core.io.sliding_window module

class dltk.core.io.sliding_window.SlidingWindow(img_shape, window_shape, has_batch_dim=True, striding=None)[source]

Bases: object

Sliding window iterator which produces slice objects to slice in a sliding window. This is useful for inference.

next()[source]

Module contents