Recent Changes - Search:

Homepage

This is the old Camino website, please visit our new page to download the code and get the latest documentation.









UCL MIG Home

UCL CS Home

UCL Home

edit SideBar

MbalignTutorial

Tutorials.MbalignTutorial History

Hide minor edits - Show changes to markup

May 21, 2010, at 10:21 AM by shahrum - Reverted to original version.
Changed lines 1-220 from:

haier america trading l.l.c http://predphechi.angelfire.com/u.n.-invasion-of-america.html toto u.s. america washlet 2006 mr. america bodybuilding http://predphechi.angelfire.com/america-on-line.com.html sap america inc the downsizing of america http://predphechi.angelfire.com/www.miss-america.com.html www.htc america.com overdose america.co http://predphechi.angelfire.com/www.guns-america-.com.html grohe america inc bank of america myeasypayments.com http://predphechi.angelfire.com/air-america-2.0.html bond america.com www.at home america.net http://predphechi.angelfire.com/www.tyre-america.com.html www.america mall.com blanco america.com http://predphechi.angelfire.com/mid-america-distribution-st.-joseph.html infoplease.com native america history lead america.org http://predphechi.angelfire.com/naughty-america.com-vip.html olympus america.com america personals singles.com http://predphechi.angelfire.com/america-bancard.com.html miss america pageant.com america s tire co http://predphechi.angelfire.com/frito-lay-north-america-inc.html history america.com

to:

Tutorial: Motion Correction for Diffusion Weighted Images

This tutorial introduces the function mbalign in Camino, which is used to align the diffusion-weighted images within a single acquisition.

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/S32.gif

SYNOPSIS
mbalign [options]

1. Preparation before running mbalign

1.1.General data files and information

Before running mbalign, we need to have input and scheme files ready, and use

-inputfile <Input voxel-order file>
-schemefile <Scheme file name>

to specify in command options. If the input file is in scanner-order, we can use

-scanner -inputfile <Input scanner-order file>.

And also we need to make some other information of input image data clear and specify a few other options

-datadims X Y Z <Number of voxels in each dimension>
-voxeldims x y z <Voxel size in mm>
-sigma <Standard deviation of noise>

1.2.Sigma

The value of sigma is the approximate noise standard deviation. An estimate of sigma is sqrt(E(S^2)/2), where S is the signal in background and E denotes expectation over an ROI. The camino program, datastats, can work it out for you:

datastats -schemefile S.scheme -bgmask S32_BG.Bshort -inputfile S32.Bfloat

where S32_BG.Bshort is a binary image containing an ROI in a background region of the image.

The output looks like this:
=============================================================================================
Foreground voxel count: 142584
Component E(S) E(S^2) Var(S) Std(S)
1 2.882503E02 9.834995E04 1.526169E04 1.235382E02
2 3.010773E02 1.070645E05 1.641700E04 1.281288E02
3 2.876059E02 9.854322E04 1.582610E04 1.258018E02
4 2.564062E02 9.868863E04 1.294450E04 1.137739E02
5 2.017598E02 9.636593E04 1.028376E04 1.293741E02
6 2.915845E02 9.591012E04 1.817574E04 1.197654E02
:
:
:
==============================================================================================

A well chosen background region that genuinely contains no signal should show similar statistics in the output above in both non-diffusion-weighted (b=0) images and diffusion weighted images. The first four images in the example above have b=0 and the subsequent ones have b>0. We see little difference in the statistics, which suggests the background genuinely contains no signal.

The value of E(S^2) is around 1E5, so we might pick sigma = sqrt(E(S^2)/2), ie around 224.

However, you may need to play with the setting of sigma to get the best results out of mbalign. The value is somewhat artificial, because really we just seek a good threshold that reliably rejects measurements from corrupted images from contributing to the diffusion tensor fit. Several users have reported that they have to set sigma 100 or 1000 times smaller than the estimate of sigma described above to get good results. Others report having to set sigma much higher, so this seems to be data dependent.

1.3.Make slice to check input volume

This section shows a simple way to check the input volume is what the program expects and also to give you a fell for how much realignment is required. It creates an image volume containing the corresponding slice from each image volume in the data set.

If the image file is in voxel-order, we need to transfer it to scanner-order first:

voxel2scanner -voxels $((128*128*32)) -inputdatatype float -outputdatatype float -components 64 -inputfile S32.Bfloat > S32.scan.Bfloat

Then we can use camino function shredder to extract one slice from each of the 64 3D components, and build a 3D image shown in Fig1:

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/s32.fmr10_normmi.slice.check.jpg

Fig.1 An image volume containing 1 slices from each of the 64 component images in the data set.

Here is an example script for creating the image volume above:

COMPONENT=64
DATADIM_X=128
DATADIM_Y=128
DATADIM_Z=32

#Since our dataset used in the example is float, so
TYPESIZE=4

# Extract the middle slice
OFFSET=$(($DATADIM_X*$DATADIM_Y*$((DATADIM_Z/2))*$TYPESIZE))
shredder $OFFSET $(($DATADIM_X*$DATADIM_Y*$TYPESIZE)) $(($DATADIM_X*$DATADIM_Y*$(($DATADIM_Z-1))*$TYPESIZE)) < S32.scan.Bfloat > S32._SLICECHECK.img

# Make a header file VOXELDIM_X=1.88
VOXELDIM_Y=1.88
VOXELDIM_Z=2.0

analyzeheader -voxeldims $VOXELDIM_X $VOXELDIM_Y $VOXELDIM_Z -datadims $DATADIM_X $DATADIM_Y $COMPONENT -datatype float > S32._SLICECHECK.hdr

Now we can use visualisation tools, like MRIcro (Fig.2), to check the alignment of input data set.

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/s32_mircro.jpg

Fig.2 Using MRIcro to see slice volume

2. Run mbalign

2.1. Run mbalign simply

