preprocessor

preprocessor.correct_bias_field(img, mask=None, scale=0.25, niters=[50, 50, 50, 50])[source]

Correct bias field in image using the N4ITK algorithm (http://bit.ly/2oFwAun)

img : {SimpleITK.SimpleITK.Image}
Input image with bias field.
mask : {SimpleITK.SimpleITK.Image}, optional
If used, the bias field will only be corrected within the mask. (the default is None, which results in the whole image being corrected.)
scale : {float}, optional
Scale at which to compute the bias correction. (the default is 0.25, which results in bias correction computed on an image downsampled to 1/4 of it’s original size)
niters : {list}, optional
Number of iterations per resolution. Each additional entry in the list adds an additional resolution at which the bias is estimated. (the default is [50, 50, 50, 50] which results in 50 iterations per resolution at 4 resolutions)
Returns:

SimpleITK.SimpleITK.Image

Bias-corrected image that has the same size and spacing as the input image.

preprocessor.create_mask(img, use_triangle=False)[source]

Creates a mask of the image to separate brain from background using triangle or otsu thresholding. Otsu thresholding is the default.

img : {SimpleITK.SimpleITK.Image}
Image to compute the mask on.
use_triangle : {bool}, optional
Set to True if you want to use triangle thresholding. (the default is False, which results in Otsu thresholding)
Returns:

SimpleITK.SimpleITK.Image

Binary mask with 1s as the foreground and 0s as the background.

preprocessor.downsample_and_reorient(atlas, target, atlas_orient, target_orient, spacing, size=[], set_origin=True, dv_atlas=0.0, dv_target=0.0)[source]

make sure img1 is the source and img2 is the target. iamges will be resampled to match the coordinate system of img2.

preprocessor.imgHM(img, ref_img, numMatchPoints=64, numBins=256)[source]

Performs histogram matching on two images.

img : {SimpleITK.SimpleITK.Image}
Image on which histogram matching is performed.
ref_img : {SimpleITK.SimpleITK.Image}
reference image for histogram matching.
numMatchPoints : {int}, optional
number of quantile values to be matched. (the default is 64)
numBins : {int}, optional
Number of bins used in computation of the histogram(the default is 256)
Returns:

SimpleITK.SimpleITK.Image

Input image histgram-matched to the reference image.

preprocessor.imgReorient(img, in_orient, out_orient)[source]

Reorients input image to match out_orient.

img : {SimpleITK.SimpleITK.Image}
Input 3D image.
in_orient : {str}
3-letter string indicating orientation of brain.
out_orient : {str}
3-letter string indicating desired orientation of input.
Returns:

SimpleITK.SimpleITK.Image

Reoriented input image.

preprocessor.imgResample(img, spacing, size=[], useNearest=False, origin=None, outsideValue=0)[source]

Resample image to certain spacing and size.

img : {SimpleITK.SimpleITK.Image}
Input 3D image.
spacing : {list}
List of length 3 indicating the voxel spacing as [x, y, z]
size : {list}, optional
List of length 3 indicating the number of voxels per dim [x, y, z] (the default is [], which will use compute the appropriate size based on the spacing.)
useNearest : {bool}, optional
If True use nearest neighbor interpolation. (the default is False, which will use linear interpolation.)
origin : {list}, optional
The location in physical space representing the [0,0,0] voxel in the input image. (the default is [0,0,0])
outsideValue : {int}, optional
value used to pad are outside image (the default is 0)
Returns:

SimpleITK.SimpleITK.Image

Resampled input image.

preprocessor.normalize(img, percentile=0.99)[source]
preprocessor.preprocess_brain(img, spacing, modality, image_orientation, atlas_orientation='pir')[source]

Perform all preprocessing steps associated with a given imaging modality.

img : {SimpleITK.SimpleITK.Image}
Input brain image to preprocess.
spacing : {list}
Voxel spacing in the x, y, and z direction, respectively, in mm.
modality : {str}
Can be either ‘lavision’ or ‘colm’ depending on the microscope used to collect the images.
image_orientation : {str}
A 3-letter string describing the orientation of the brain along the x, y, and z axes. See (http://www.grahamwideman.com/gw/brain/orientation/orientterms.htm) for more information
atlas_orientation : {str}, optional
Orientation of the atlas you are using. (the default is ‘pir’, which is the orientation for the Allen Reference Atlas.)
Returns:

SimpleITK.SimpleITK.Image

Preprocessed mouse brain volume.

preprocessor.remove_grid_artifact(img, z_axis=1, sigma=10, mask=None)[source]

Remove the gridding artifact from COLM images.

img : {SimpleITK.SimpleITK.Image}
Input image.
z_axis : {int}, optional
An int indicating which axis is the z-axis. Can be 0, 1, or 2 (the default is 1, which indicates the 2nd dimension is the z axis)
sigma : {int}, optional
The variance of the gaussian used to blur the image. Larger sigma means more grid correction but stronger edge artifacts. (the default is 10, which empirically works well our data at 50 um)
mask : {SimpleITK.SimpleITK.Image}, optional
An image with 1s representing the foreground (brain) and 0s representing the background. (the default is None, which will use otsu thresholding to create the brain mask.)
Returns:

SimpleITK.SimpleITK.Image

Input image with grid artifact removed.