Menu

Helper Module for Deep Learning.

Common functions to spatialy normalize the data.

pynet.preprocessing.spatial.apply(im, target, affines, interp='spline', tmpdir=None)[source]

Apply affine transformations to an image.

This function is based on FSL.

Parameters

im: nibabel.Nifti1Image

the input image.

target: nibabel.Nifti1Image

the target image.

affines: str or list of str

the affine transforms to be applied. If multiple transforms are specified, they are first composed.

interp: str, default ‘spline’

Choose the most appropriate interpolation method: ‘trilinear’, ‘nearestneighbour’, ‘sinc’, ‘spline’.

tmpdir: str, default None

a folder where the intermediate results are saved.

Returns

normalized: nibabel.Nifti1Image

the normalized input image.

pynet.preprocessing.spatial.biasfield(im, mask=None, nb_iterations=50, convergence_threshold=0.001, bspline_grid=(1, 1, 1), shrink_factor=1, bspline_order=3, histogram_sharpening=(0.15, 0.01, 200), tmpdir=None)[source]

Perform MRI bias field correction using N4 algorithm.

This function is based on ITK and ANTS.

Parameters

im: nibabel.Nifti1Image

the input image.

mask: nibabel.Nifti1Image, default None

the brain mask image.

nb_iterations: int, default 50

Maximum number of iterations at each level of resolution. Larger values will increase execution time, but may lead to better results.

convergence_threshold: float, default 0.001

Stopping criterion for the iterative bias estimation. Larger values will lead to smaller execution time.

bspline_grid: int, default (1, 1, 1)

Resolution of the initial bspline grid defined as a sequence of three numbers. The actual resolution will be defined by adding the bspline order (default is 3) to the resolution in each dimension specified here. For example, 1,1,1 will result in a 4x4x4 grid of control points. This parameter may need to be adjusted based on your input image. In the multi-resolution N4 framework, the resolution of the bspline grid at subsequent iterations will be doubled. The number of resolutions is implicitly defined by Number of iterations parameter (the size of this list is the number of resolutions).

shrink_factor: int, default 1

Defines how much the image should be upsampled before estimating the inhomogeneity field. Increase if you want to reduce the execution time. 1 corresponds to the original resolution. Larger values will significantly reduce the computation time.

bspline_order: int, default 3

Order of B-spline used in the approximation. Larger values will lead to longer execution times, may result in overfitting and poor result.

histogram_sharpening: 3-uplate, default (0.15, 0.01, 200)

A vector of up to three values. Non-zero values correspond to Bias Field Full Width at Half Maximum, Wiener filter noise, and Number of histogram bins.

tmpdir: str, default None

a folder where the intermediate results are saved.

Returns

normalized: nibabel.Nifti1Image

the normalized input image.

pynet.preprocessing.spatial.check_command(command)[source]

Check if a command is installed.

This function is based on which.

Parameters

command: str

the name of the command to locate.

pynet.preprocessing.spatial.check_version(package_name)[source]

Check installed version of a package.

This function is based on dpkg.

Parameters

package_name: str

the name of the package we want to check the version.

pynet.preprocessing.spatial.downsample(arr, scale)[source]

Apply a downsampling.

Parameters

arr: array

the input data.

scale: int

the downsampling scale factor in all directions.

Returns

transformed: array

the transformed input data.

pynet.preprocessing.spatial.padd(arr, shape, fill_value=0)[source]

Apply a padding.

Parameters

arr: array

the input data.

shape: list of int

the desired shape.

fill_value: int, default 0

the value used to fill the array.

Returns

transformed: array

the transformed input data.

pynet.preprocessing.spatial.register(im, target, mask=None, cost='normmi', bins=256, interp='spline', dof=9, tmpdir=None)[source]

Register the MRI image to a target image using an affine transform with 9 dofs.

This function is based on FSL.

Parameters

im: nibabel.Nifti1Image

the input image.

target: nibabel.Nifti1Image

the target image.

mask: nibabel.Nifti1Image, default None

the white matter mask image needed by the bbr cost function.

cost: str, default ‘normmi’

Choose the most appropriate metric: ‘mutualinfo’, ‘corratio’, ‘normcorr’, ‘normmi’, ‘leastsq’, ‘labeldiff’, ‘bbr’.

bins: int, default 256

Number of histogram bins

interp: str, default ‘spline’

Choose the most appropriate interpolation method: ‘trilinear’, ‘nearestneighbour’, ‘sinc’, ‘spline’.

dof: int, default 9

Number of affine transform dofs.

tmpdir: str, default None

a folder where the intermediate results are saved.

Returns

normalized: nibabel.Nifti1Image

the normalized input image.

pynet.preprocessing.spatial.reorient2std(im, tmpdir=None)[source]

Reorient the MRI image to match the approximate orientation of the standard template images (MNI152).

This function is based on FSL.

Parameters

im: nibabel.Nifti1Image

the input image.

tmpdir: str, default None

a folder where the intermediate results are saved.

Returns

normalized: nibabel.Nifti1Image

the normalized input image.

pynet.preprocessing.spatial.scale(im, scale, tmpdir=None, interp='spline')[source]

Scale the MRI image.

This function is based on FSL.

Parameters

im: nibabel.Nifti1Image

the input image.

scale: int

the scale factor in all directions.

interp: str, default ‘spline’

Choose the most appropriate interpolation method: ‘trilinear’, ‘nearestneighbour’, ‘sinc’, ‘spline’.

tmpdir: str, default None

a folder where the intermediate results are saved.

Returns

normalized: nibabel.Nifti1Image

the normalized input image.

Follow us

© 2019, pynet developers .
Inspired by AZMIND template.