Utilities

Input/Output Functions

synthit.util.io

handle io operations for the synthit package

Author: Jacob Reinhold (jacob.reinhold@jhu.edu)

Created on: Jun 20, 2018

synthit.util.io.split_filename(filepath)

split a filepath into the directory, base, and extension

synthit.util.io.glob_nii(path)

grab all nifti files in a directory and sort them for consistency

Patch Extraction

synthit.util.patches

handle the extraction of patches and reconstruction from patches of 3d arrays (namely, 3d MR images)

Author: Jacob Reinhold (jacob.reinhold@jhu.edu)

Created on: Jun 20, 2018

synthit.util.patches.extract_patches(data, idxs=None, patch_size=3, min_val=0, ctx_radius=(3, 5, 7), economy_patch=True, mean=False)

extract patches (with or without context) from a 3D image

if the user sets patch_size equal to 1 and ctx_radius equal to (0,), then all (and only) the values of idxs will be directly pulled from the numpy array (very fast!)

if the user sets patch_size equal to 0, then the central pixel will not be extracted, only the six nearest neighbors and context features will be extracted

Parameters:
  • data (np.ndarray) – 3d data
  • idxs (tuple) – tuple of np.ndarrays corresponding to indices (e.g., output from np.where)
  • patch_size (int) – patch size (this cubed), must be odd
  • min_val (float) – minimum value of extracted indices if idxs not provided
  • ctx_radius (tuple) – tuple of positive integers greater than patch size ((0) if no context desired)
  • economy_patch (bool) – return ‘economy-sized’ patches (not full patches, just the center and the 6-nearest neighbor voxels)
  • mean (bool) – return mean value of patches
Returns:

array of patches

Return type:

patches (np.ndarray)