dipy logo

Site Navigation

NIPY Community

Previous topic

dipy.external.fsl

Next topic

dipy io

dipy.external.fsl

FSL IO

exception dipy.external.fsl.FSLError

Class signals error in FSL processing

dipy.external.fsl.flirt2aff(mat, in_img, ref_img)

Transform from in_img voxels to ref_img voxels given mat

Parameters :

mat : (4,4) array

contents (as array) of output -omat transformation file from flirt

in_img : img

image passed (as filename) to flirt as -in image

ref_img : img

image passed (as filename) to flirt as -ref image

Returns :

aff : (4,4) array

Transform from voxel coordinates in in_img to voxel coordinates in ref_img

Notes

Thanks to Mark Jenkinson and Jesper Andersson for the correct statements here, apologies for any errors we’ve added.

flirt registers an in image to a ref image. It can produce (with the -omat option) - a 4 x 4 affine matrix giving the mapping from inspace to refspace.

The rest of this note is to specify what inspace and refspace are.

In what follows, a voxtrans for an image is the 4 by 4 affine np.diag([vox_i, vox_j, vox_k, 1]) where vox_i etc are the voxel sizes for the first second and third voxel dimension. vox_i etc are always positive.

If the input image has an affine with a negative determinant, then the mapping from voxel coordinates in the input image to inspace is simply voxtrans for the input image. If the reference image has a negative determinant, the mapping from voxel space in the reference image to refspace is simply voxtrans for the reference image.

A negative determinant for the image affine is the common case, of an image with a x voxel flip. Analyze images don’t store affines and flirt assumes a negative determinant in these cases.

For positive determinant affines, flirt starts inspace and / or refspace with an x voxel flip. The mapping implied for an x voxel flip for image with shape (N_i, N_j, N_k) is:

[[-1, 0, 0, N_i - 1],
[ 0, 1, 0, 0], [ 0, 0, 1, 0], [ 0, 0, 0, 1]]

If the input image has an affine with a positive determinant, then mapping from input image voxel coordinates to inspace is np.dot(input_voxtrans, input_x_flip) - where input_x_flip is the matrix above with N_i given by the input image first axis length. Similarly the mapping from reference voxel coordinates to refspace, if the reference image has a positive determinant, is np.dot(ref_voxtrans, ref_x_flip) - where ref_x_flip is the matrix above with N_i given by the reference image first axis length.

dipy.external.fsl.flirt2aff_files(matfile, in_fname, ref_fname)

Map from in_fname image voxels to ref_fname voxels given matfile

See flirt2aff() docstring for details.

Parameters :

matfile : str

filename of output -omat transformation file from flirt

in_fname : str

filename for image passed to flirt as -in image

ref_fname : str

filename for image passed to flirt as -ref image

Returns :

aff : (4,4) array

Transform from voxel coordinates in image for in_fname to voxel coordinates in image for ref_fname

dipy.external.fsl.have_flirt()

Return True if we can call flirt without error

Relies on the fact that flirt produces text on stdout when called with no arguments

dipy.external.fsl.pipe(cmd)

A tine pipeline system to run external tools.

For more advanced pipelining use nipype http://www.nipy.org/nipype

dipy.external.fsl.run_flirt_imgs(in_img, ref_img, dof=6, flags='')

Run flirt on nibabel images, returning affine

Parameters :

in_img : `SpatialImage’

image to register

ref_img : SpatialImage

image to register to

dof : int, optional

degrees of freedom for registration (default 6)

flags : str, optional

other flags to pass to flirt command string

Returns :

in_vox2out_vox : (4,4) ndarray

affine such that, if [i, j, k] is a coordinate in voxels in the in_img, and [p, q, r] are the equivalent voxel coordinates in the reference image, then [p, q, r] = np.dot(in_vox2out_vox[:3,:3]), [i, j, k] + in_vox2out_vox[:3,3])

dipy.external.fsl.warp_displacements(ffa, flaff, fdis, fref, ffaw, order=1)

Warp an image using fsl displacements

Parameters :

ffa : filename of nifti to be warped

flaff : filename of .mat (flirt)

fdis : filename of displacements (fnirtfileutils)

fref : filename of reference volume e.g. (FMRIB58_FA_1mm.nii.gz)

ffaw : filename for the output warped image

dipy.external.fsl.warp_displacements_tracks(fdpy, ffa, fmat, finv, fdis, fdisa, fref, fdpyw)

Warp tracks from native space to the FMRIB58/MNI space

We use here the fsl displacements. Have a look at create_displacements to see an example of how to use these displacements.

Parameters :

fdpy : filename of the .dpy file with the tractography

ffa : filename of nifti to be warped

fmat : filename of .mat (flirt)

fdis : filename of displacements (fnirtfileutils)

fdisa : filename of displacements (fnirtfileutils + affine)

finv : filename of invwarp displacements (invwarp)

fref : filename of reference volume e.g. (FMRIB58_FA_1mm.nii.gz)

fdpyw : filename of the warped tractography

See also

dipy.external.fsl.create_displacements

dipy.external.fsl.write_bvals_bvecs(bvals, bvecs, outpath=None, prefix='')

Write FSL FDT bvals and bvecs files

Parameters :

bvals : (N,) sequence

Vector with diffusion gradient strength (one per diffusion acquisition, N=no of acquisitions)

bvecs : (N, 3) array-like

diffusion gradient directions

outpath : None or str

path to write FDT bvals, bvecs text files None results in current working directory.

prefix : str

prefix for bvals, bvecs files in directory. Defaults to ‘’