An example of using mbalign in the simplest way is: mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -inputfile S32.Bfloat then the screen output would be:
=============================================================================================
:-) I have everything I need!
WARNING: No -bgmask and -bgthresh input, using zero background threshold. Performance may improve with better threshold.
WARNING: No -components input. Using 64 components from schemefile. If wrong, restart with -components option.
64 components inside inputfile.
No temp directory specified. Trying to use /tmp/S32_17.03.08_180229.
Successfully created /tmp/S32_17.03.08_180229.
Linux system detected.
No output file name specified. Output file will be: /tmp/S32.out.Bfloat
Disk space temporarily used during calculation is about 2264924160. Make sure space is available!
==============================================================================================
The program will create a temporary directory used for calculation process. It can be either specified by -tmpdir or automatically create according to the file name and current time. We do not have to use -outputfile to specify the output file name, and the program can generate it according to the input file name, which is like the example shown above. To run mbalign, computer need to have registration software flirt(http://www.fmrib.ox.ac.uk/fsl/flirt/index.html) installed, which is part of FSL library(http://www.fmrib.ox.ac.uk/fsl/). We also need to specify the flirt direction by using -fsldir, but more easily, once we have camino and FSL installed, default value of variable DIR_FSL can be set which can be easily found inside mbalign. During the running of mbalign, there could be a lot of warning messages showing inside terminal window. Normally, just do not worry about it too much. Once the registration is complete, we may see the message shown below.
==============================================================================================
...
Registering ori.ScannerOrder.Bfloat.ck by using ref.ScannerOrder.Bfloat.ck
Registering ori.ScannerOrder.Bfloat.cl by using ref.ScannerOrder.Bfloat.cl
Transferring output to Big-endian format...
Making img and hdr files for slice checking...
Transfer output file to voxel-order...
Removing junk files...
Scheme file not updated.
Aligned data set output to /tmp/S32.out.Bfloat.
Program finished at
Mon Mar 24 23:36:24 GMT 2008
==============================================================================================
After program finishes, the temporary directory would be deleted (Removing junk files...), but we can still use -keepjunk to make it kept, which could be useful to help us to analyse the final output. Certainly, if the program is interrupted, this temporary fold will remain as junk files in computer. If we did not specify -outputfile, the program can generate it according to the input file name (Aligned data set output to /tmp/S32.out.Bfloat). We will discuss scheme file updating in Section 4.Update Gradient.

2.2. Run mbalign in an advanced way

Some other options mignt need to use: -flirtsearchcost <Search cost function used in flirt>
Default cost function is mutualinfo (Mutual Information). Other options are corratio,normcorr,normmi,leastsq. -flirttransform <Transformation used in flirt>
Default transformation is affine. The other option is rigid. -searchrange <angle>
Default is 90, which means search range is between -90 and 90 in all x, y and z directions. -eddy
Specifies registration for eddy-current induced distortion. -datatype <Data type for input and output files>
Default is float. -scanout <output scanner-order file>
Adds an extra output file in scanner-order. This won't stop default voxel-order output. -omat <File name>
Output transform matrix in ascii format. -slicecheck <File name>
Output a pair of <File name>.img and <File name>.hrd files. Default is no calculation.
When all the options are decided, we can run mbalign in an advanced way, such like mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -fsldir /cs/research/medim/common0/green/common/fsl/fslRH9/ -inputfile S32.Bfloat -slicecheck S32.fmr.slice.check -outputfile S32.fmr.Bfloat -omat S32.fmr.mat.txt -scanout S32.fmr.scanout.Bfloat -keepjunk -tmpdir tmp.fmr

3. Improve performance

There are a few options can be used to improve the performance of mbalign. -sigma
High sigma allows the program to involve more measurement in the DT fitting, and low sigma leads rejections during the DT fitting. Based on this theory, we can change the value of sigma to improve the reference making. -bgmask <Mask file>
Use a mask file can improve the quality of the reference images used in mbalign registration. And the data type of mask file should be "short". Camino function mask can help to create a background mask from a voxel-ordered DW data file by thresholding the average b=0 measurement. mask -inputfile S32.Bfloat -inputdatatype float -schemefile S.scheme -bgthresh 100 -outputdatatype short > S32_M100.Bshort

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/fa.s32.bdouble.jpg

Fig.3 View projection of FA map generated by camino

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/s32_m100.bshort.jpg

Fig.4 View projection of mask file generated by camino

We can also use matlab to make a mask file. -bgthresh <Background threshold>
Decide the value of threshold, and improve fitting the diffusion tensors. -searchrange <angle>
Sometimes, the pitch of histogram will cause the failure of registration. Simply narrow down the angle search range can cover this problem for most of the time.

4. Update Gradient

Updating diffusion gradients after registration is not an essential procedure, but can improve the registration result. Fig.5 explains the reason why diffusion gradients need to be updated after registration.

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/rotate_tif_c.png Fig.5 Illustration of how rotation affects the effective gradient direction. The arrows indicate gradient directions. (a) Head without rotation. Suppose the mouth is a fibre. The signal is high because the gradient is perpendicular to the fibre. (b) Head with rotation. The signal is lower in the mouth fibre. (c) The unrotated head (after registration). The effective gradient direction for the corrected image is rotated. We can use our matlab function to update diffusion gradient for registered data set, and the usage method is explained inside the matlab file. Since the transformations used in the registration contribute to the gradient updating, we MUST save the transform matrix when running mbalign, using -omat.

5. More hints

Quite a few default options can be change in the source code of mbalign. Make the default values to the ones most frequently used can make the everyday use of mbalign much simpler. Inside mbalign source code, we can find and change the default options from the following part.

####################################################
##### Change default variables to match system #####
####################################################
# Hint: To make your input arguments simple, set
# default input which you most often to use.
# FSL directory
DIR_FSL=/cs/research/medim/common0/green/common/fsl/fslRH9
# LIM_ROTATE is default for -searchrange
LIM_ROTATE=90
# Available cost functions are:
# mutualinfo corratio,normcorr,normmi,leastsq.
SEARCH_COST=mutualinfo
#Degree of freedom
# 12 for affine; 6 for rigid.
DOF=12

Acknowledgement

We would like to thank Geoff Parker and Karl Embleton, University of Manchester, for providing the brain data.

Reference

- Y. Bai and D. C. Alexander, “Model-Based Registration to Correct for Motion between Acquisitions in Diffusion MR Imaging”, The Fifth IEEE International Symposium on Biomedical Imaging ( ISBI 2008), May 2008.

May 16, 2010, at 06:04 PM by mr gay america - EFBEOkhgwnKSCrHx
Changed line 1 from:

SB7Bpg <a href="http://eobrqiurerih.com/">eobrqiurerih</a>, [url=http://sgtunkytfqev.com/]sgtunkytfqev[/url], [link=http://ayesnfbmznxj.com/]ayesnfbmznxj[/link], http://lubozxqctamy.com/

to:

haier america trading l.l.c http://predphechi.angelfire.com/u.n.-invasion-of-america.html toto u.s. america washlet 2006 mr. america bodybuilding http://predphechi.angelfire.com/america-on-line.com.html sap america inc the downsizing of america http://predphechi.angelfire.com/www.miss-america.com.html www.htc america.com overdose america.co http://predphechi.angelfire.com/www.guns-america-.com.html grohe america inc bank of america myeasypayments.com http://predphechi.angelfire.com/air-america-2.0.html bond america.com www.at home america.net http://predphechi.angelfire.com/www.tyre-america.com.html www.america mall.com blanco america.com http://predphechi.angelfire.com/mid-america-distribution-st.-joseph.html infoplease.com native america history lead america.org http://predphechi.angelfire.com/naughty-america.com-vip.html olympus america.com america personals singles.com http://predphechi.angelfire.com/america-bancard.com.html miss america pageant.com america s tire co http://predphechi.angelfire.com/frito-lay-north-america-inc.html history america.com

May 04, 2010, at 11:03 AM by ghcaoov - jbvjFBnbRRq
Changed lines 1-240 from:

Tutorial: Motion Correction for Diffusion Weighted Images

This tutorial introduces the function mbalign in Camino, which is used to align the diffusion-weighted images within a single acquisition. The program comes with a health warning: it is far from perfect. It can help to realign images, but we strongly recommend you check the output of the procedure to ensure it has made a genuine improvement. There are several tips below to help improve performance of the algorithm. Experience tells us that each data set requires different settings in mbalign to get it to work. Below is an example that worked on one sample data set, but you'll probably need to play with the settings to get it to work on yours.

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/S32.gif

SYNOPSIS
mbalign [options]

1. Preparation before running mbalign

1.1.General data files and information

Before running mbalign, we need to have input and scheme files ready, and use

-inputfile <Input voxel-order file>
-schemefile <Scheme file name>

to specify in command options. If the input file is in scanner-order, we can use

-scanner -inputfile <Input scanner-order file>.

And also we need to make some other information of input image data clear and specify a few other options

-datadims X Y Z <Number of voxels in each dimension>
-voxeldims x y z <Voxel size in mm>
-sigma <Standard deviation of noise>

1.2.Sigma

The value of sigma is the approximate noise standard deviation. An estimate of sigma is sqrt(E(S^2)/2), where S is the signal in background and E denotes expectation over an ROI. The camino program, datastats, can work it out for you:

datastats -schemefile S.scheme -bgmask S32_BG.Bshort -inputfile S32.Bfloat

where S32_BG.Bshort is a binary image containing an ROI in a background region of the image.

The output looks like this:
=============================================================================================
Foreground voxel count: 142584
Component E(S) E(S^2) Var(S) Std(S)
1 2.882503E02 9.834995E04 1.526169E04 1.235382E02
2 3.010773E02 1.070645E05 1.641700E04 1.281288E02
3 2.876059E02 9.854322E04 1.582610E04 1.258018E02
4 2.564062E02 9.868863E04 1.294450E04 1.137739E02
5 2.017598E02 9.636593E04 1.028376E04 1.293741E02
6 2.915845E02 9.591012E04 1.817574E04 1.197654E02
:
:
:
==============================================================================================

A well chosen background region that genuinely contains no signal should show similar statistics in the output above in both non-diffusion-weighted (b=0) images and diffusion weighted images. The first four images in the example above have b=0 and the subsequent ones have b>0. We see little difference in the statistics, which suggests the background genuinely contains no signal.

The value of E(S^2) is around 1E5, so we might pick sigma = sqrt(E(S^2)/2), ie around 224.

However, you may need to play with the setting of sigma to get the best results out of mbalign. The value is somewhat artificial, because really we just seek a good threshold that reliably rejects measurements from corrupted images from contributing to the diffusion tensor fit. Several users have reported that they have to set sigma 100 or 1000 times smaller than the estimate of sigma described above to get good results. Others report having to set sigma much higher, so this seems to be data dependent.

1.3.Make slice to check input volume

This section shows a simple way to check the input volume is what the program expects and also to give you a fell for how much realignment is required. It creates an image volume containing the corresponding slice from each image volume in the data set.

If the image file is in voxel-order, we need to transfer it to scanner-order first:

voxel2scanner -voxels $((128*128*32)) -inputdatatype float -outputdatatype float -components 64 -inputfile S32.Bfloat > S32.scan.Bfloat

Then we can use camino function shredder to extract one slice from each of the 64 3D components, and build a 3D image shown in Fig1:

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/s32.fmr10_normmi.slice.check.jpg

Fig.1 An image volume containing 1 slices from each of the 64 component images in the data set.

Here is an example script for creating the image volume above:

COMPONENT=64
DATADIM_X=128
DATADIM_Y=128
DATADIM_Z=32

#Since our dataset used in the example is float, so
TYPESIZE=4

# Extract the middle slice
OFFSET=$(($DATADIM_X*$DATADIM_Y*$((DATADIM_Z/2))*$TYPESIZE))
shredder $OFFSET $(($DATADIM_X*$DATADIM_Y*$TYPESIZE)) $(($DATADIM_X*$DATADIM_Y*$(($DATADIM_Z-1))*$TYPESIZE)) < S32.scan.Bfloat > S32._SLICECHECK.img

# Make a header file VOXELDIM_X=1.88
VOXELDIM_Y=1.88
VOXELDIM_Z=2.0

analyzeheader -voxeldims $VOXELDIM_X $VOXELDIM_Y $VOXELDIM_Z -datadims $DATADIM_X $DATADIM_Y $COMPONENT -datatype float > S32._SLICECHECK.hdr

Now we can use visualisation tools, like MRIcro (Fig.2), to check the alignment of input data set.

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/s32_mircro.jpg

Fig.2 Using MRIcro to see slice volume

2. Run mbalign

2.1. Run mbalign simply

An example of using mbalign in the simplest way is:
mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -inputfile S32.Bfloat
That outputs:
=============================================================================================
:-) I have everything I need!
WARNING: No -bgmask and -bgthresh input, using zero background threshold. Performance may improve with better threshold.
WARNING: No -components input. Using 64 components from schemefile. If wrong, restart with -components option.
64 components inside inputfile.
No temp directory specified. Trying to use /tmp/S32_17.03.08_180229.
Successfully created /tmp/S32_17.03.08_180229.
Linux system detected.
No output file name specified. Output file will be: /tmp/S32.out.Bfloat
Disk space temporarily used during calculation is about 2264924160. Make sure space is available!
==============================================================================================

The program will create a temporary directory used during processing. It can be either specified by -tmpdir or automatically created according to the file name and current time. We do not have to use -outputfile to specify the output file name, and the program can generate it according to the input file name, as in the example shown above.

To run mbalign, computer need to have registration software flirt(http://www.fmrib.ox.ac.uk/fsl/flirt/index.html) installed, which is part of FSL library(http://www.fmrib.ox.ac.uk/fsl/). We also need to specify the flirt directory by using -fsldir, but more easily, once we have camino and FSL installed, default value of variable DIR_FSL can be set inside the mbalign script.

During the running of mbalign, you may see a lot of warning messages showing inside terminal window. Normally, just do not worry about it too much. Once the registration is complete, you should see the message shown below.
==============================================================================================
...
Registering ori.ScannerOrder.Bfloat.ck by using ref.ScannerOrder.Bfloat.ck
Registering ori.ScannerOrder.Bfloat.cl by using ref.ScannerOrder.Bfloat.cl
Transferring output to Big-endian format...
Making img and hdr files for slice checking...
Transfer output file to voxel-order...
Removing junk files...
Scheme file not updated.
Aligned data set output to /tmp/S32.out.Bfloat.
Program finished at
Mon Mar 24 23:36:24 GMT 2008
==============================================================================================

After program finishes, the temporary directory should be deleted (Removing junk files...), but we can still use -keepjunk to prevent removal, which can be useful to help us analyse the final output. If the program is interrupted, this temporary folder will remain as junk files in computer and may need manual deletion.

If we did not specify -outputfile, the program can generate it according to the input file name (Aligned data set output to /tmp/S32.out.Bfloat).

After mbalign is complete, it is a good idea to repeat the procedure in section 1.3 to check the quality of the alignment. The registration does not always work and may do strange things to some component volumes, so manual checking is required. You may also find, as with any realignment procedure, that it does not improve the alignment. If the images were well aligned to begin with, you may want to stick with them rather than use the mbalign output.

2.2. Run mbalign in an advanced way

Some other options can be useful:

-flirtsearchcost <Search cost function used in flirt>
Default cost function is mutualinfo (Mutual Information). Other options are corratio,normcorr,normmi,leastsq.

-flirttransform <Transformation used in flirt>
Default transformation is affine. The other option is rigid.

-searchrange <angle>
Default is 90, which means search range is between -90 and 90 in all x, y and z directions.

-eddy
Specifies registration for eddy-current induced distortion.

-datatype <Data type for input and output files>
Default is float.

-scanout <output scanner-order file>
Adds an extra output file in scanner-order. This won't stop default voxel-order output.

-omat <File name>
Output transform matrix in ascii format.

-slicecheck <File name>
Output a pair of <File name>.img and <File name>.hrd files. Default is no calculation.

When all the options are decided, we can run mbalign in an advanced way, such like

mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -fsldir /cs/research/medim/common0/green/common/fsl/fslRH9/ -inputfile S32.Bfloat -slicecheck S32.fmr.slice.check -outputfile S32.fmr.Bfloat -omat S32.fmr.mat.txt -scanout S32.fmr.scanout.Bfloat -keepjunk -tmpdir tmp.fmr

3. Improving performance

There are a few options can be used to improve the performance of mbalign.

-sigma
High sigma allows the program to involve more measurement in the DT fitting, and low sigma leads rejections during the DT fitting. Based on this theory, we can change the value of sigma to improve the reference making, as discussed in section 1.2 above.

-bgmask <Mask file>
Use a mask file that specifies the brain region in the image usually improves the performance of the registration in mbalign and is strongly recommended. The data type of mask file should be "short". Camino function mask can help to create a background mask from a voxel-ordered DW data file by thresholding the average b=0 measurement, eg:
mask -inputfile S32.Bfloat -inputdatatype float -schemefile S.scheme -bgthresh 100 -outputdatatype short > S32_M100.Bshort

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/fa.s32.bdouble.jpg

Fig.3 View projection of FA map generated by camino

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/s32_m100.bshort.jpg

Fig.4 View projection of mask file generated by camino

We can also use matlab to make a mask file.

-bgthresh <Background threshold>
Decide the value of threshold, and improve fitting the diffusion tensors. This is an alternative to specifying the mask file as above and tells the program to threshold on the b=0 measurement directly.

-searchrange <angle>
Sometimes, the pitch of histogram will cause the failure of registration. Simply narrow down the angle search range can cover this problem for most of the time.

4. Update Gradient

Updating diffusion gradients after registration is not an essential procedure, but can improve the precision of subsequent processing. Fig.5 explains the reason why diffusion gradients need to be updated after registration.

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/rotate_tif_c.png Fig.5 Illustration of how rotation affects the effective gradient direction. The arrows indicate gradient directions. (a) Head without rotation. Suppose the mouth is a fibre. The signal is high because the gradient is perpendicular to the fibre. (b) Head with rotation. The signal is lower in the mouth fibre. (c) The unrotated head (after registration). The effective gradient direction for the corrected image is rotated.

We can use the matlab function to update diffusion gradient for registered data set, and the usage method is explained inside the matlab file. Since the transformations used in the registration contribute to the gradient updating, we MUST save the transform matrix when running mbalign, using -omat.

5. More hints

Quite a few default options can be changed in the source code of mbalign. Make the default values to the ones most frequently used can make the everyday use of mbalign much simpler. Inside mbalign source code, we can find and change the default options from the following part.

####################################################
##### Change default variables to match system #####
####################################################
# Hint: To make your input arguments simple, set
# default input which you most often to use.
# FSL directory
DIR_FSL=/cs/research/medim/common0/green/common/fsl/fslRH9
# LIM_ROTATE is default for -searchrange
LIM_ROTATE=90
# Available cost functions are:
# mutualinfo corratio,normcorr,normmi,leastsq.
SEARCH_COST=mutualinfo
#Degree of freedom
# 12 for affine; 6 for rigid.
DOF=12

Acknowledgement

We would like to thank Geoff Parker and Karl Embleton, University of Manchester, for providing the brain data.

Reference

- Y. Bai and D. C. Alexander, “Model-Based Registration to Correct for Motion between Acquisitions in Diffusion MR Imaging”, The Fifth IEEE International Symposium on Biomedical Imaging ( ISBI 2008), May 2008.

to:

SB7Bpg <a href="http://eobrqiurerih.com/">eobrqiurerih</a>, [url=http://sgtunkytfqev.com/]sgtunkytfqev[/url], [link=http://ayesnfbmznxj.com/]ayesnfbmznxj[/link], http://lubozxqctamy.com/

February 18, 2010, at 10:19 AM by Danny -
Changed lines 3-4 from:

This tutorial introduces the function mbalign in Camino, which is used to align the diffusion-weighted images within a single acquisition.

to:

This tutorial introduces the function mbalign in Camino, which is used to align the diffusion-weighted images within a single acquisition. The program comes with a health warning: it is far from perfect. It can help to realign images, but we strongly recommend you check the output of the procedure to ensure it has made a genuine improvement. There are several tips below to help improve performance of the algorithm. Experience tells us that each data set requires different settings in mbalign to get it to work. Below is an example that worked on one sample data set, but you'll probably need to play with the settings to get it to work on yours.

Changed lines 106-108 from:

An example of using mbalign in the simplest way is: mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -inputfile S32.Bfloat then the screen output would be: \\

to:

An example of using mbalign in the simplest way is:
mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -inputfile S32.Bfloat
That outputs: \\

Changed lines 120-124 from:

==============================================================================================
The program will create a temporary directory used for calculation process. It can be either specified by -tmpdir or automatically create according to the file name and current time. We do not have to use -outputfile to specify the output file name, and the program can generate it according to the input file name, which is like the example shown above. To run mbalign, computer need to have registration software flirt(http://www.fmrib.ox.ac.uk/fsl/flirt/index.html) installed, which is part of FSL library(http://www.fmrib.ox.ac.uk/fsl/). We also need to specify the flirt direction by using -fsldir, but more easily, once we have camino and FSL installed, default value of variable DIR_FSL can be set which can be easily found inside mbalign. During the running of mbalign, there could be a lot of warning messages showing inside terminal window. Normally, just do not worry about it too much. Once the registration is complete, we may see the message shown below.\\

to:

==============================================================================================

The program will create a temporary directory used during processing. It can be either specified by -tmpdir or automatically created according to the file name and current time. We do not have to use -outputfile to specify the output file name, and the program can generate it according to the input file name, as in the example shown above.

To run mbalign, computer need to have registration software flirt(http://www.fmrib.ox.ac.uk/fsl/flirt/index.html) installed, which is part of FSL library(http://www.fmrib.ox.ac.uk/fsl/). We also need to specify the flirt directory by using -fsldir, but more easily, once we have camino and FSL installed, default value of variable DIR_FSL can be set inside the mbalign script.

During the running of mbalign, you may see a lot of warning messages showing inside terminal window. Normally, just do not worry about it too much. Once the registration is complete, you should see the message shown below.\\

Changed lines 139-140 from:

==============================================================================================
After program finishes, the temporary directory would be deleted (Removing junk files...), but we can still use -keepjunk to make it kept, which could be useful to help us to analyse the final output. Certainly, if the program is interrupted, this temporary fold will remain as junk files in computer.

to:

==============================================================================================

After program finishes, the temporary directory should be deleted (Removing junk files...), but we can still use -keepjunk to prevent removal, which can be useful to help us analyse the final output. If the program is interrupted, this temporary folder will remain as junk files in computer and may need manual deletion.

Changed lines 144-145 from:

We will discuss scheme file updating in Section 4.Update Gradient.

to:

After mbalign is complete, it is a good idea to repeat the procedure in section 1.3 to check the quality of the alignment. The registration does not always work and may do strange things to some component volumes, so manual checking is required. You may also find, as with any realignment procedure, that it does not improve the alignment. If the images were well aligned to begin with, you may want to stick with them rather than use the mbalign output.

Changed lines 149-150 from:

Some other options mignt need to use:

to:

Some other options can be useful:

Added line 153:
Added line 156:
Added line 159:
Added line 162:
Added line 165:
Added line 168:
Added line 171:
Changed lines 173-174 from:

Output a pair of <File name>.img and <File name>.hrd files. Default is no calculation. \\

to:

Output a pair of <File name>.img and <File name>.hrd files. Default is no calculation.

Added line 176:
Changed lines 179-180 from:

3. Improve performance

to:

3. Improving performance

Added line 182:
Changed lines 184-185 from:

High sigma allows the program to involve more measurement in the DT fitting, and low sigma leads rejections during the DT fitting. Based on this theory, we can change the value of sigma to improve the reference making.

to:

High sigma allows the program to involve more measurement in the DT fitting, and low sigma leads rejections during the DT fitting. Based on this theory, we can change the value of sigma to improve the reference making, as discussed in section 1.2 above.

Changed lines 187-188 from:

Use a mask file can improve the quality of the reference images used in mbalign registration. And the data type of mask file should be "short". Camino function mask can help to create a background mask from a voxel-ordered DW data file by thresholding the average b=0 measurement.

to:

Use a mask file that specifies the brain region in the image usually improves the performance of the registration in mbalign and is strongly recommended. The data type of mask file should be "short". Camino function mask can help to create a background mask from a voxel-ordered DW data file by thresholding the average b=0 measurement, eg:\\

Added line 199:
Changed lines 201-202 from:

Decide the value of threshold, and improve fitting the diffusion tensors.

to:

Decide the value of threshold, and improve fitting the diffusion tensors. This is an alternative to specifying the mask file as above and tells the program to threshold on the b=0 measurement directly.

Changed line 207 from:

Updating diffusion gradients after registration is not an essential procedure, but can improve the registration result.

to:

Updating diffusion gradients after registration is not an essential procedure, but can improve the precision of subsequent processing.

Changed lines 212-213 from:

We can use our matlab function to update diffusion gradient for registered data set, and the usage method is explained inside the matlab file. Since the transformations used in the registration contribute to the gradient updating, we MUST save the transform matrix when running mbalign, using -omat.

to:

We can use the matlab function to update diffusion gradient for registered data set, and the usage method is explained inside the matlab file. Since the transformations used in the registration contribute to the gradient updating, we MUST save the transform matrix when running mbalign, using -omat.

Changed line 216 from:

Quite a few default options can be change in the source code of mbalign. Make the default values to the ones most frequently used can make the everyday use of mbalign much simpler. Inside mbalign source code, we can find and change the default options from the following part.

to:

Quite a few default options can be changed in the source code of mbalign. Make the default values to the ones most frequently used can make the everyday use of mbalign much simpler. Inside mbalign source code, we can find and change the default options from the following part.

February 18, 2010, at 10:05 AM by Danny -
Changed lines 61-62 from:

1.4.Make slice to check input volume

to:

1.3.Make slice to check input volume

This section shows a simple way to check the input volume is what the program expects and also to give you a fell for how much realignment is required. It creates an image volume containing the corresponding slice from each image volume in the data set.

Changed lines 69-70 from:

Then we can use camino function shredder to extract one slice from each of the 32 3D components, and build a 3D image shown in Fig1:

to:

Then we can use camino function shredder to extract one slice from each of the 64 3D components, and build a 3D image shown in Fig1:

Changed lines 73-74 from:

Fig.1 An image volume containing 32 slices from 64 diffusion components.

to:

Fig.1 An image volume containing 1 slices from each of the 64 component images in the data set.

Changed lines 77-78 from:

To make the command easy to read, we can use variables representing data information:

to:

Here is an example script for creating the image volume above:

Deleted line 79:
 \\
Changed lines 84-85 from:

Since our dataset used in the example is float, so

to:

#Since our dataset used in the example is float, so\\

Changed lines 87-92 from:

If we would like to extract the middle slice along z direction, we can set

OFFSET=$(($DATADIM_X*$DATADIM_Y*$((DATADIM_Z/2))*$TYPESIZE))

Then, calling shredder

to:

# Extract the middle slice
OFFSET=$(($DATADIM_X*$DATADIM_Y*$((DATADIM_Z/2))*$TYPESIZE))\\

Changed lines 91-92 from:

Make a header file (*.hdr) to make *.img file readable by many visualisation softwares:

to:

# Make a header file

Changed line 98 from:

Using some visualisation tools, such like MRIcro(Fig.2) and camino, we can check the slice motion of input data set.

to:

Now we can use visualisation tools, like MRIcro (Fig.2), to check the alignment of input data set.

February 18, 2010, at 09:51 AM by Danny -
Changed lines 3-4 from:

This tutorial gives a general introduction of using function mbalign in Camino package to align the diffusion-weighted images within a single acquisition.

to:

This tutorial introduces the function mbalign in Camino, which is used to align the diffusion-weighted images within a single acquisition.

Changed lines 31-39 from:

The sigma is approximate noise standard deviation. An estimate of sigma is sqrt(E(S^2)/2), where S is the signal in background and E denotes expectation over an ROI.

A camino program, datastats, can work it out for you as well.

datastats -schemefile S.scheme -bgmask S32_M100.Bshort -inputfile S32.Bfloat

where S32_M100.Bshort is a mask file for ROI (we will discuss more about generating mask in Section 3).

then the screen output would be: \\

to:

The value of sigma is the approximate noise standard deviation. An estimate of sigma is sqrt(E(S^2)/2), where S is the signal in background and E denotes expectation over an ROI. The camino program, datastats, can work it out for you:

datastats -schemefile S.scheme -bgmask S32_BG.Bshort -inputfile S32.Bfloat

where S32_BG.Bshort is a binary image containing an ROI in a background region of the image.

The output looks like this: \\

Changed lines 44-55 from:

4 2.564062E02 7.868863E04 1.294450E04 1.137739E02
5 7.893223E01 7.438512E03 1.208215E03 3.475939E01
6 7.813621E01 7.298962E03 1.193695E03 3.454989E01
7 8.115909E01 7.870362E03 1.283565E03 3.582688E01
8 7.870379E01 7.465566E03 1.271279E03 3.565500E01
9 8.104558E01 7.776110E03 1.207724E03 3.475232E01
10 8.053585E01 7.688916E03 1.202894E03 3.468276E01
11 8.019136E01 7.728569E03 1.297915E03 3.602659E01
12 7.751786E01 7.154714E03 1.145696E03 3.384814E01
13 8.196583E01 8.091765E03 1.373367E03 3.705897E01
14 7.725234E01 7.106027E03 1.138104E03 3.373580E01
15 8.016002E01 7.625693E03 1.200064E03 3.464194E01 \\

to:

4 2.564062E02 9.868863E04 1.294450E04 1.137739E02
5 2.017598E02 9.636593E04 1.028376E04 1.293741E02
6 2.915845E02 9.591012E04 1.817574E04 1.197654E02
:
:
:\\

Changed lines 52-55 from:

So we can choose 7.5 as the value of E(S^2). Then sigma, sqrt(E(S^2)/2), would be 1.9.

However, you may need to play with the value of sigma to get the best results out of mbalign. The value is somewhat artificial, because really we just seek a good setting that reliably rejects measurements from corrupted images from contributing to the diffusion tensor fit. Several users have reported that they have to set

to:

A well chosen background region that genuinely contains no signal should show similar statistics in the output above in both non-diffusion-weighted (b=0) images and diffusion weighted images. The first four images in the example above have b=0 and the subsequent ones have b>0. We see little difference in the statistics, which suggests the background genuinely contains no signal.

The value of E(S^2) is around 1E5, so we might pick sigma = sqrt(E(S^2)/2), ie around 224.

However, you may need to play with the setting of sigma to get the best results out of mbalign. The value is somewhat artificial, because really we just seek a good threshold that reliably rejects measurements from corrupted images from contributing to the diffusion tensor fit. Several users have reported that they have to set

February 18, 2010, at 09:40 AM by Danny -
Changed lines 209-225 from:

#################################################### \\ ##### Change default variables to match system ##### \\ #################################################### \\ # Hint: To make your input arguments simple, set \\ # default input which you most often to use. # FSL directory \\ DIR_FSL=/cs/research/medim/common0/green/common/fsl/fslRH9 # LIM_ROTATE is default for -searchrange \\ LIM_ROTATE=90 # Available cost functions are: \\ # mutualinfo corratio,normcorr,normmi,leastsq. \\ SEARCH_COST=mutualinfo #Degree of freedom \\ # 12 for affine; 6 for rigid. \\ DOF=12

to:

####################################################
##### Change default variables to match system #####
####################################################
# Hint: To make your input arguments simple, set
# default input which you most often to use.
# FSL directory
DIR_FSL=/cs/research/medim/common0/green/common/fsl/fslRH9
# LIM_ROTATE is default for -searchrange
LIM_ROTATE=90
# Available cost functions are:
# mutualinfo corratio,normcorr,normmi,leastsq.
SEARCH_COST=mutualinfo
#Degree of freedom
# 12 for affine; 6 for rigid.
DOF=12

February 18, 2010, at 09:39 AM by Danny -
Added line 209:

[=

Added line 225:

=]

February 18, 2010, at 09:36 AM by Danny -
Changed lines 204-206 from:

We can use our matlab function to update diffusion gradient for registered data set, and the usage method is explained inside the matlab file. Since the transformations used in the registration contribute to the gradient updating, we MUST save the transform matrix when running mbalign, using -omat.!! 5. More hints

to:

We can use our matlab function to update diffusion gradient for registered data set, and the usage method is explained inside the matlab file. Since the transformations used in the registration contribute to the gradient updating, we MUST save the transform matrix when running mbalign, using -omat.

5. More hints

Added line 208:
February 18, 2010, at 09:35 AM by Danny -
Added line 114:
Changed lines 150-153 from:

We will discuss scheme file updating in Section 4.Update Gradient.!!! 2.2. Run mbalign in an advanced way

to:

We will discuss scheme file updating in Section 4.Update Gradient.

2.2. Run mbalign in an advanced way

Changed lines 172-175 from:

mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -fsldir /cs/research/medim/common0/green/common/fsl/fslRH9/ -inputfile S32.Bfloat -slicecheck S32.fmr.slice.check -outputfile S32.fmr.Bfloat -omat S32.fmr.mat.txt -scanout S32.fmr.scanout.Bfloat -keepjunk -tmpdir tmp.fmr!! 3. Improve performance

to:

mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -fsldir /cs/research/medim/common0/green/common/fsl/fslRH9/ -inputfile S32.Bfloat -slicecheck S32.fmr.slice.check -outputfile S32.fmr.Bfloat -omat S32.fmr.mat.txt -scanout S32.fmr.scanout.Bfloat -keepjunk -tmpdir tmp.fmr

3. Improve performance

Added line 183:
Added line 185:
Added line 189:
Changed lines 196-198 from:

Sometimes, the pitch of histogram will cause the failure of registration. Simply narrow down the angle search range can cover this problem for most of the time.!! 4. Update Gradient

to:

Sometimes, the pitch of histogram will cause the failure of registration. Simply narrow down the angle search range can cover this problem for most of the time.

4. Update Gradient

February 18, 2010, at 09:31 AM by Danny -
Changed lines 208-209 from:

DOF=12!! Acknowledgement We would like to thank Geoff Parker and Karl Embleton, University of Manchester, for providing the brain data. \\

to:

DOF=12

Acknowledgement

We would like to thank Geoff Parker and Karl Embleton, University of Manchester, for providing the brain data.

February 18, 2010, at 09:30 AM by Danny -
Changed line 129 from:

==============================================================================================

to:

==============================================================================================\\

Changed line 133 from:

During the running of mbalign, there could be a lot of warning messages showing inside terminal window. Normally, just do not worry about it too much. Once the registration has got done, we may see the message shown below.

to:

During the running of mbalign, there could be a lot of warning messages showing inside terminal window. Normally, just do not worry about it too much. Once the registration is complete, we may see the message shown below.\\

Changed line 146 from:

==============================================================================================

to:

==============================================================================================\\

Changed lines 209-210 from:

We would like to thank Geoff Parker and Karl Embleton, University of Manchester, for providing the brain data. \\!! Reference

to:

We would like to thank Geoff Parker and Karl Embleton, University of Manchester, for providing the brain data.
!! Reference

February 18, 2010, at 09:27 AM by Danny -
Changed line 60 from:

So we can choose 7.5 as the value of E(S^2). Then sigma, sqrt(E(S^2)/2), would be 1.9. \\

to:

So we can choose 7.5 as the value of E(S^2). Then sigma, sqrt(E(S^2)/2), would be 1.9.

February 18, 2010, at 09:25 AM by Danny - Added sentence on setting sigma in mbalign.
Changed lines 31-32 from:

The sigma is approximate noise standard deviation. A suggested value is sqrt(E(S^2)/2), where S is the signal in background and E denotes expectation over an ROI.

to:

The sigma is approximate noise standard deviation. An estimate of sigma is sqrt(E(S^2)/2), where S is the signal in background and E denotes expectation over an ROI.

Added lines 61-65:

However, you may need to play with the value of sigma to get the best results out of mbalign. The value is somewhat artificial, because really we just seek a good setting that reliably rejects measurements from corrupted images from contributing to the diffusion tensor fit. Several users have reported that they have to set sigma 100 or 1000 times smaller than the estimate of sigma described above to get good results. Others report having to set sigma much higher, so this seems to be data dependent.\\

October 22, 2009, at 03:47 AM by shahrum -
Changed lines 5-6 from:

files/mbalign/S32.gif

to:

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/S32.gif

Changed lines 70-71 from:
 files/mbalign/s32.fmr10_normmi.slice.check.jpg
to:

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/s32.fmr10_normmi.slice.check.jpg

Changed lines 106-107 from:

files/mbalign/s32_mircro.jpg

to:

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/s32_mircro.jpg

Changed lines 109-110 from:

2. Run mbalign!!! 2.1. Run mbalign simply

to:

2. Run mbalign

2.1. Run mbalign simply

Changed line 112 from:

mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -inputfile S32.Bfloat

to:

mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -inputfile S32.Bfloat

Changed lines 171-172 from:

files/mbalign/fa.s32.bdouble.jpg

to:

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/fa.s32.bdouble.jpg

Changed lines 173-174 from:

files/mbalign/s32_m100.bshort.jpg

to:

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/s32_m100.bshort.jpg

Added line 176:
Changed lines 184-185 from:

files/mbalign/rotate_tif_c.png

to:

http://www.cs.ucl.ac.uk/research/medic/camino/tutorials/files/mbalign/rotate_tif_c.png

September 04, 2009, at 04:54 PM by shahrum -
August 31, 2009, at 01:03 AM by shahrum -
Changed lines 1-3 from:

Tutorial: Spatial normalization using flirt with diffusion tensor reorientation

This case study shows how to combine FSL's flirt program with Camino's tensor reorientation (using the preservation of principal directions (PPD) algorithm from Alexander et al, IEEE Trans. Medical Imaging 20(11) 1131-1139 2001) to perform spatial normalization of diffusion tensor images. Specifically, we will align two diffusion tensor images from different subjects. \\

to:

Tutorial: Motion Correction for Diffusion Weighted Images

This tutorial gives a general introduction of using function mbalign in Camino package to align the diffusion-weighted images within a single acquisition.

files/mbalign/S32.gif

SYNOPSIS
mbalign [options]

1. Preparation before running mbalign

1.1.General data files and information

Before running mbalign, we need to have input and scheme files ready, and use

-inputfile <Input voxel-order file>
-schemefile <Scheme file name>

to specify in command options. If the input file is in scanner-order, we can use

-scanner -inputfile <Input scanner-order file>.

And also we need to make some other information of input image data clear and specify a few other options

-datadims X Y Z <Number of voxels in each dimension>
-voxeldims x y z <Voxel size in mm>
-sigma <Standard deviation of noise>

1.2.Sigma

The sigma is approximate noise standard deviation. A suggested value is sqrt(E(S^2)/2), where S is the signal in background and E denotes expectation over an ROI.

A camino program, datastats, can work it out for you as well.

datastats -schemefile S.scheme -bgmask S32_M100.Bshort -inputfile S32.Bfloat

where S32_M100.Bshort is a mask file for ROI (we will discuss more about generating mask in Section 3).

then the screen output would be:
=============================================================================================
Foreground voxel count: 142584
Component E(S) E(S^2) Var(S) Std(S)
1 2.882503E02 9.834995E04 1.526169E04 1.235382E02
2 3.010773E02 1.070645E05 1.641700E04 1.281288E02
3 2.876059E02 9.854322E04 1.582610E04 1.258018E02
4 2.564062E02 7.868863E04 1.294450E04 1.137739E02
5 7.893223E01 7.438512E03 1.208215E03 3.475939E01
6 7.813621E01 7.298962E03 1.193695E03 3.454989E01
7 8.115909E01 7.870362E03 1.283565E03 3.582688E01
8 7.870379E01 7.465566E03 1.271279E03 3.565500E01
9 8.104558E01 7.776110E03 1.207724E03 3.475232E01
10 8.053585E01 7.688916E03 1.202894E03 3.468276E01
11 8.019136E01 7.728569E03 1.297915E03 3.602659E01
12 7.751786E01 7.154714E03 1.145696E03 3.384814E01
13 8.196583E01 8.091765E03 1.373367E03 3.705897E01
14 7.725234E01 7.106027E03 1.138104E03 3.373580E01
15 8.016002E01 7.625693E03 1.200064E03 3.464194E01
==============================================================================================

So we can choose 7.5 as the value of E(S^2). Then sigma, sqrt(E(S^2)/2), would be 1.9.

1.4.Make slice to check input volume

If the image file is in voxel-order, we need to transfer it to scanner-order first:

voxel2scanner -voxels $((128*128*32)) -inputdatatype float -outputdatatype float -components 64 -inputfile S32.Bfloat > S32.scan.Bfloat

Then we can use camino function shredder to extract one slice from each of the 32 3D components, and build a 3D image shown in Fig1:

 files/mbalign/s32.fmr10_normmi.slice.check.jpg

Fig.1 An image volume containing 32 slices from 64 diffusion components.

To make the command easy to read, we can use variables representing data information:

COMPONENT=64 \\

Changed lines 80-134 from:

Make sure camino/bin and fsl/bin are in your PATH.

The files Control1.Bfloat and Control3.Bfloat contain the raw diffusion-weighted image data in voxel order. (See the camino man page or the Pig Brain tutorial? for details on standard camino data formats and how to create them.) First, we shall create background masks for the two images and then use them to create masked diffusion tensor volumes.

We shall make background masks using FSL's Brain Extraction Tool (BET). We'll run BET on a single unweighted (b=0) image from each subject. We need analyze format images to input to FSL programs, which the commands below create from the raw camino format data files:

shredder 0 4 $((4*65)) < Control1.Bfloat > Control1_B0.img \\ shredder 0 4 $((4*65)) < Control3.Bfloat > Control3_B0.img \\ analyzeheader -voxeldims 1.7 1.7 2.5 -datadims 128 128 60 -datatype float > Control3_B0.hdr \\ analyzeheader -voxeldims 1.7 1.7 2.5 -datadims 128 128 60 -datatype float > Control1_B0.hdr \\

The shredder commands pull out the first measurements in each voxel, which is a b=0 measurement. Analyze format images consist of a raw data file with name ending .img and a header file with name ending .hdr. The output of the shredder commands provides the raw data files. The camino command analyzeheader creates appropriate headers. Now we can use BET to create background masks for each subject:

bet2 Control1_B0 Control1 -m \\ bet2 Control3_B0 Control3 -m \\ shredder 0 -2 0 < Control1_mask.img > Control1_Mask.Bshort \\ shredder 0 -2 0 < Control3_mask.img > Control3_Mask.Bshort

The bet2 commands output analyze format files containing one in the foreground portion and zero in the background portion of the image. These mask files store the value in each voxel as a short integer and bet2 outputs data with the native byte ordering. On linux the native byte ordering is little endian, so we need to switch to big endian for camino, which is what the shredder commands above do. Now we can use these masks while fitting the diffusion tensor to obtain masked diffusion tensor volumes for each subject:

modelfit -inputfile Control1.Bfloat -inversion 1 -schemefile ION54_6_6_NX.scheme -bgmask Control1_Mask.Bshort > Control1_DT.Bdouble \\ modelfit -inputfile Control3.Bfloat -inversion 1 -schemefile ION54_6_6_NX.scheme -bgmask Control3_Mask.Bshort > Control3_DT.Bdouble

It is worth checking at this stage that all the principal directions are defined in the same reference frame as the image. Having them in a different reference frame is a common error when handling diffusion MRI data and can lead to unexpectedly poor results. The tractography tutorial? discusses this issue in a bit more detail. Briefly though, running this command:

dteig < Control1_DT.Bdouble | dtpdview -datadims 128 128 60

Should give a result that looks something like this in the axial plane:

files/spatnorm/dtpdview_cc.png


with all the principal directions nicely aligned with the direction of the corpus callosum. It is worth checking the coronal and sagittal planes too.

To compute the transformation between the two subjects' images, we shall register fractional anisotropy maps from each. First we create fractional anisotropy images in analyze format:

fa < Control1_DT.Bdouble > Control1_FA.Bdouble \\ mv Control1_FA.Bdouble Control1_FA.img \\ fa < Control3_DT.Bdouble > Control3_FA.Bdouble \\ mv Control3_FA.Bdouble Control3_FA.img \\ analyzeheader -voxeldims 1.7 1.7 2.5 -datadims 128 128 60 -datatype double > Control1_FA.hdr \\ analyzeheader -voxeldims 1.7 1.7 2.5 -datadims 128 128 60 -datatype double > Control3_FA.hdr

Now do the registration using flirt:

flirt -in Control1_FA.img -ref Control3_FA.img -out Control1_FA_SN.img -omat C1C3_Affine.txt

The flirt program writes the output to the text file C1C3_Affine.txt. It looks like this:

cat C1C3_Affine.txt \\ 1.0437 0.0346392 -0.0321966 -8.56335 \\ -0.0288245 1.0066 0.151991 -3.35788 \\ 0.048813 -0.211909 0.960858 18.6044 0 0 0 1

Now we have the transformation, we can transform the tensor image. We'll do it component by component using the flirt program. Here are some shell commands to separate the eight components of the tensor image, convert them to analyze format and warp them using flirt:

for ((i=0; i<8; i=i+1)); do \\ \\ # Create volume of i-th component \\ shredder $((i*8)) 8 56 < Control1_DT.Bdouble > Control1_DT_Comp${i}.img \\ analyzeheader -voxeldims 1.7 1.7 2.5 -datadims 128 128 60 -datatype double > Control1_DT_Comp${i}.hdr \\ # Transform. Note that the first component contains exit codes, so \\ # must be transformed using nearest neighbour interpolation. \\ if [ $i == 0 ]; then \\ flirt -in Control1_DT_Comp${i}.img -applyxfm -init C1C3_Affine.txt -out Control1_DT_Comp${i}_SN.img -ref Control3_FA.img -interp nearestneighbour \\ else \\ flirt -in /tmp/Control1_DT_Comp${i}.img -applyxfm -init C1C3_Affine.txt -out Control1_DT_Comp${i}_SN.img -ref Control3_FA.img \\ fi \\ \\ done

The shredder command extracts the i-th component volume. Note that we use nearest-neighbour interpolation for the first component, which contains integer-valued exit codes and trilinear interpolation for all the other components that contain real values.

Now we can recombine the warped component images into a single DT file in camino format. On a linux machine, flirt outputs results with little-endian byte ordering, which we need to reverse, as camino assumes big-endian byte ordering.

cat Control1_DT_Comp?_SN.img | shredder 0 -8 0 | scanner2voxel -voxels 983040 -components 8 -inputdatatype double -outputdatatype double > Control1_DT_SNNR.Bdouble \\

Finally, we reorient the tensors using PPD:

reorient -trans C1C3_Affine.txt < Control1_DT_SNNR.Bdouble > Control1_DT_SNPPD.Bdouble \\

Note that reorient will also work with non-linear warps produced by FSL's non-linear registration program fnirt. See the reorient man page for details.
\\

to:

DATADIM_X=128
DATADIM_Y=128
DATADIM_Z=32

Since our dataset used in the example is float, so

TYPESIZE=4

If we would like to extract the middle slice along z direction, we can set

OFFSET=$(($DATADIM_X*$DATADIM_Y*$((DATADIM_Z/2))*$TYPESIZE))

Then, calling shredder

shredder $OFFSET $(($DATADIM_X*$DATADIM_Y*$TYPESIZE)) $(($DATADIM_X*$DATADIM_Y*$(($DATADIM_Z-1))*$TYPESIZE)) < S32.scan.Bfloat > S32._SLICECHECK.img

Make a header file (*.hdr) to make *.img file readable by many visualisation softwares:

VOXELDIM_X=1.88
VOXELDIM_Y=1.88
VOXELDIM_Z=2.0

analyzeheader -voxeldims $VOXELDIM_X $VOXELDIM_Y $VOXELDIM_Z -datadims $DATADIM_X $DATADIM_Y $COMPONENT -datatype float > S32._SLICECHECK.hdr

Using some visualisation tools, such like MRIcro(Fig.2) and camino, we can check the slice motion of input data set.

files/mbalign/s32_mircro.jpg

Fig.2 Using MRIcro to see slice volume

2. Run mbalign!!! 2.1. Run mbalign simply

An example of using mbalign in the simplest way is: mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -inputfile S32.Bfloat then the screen output would be:
=============================================================================================
:-) I have everything I need!
WARNING: No -bgmask and -bgthresh input, using zero background threshold. Performance may improve with better threshold.
WARNING: No -components input. Using 64 components from schemefile. If wrong, restart with -components option.
64 components inside inputfile.
No temp directory specified. Trying to use /tmp/S32_17.03.08_180229.
Successfully created /tmp/S32_17.03.08_180229.
Linux system detected.
No output file name specified. Output file will be: /tmp/S32.out.Bfloat
Disk space temporarily used during calculation is about 2264924160. Make sure space is available!
============================================================================================== The program will create a temporary directory used for calculation process. It can be either specified by -tmpdir or automatically create according to the file name and current time. We do not have to use -outputfile to specify the output file name, and the program can generate it according to the input file name, which is like the example shown above. To run mbalign, computer need to have registration software flirt(http://www.fmrib.ox.ac.uk/fsl/flirt/index.html) installed, which is part of FSL library(http://www.fmrib.ox.ac.uk/fsl/). We also need to specify the flirt direction by using -fsldir, but more easily, once we have camino and FSL installed, default value of variable DIR_FSL can be set which can be easily found inside mbalign. During the running of mbalign, there could be a lot of warning messages showing inside terminal window. Normally, just do not worry about it too much. Once the registration has got done, we may see the message shown below. ==============================================================================================
...
Registering ori.ScannerOrder.Bfloat.ck by using ref.ScannerOrder.Bfloat.ck
Registering ori.ScannerOrder.Bfloat.cl by using ref.ScannerOrder.Bfloat.cl
Transferring output to Big-endian format...
Making img and hdr files for slice checking...
Transfer output file to voxel-order...
Removing junk files...
Scheme file not updated.
Aligned data set output to /tmp/S32.out.Bfloat.
Program finished at
Mon Mar 24 23:36:24 GMT 2008
============================================================================================== After program finishes, the temporary directory would be deleted (Removing junk files...), but we can still use -keepjunk to make it kept, which could be useful to help us to analyse the final output. Certainly, if the program is interrupted, this temporary fold will remain as junk files in computer. If we did not specify -outputfile, the program can generate it according to the input file name (Aligned data set output to /tmp/S32.out.Bfloat). We will discuss scheme file updating in Section 4.Update Gradient.!!! 2.2. Run mbalign in an advanced way Some other options mignt need to use: -flirtsearchcost <Search cost function used in flirt>
Default cost function is mutualinfo (Mutual Information). Other options are corratio,normcorr,normmi,leastsq. -flirttransform <Transformation used in flirt>
Default transformation is affine. The other option is rigid. -searchrange <angle>
Default is 90, which means search range is between -90 and 90 in all x, y and z directions. -eddy
Specifies registration for eddy-current induced distortion. -datatype <Data type for input and output files>
Default is float. -scanout <output scanner-order file>
Adds an extra output file in scanner-order. This won't stop default voxel-order output. -omat <File name>
Output transform matrix in ascii format. -slicecheck <File name>
Output a pair of <File name>.img and <File name>.hrd files. Default is no calculation.
When all the options are decided, we can run mbalign in an advanced way, such like mbalign -datatype float -schemefile S.scheme -datadims 128 128 60 -voxeldims 1.88 1.88 2.0 -sigma 1.9 -fsldir /cs/research/medim/common0/green/common/fsl/fslRH9/ -inputfile S32.Bfloat -slicecheck S32.fmr.slice.check -outputfile S32.fmr.Bfloat -omat S32.fmr.mat.txt -scanout S32.fmr.scanout.Bfloat -keepjunk -tmpdir tmp.fmr!! 3. Improve performance There are a few options can be used to improve the performance of mbalign. -sigma
High sigma allows the program to involve more measurement in the DT fitting, and low sigma leads rejections during the DT fitting. Based on this theory, we can change the value of sigma to improve the reference making. -bgmask <Mask file>
Use a mask file can improve the quality of the reference images used in mbalign registration. And the data type of mask file should be "short". Camino function mask can help to create a background mask from a voxel-ordered DW data file by thresholding the average b=0 measurement. mask -inputfile S32.Bfloat -inputdatatype float -schemefile S.scheme -bgthresh 100 -outputdatatype short > S32_M100.Bshort files/mbalign/fa.s32.bdouble.jpg

Fig.3 View projection of FA map generated by camino files/mbalign/s32_m100.bshort.jpg

Fig.4 View projection of mask file generated by camino We can also use matlab to make a mask file. -bgthresh <Background threshold>
Decide the value of threshold, and improve fitting the diffusion tensors. -searchrange <angle>
Sometimes, the pitch of histogram will cause the failure of registration. Simply narrow down the angle search range can cover this problem for most of the time.!! 4. Update Gradient Updating diffusion gradients after registration is not an essential procedure, but can improve the registration result. Fig.5 explains the reason why diffusion gradients need to be updated after registration. files/mbalign/rotate_tif_c.png

Fig.5 Illustration of how rotation affects the effective gradient direction. The arrows indicate gradient directions. (a) Head without rotation. Suppose the mouth is a fibre. The signal is high because the gradient is perpendicular to the fibre. (b) Head with rotation. The signal is lower in the mouth fibre. (c) The unrotated head (after registration). The effective gradient direction for the corrected image is rotated. We can use our matlab function to update diffusion gradient for registered data set, and the usage method is explained inside the matlab file. Since the transformations used in the registration contribute to the gradient updating, we MUST save the transform matrix when running mbalign, using -omat.!! 5. More hints Quite a few default options can be change in the source code of mbalign. Make the default values to the ones most frequently used can make the everyday use of mbalign much simpler. Inside mbalign source code, we can find and change the default options from the following part.


  1. ##### Change default variables to match system #####
    ####################################################
    # Hint: To make your input arguments simple, set
    # default input which you most often to use.
  1. FSL directory
    DIR_FSL=/cs/research/medim/common0/green/common/fsl/fslRH9
  2. LIM_ROTATE is default for -searchrange
    LIM_ROTATE=90
  3. Available cost functions are:
    # mutualinfo corratio,normcorr,normmi,leastsq.
    SEARCH_COST=mutualinfo
  4. Degree of freedom
    # 12 for affine; 6 for rigid.
    DOF=12!! Acknowledgement

We would like to thank Geoff Parker and Karl Embleton, University of Manchester, for providing the brain data. \\!! Reference - Y. Bai and D. C. Alexander, “Model-Based Registration to Correct for Motion between Acquisitions in Diffusion MR Imaging”, The Fifth IEEE International Symposium on Biomedical Imaging ( ISBI 2008), May 2008.

August 31, 2009, at 01:02 AM by shahrum -
Added lines 1-59:

Tutorial: Spatial normalization using flirt with diffusion tensor reorientation

This case study shows how to combine FSL's flirt program with Camino's tensor reorientation (using the preservation of principal directions (PPD) algorithm from Alexander et al, IEEE Trans. Medical Imaging 20(11) 1131-1139 2001) to perform spatial normalization of diffusion tensor images. Specifically, we will align two diffusion tensor images from different subjects.

Make sure camino/bin and fsl/bin are in your PATH.

The files Control1.Bfloat and Control3.Bfloat contain the raw diffusion-weighted image data in voxel order. (See the camino man page or the Pig Brain tutorial? for details on standard camino data formats and how to create them.) First, we shall create background masks for the two images and then use them to create masked diffusion tensor volumes.

We shall make background masks using FSL's Brain Extraction Tool (BET). We'll run BET on a single unweighted (b=0) image from each subject. We need analyze format images to input to FSL programs, which the commands below create from the raw camino format data files:

shredder 0 4 $((4*65)) < Control1.Bfloat > Control1_B0.img \\ shredder 0 4 $((4*65)) < Control3.Bfloat > Control3_B0.img \\ analyzeheader -voxeldims 1.7 1.7 2.5 -datadims 128 128 60 -datatype float > Control3_B0.hdr \\ analyzeheader -voxeldims 1.7 1.7 2.5 -datadims 128 128 60 -datatype float > Control1_B0.hdr \\

The shredder commands pull out the first measurements in each voxel, which is a b=0 measurement. Analyze format images consist of a raw data file with name ending .img and a header file with name ending .hdr. The output of the shredder commands provides the raw data files. The camino command analyzeheader creates appropriate headers. Now we can use BET to create background masks for each subject:

bet2 Control1_B0 Control1 -m \\ bet2 Control3_B0 Control3 -m \\ shredder 0 -2 0 < Control1_mask.img > Control1_Mask.Bshort \\ shredder 0 -2 0 < Control3_mask.img > Control3_Mask.Bshort

The bet2 commands output analyze format files containing one in the foreground portion and zero in the background portion of the image. These mask files store the value in each voxel as a short integer and bet2 outputs data with the native byte ordering. On linux the native byte ordering is little endian, so we need to switch to big endian for camino, which is what the shredder commands above do. Now we can use these masks while fitting the diffusion tensor to obtain masked diffusion tensor volumes for each subject:

modelfit -inputfile Control1.Bfloat -inversion 1 -schemefile ION54_6_6_NX.scheme -bgmask Control1_Mask.Bshort > Control1_DT.Bdouble \\ modelfit -inputfile Control3.Bfloat -inversion 1 -schemefile ION54_6_6_NX.scheme -bgmask Control3_Mask.Bshort > Control3_DT.Bdouble

It is worth checking at this stage that all the principal directions are defined in the same reference frame as the image. Having them in a different reference frame is a common error when handling diffusion MRI data and can lead to unexpectedly poor results. The tractography tutorial? discusses this issue in a bit more detail. Briefly though, running this command:

dteig < Control1_DT.Bdouble | dtpdview -datadims 128 128 60

Should give a result that looks something like this in the axial plane:

files/spatnorm/dtpdview_cc.png


with all the principal directions nicely aligned with the direction of the corpus callosum. It is worth checking the coronal and sagittal planes too.

To compute the transformation between the two subjects' images, we shall register fractional anisotropy maps from each. First we create fractional anisotropy images in analyze format:

fa < Control1_DT.Bdouble > Control1_FA.Bdouble \\ mv Control1_FA.Bdouble Control1_FA.img \\ fa < Control3_DT.Bdouble > Control3_FA.Bdouble \\ mv Control3_FA.Bdouble Control3_FA.img \\ analyzeheader -voxeldims 1.7 1.7 2.5 -datadims 128 128 60 -datatype double > Control1_FA.hdr \\ analyzeheader -voxeldims 1.7 1.7 2.5 -datadims 128 128 60 -datatype double > Control3_FA.hdr

Now do the registration using flirt:

flirt -in Control1_FA.img -ref Control3_FA.img -out Control1_FA_SN.img -omat C1C3_Affine.txt

The flirt program writes the output to the text file C1C3_Affine.txt. It looks like this:

cat C1C3_Affine.txt \\ 1.0437 0.0346392 -0.0321966 -8.56335 \\ -0.0288245 1.0066 0.151991 -3.35788 \\ 0.048813 -0.211909 0.960858 18.6044 0 0 0 1

Now we have the transformation, we can transform the tensor image. We'll do it component by component using the flirt program. Here are some shell commands to separate the eight components of the tensor image, convert them to analyze format and warp them using flirt:

for ((i=0; i<8; i=i+1)); do \\ \\ # Create volume of i-th component \\ shredder $((i*8)) 8 56 < Control1_DT.Bdouble > Control1_DT_Comp${i}.img \\ analyzeheader -voxeldims 1.7 1.7 2.5 -datadims 128 128 60 -datatype double > Control1_DT_Comp${i}.hdr \\ # Transform. Note that the first component contains exit codes, so \\ # must be transformed using nearest neighbour interpolation. \\ if [ $i == 0 ]; then \\ flirt -in Control1_DT_Comp${i}.img -applyxfm -init C1C3_Affine.txt -out Control1_DT_Comp${i}_SN.img -ref Control3_FA.img -interp nearestneighbour \\ else \\ flirt -in /tmp/Control1_DT_Comp${i}.img -applyxfm -init C1C3_Affine.txt -out Control1_DT_Comp${i}_SN.img -ref Control3_FA.img \\ fi \\ \\ done

The shredder command extracts the i-th component volume. Note that we use nearest-neighbour interpolation for the first component, which contains integer-valued exit codes and trilinear interpolation for all the other components that contain real values.

Now we can recombine the warped component images into a single DT file in camino format. On a linux machine, flirt outputs results with little-endian byte ordering, which we need to reverse, as camino assumes big-endian byte ordering.

cat Control1_DT_Comp?_SN.img | shredder 0 -8 0 | scanner2voxel -voxels 983040 -components 8 -inputdatatype double -outputdatatype double > Control1_DT_SNNR.Bdouble \\

Finally, we reorient the tensors using PPD:

reorient -trans C1C3_Affine.txt < Control1_DT_SNNR.Bdouble > Control1_DT_SNPPD.Bdouble \\

Note that reorient will also work with non-linear warps produced by FSL's non-linear registration program fnirt. See the reorient man page for details.
\\

Edit - History - Print - Recent Changes - Search
Page last modified on May 21, 2010, at 10:21 AM