ants.deeplearn.extract_image_patches

extract_image_patches(image, patch_size, max_number_of_patches='all', stride_length=1, mask_image=None, random_seed=None, return_as_array=False, randomize=True)[source]

Extract 2-D or 3-D image patches.

Parameters:
  • image (ants.core.ANTsImage) – Input image with one or more components.

  • patch_size (n-D tuple (depending on dimensionality).) – Width, height, and depth (if 3-D) of patches.

  • max_number_of_patches (int or str) – Maximum number of patches returned. If “all” is specified, then all patches in sequence (defined by the stride_length are extracted.

  • stride_length (int or typing.Tuple) – Defines the sequential patch overlap for max_number_of_patches = “all”. Can be a image-dimensional vector or a scalar.

  • mask_image (ANTsImage (optional)) – Optional image specifying the sampling region for the patches when max_number_of_patches does not equal “all”. The way we constrain patch selection using a mask is by forcing each returned patch to have a masked voxel at its center.

  • random_seed (integer (optional)) – Seed value that allows reproducible patch extraction across runs.

  • return_as_array (bool) – Specifies the return type of the function. If False (default) the return type is a list where each element is a single patch. Otherwise the return type is an array of size dim( number_of_patches, patch_size ).

  • randomize (bool) – Boolean controlling whether we randomize indices when masking.

Return type:

A list (or array) of patches.

Example

>>> import ants
>>> image = ants.image_read(ants.get_ants_data('r16'))
>>> image_patches = extract_image_patches(image, patch_size=(32, 32))