<html><head></head><body style="word-wrap: break-word; font-family: times new roman,new york,times,serif; font-size: 12pt;">Hi,<br><br>I seem to have found a bug in FNIRT, FSL's non-linear alignment tool. For some reason it does not save the affine transformation if a non-linear initial warp (inwarp) is used to initalize FNIRT. You can test this easily by running the following commands (<5min). The error does not come up on a CentOS system with the newest build, non-neurodebian). So it might have been fixed in some newer version (FNIRT build 419).<br><br>I checked the same commands on neurodebian ubuntu lucid and latest-version locally compiled CentOS, and they produce different results, if I'm not mistaken. Please check whether you can reproduce the bug with the following commands.<br><br>Thanks,<br>Jan<br><br><br>System:<br>Ubuntu Lucid<br>Linux 2.6.32-29-generic #58-Ubuntu SMP Fri Feb 11 20:52:10 UTC 2011 x86_64 GNU/Linux<br>$ fnirt<br>Part of FSL (build 418)<br>fsl 4.1.8<br><br><br><font size="2"><span style="font-family: courier new,monaco,monospace,sans-serif;"># The bug strikes on a ubuntu lucid machine and a freshly installed ubuntu lucid virtual machine. So I'm fairly sure it's not just one particular system that is affected. I tested this only on a mouse brain, so there's a slight chance the bug does not happen with "normal"-sized brains.</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;"># To test whether there is a bug take any random_image, preferably brain-extracted with some empty space around</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;"># This is going to be the new reference</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;">imcp random_image.nii.gz ref</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;"># let's move it by a perceptible amount. I created this matrix for a mouse brain, you might need larger translations for human brains</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;">printf "0.984808  0  -0.173648  0.828463\n0  1  0  -1\n0.173648  0  0.984808  -0.51938\n0  0  0  1\n" >> aff_orig.mat</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;"># the moved image is our input image</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;">flirt -in ref -ref ref -applyxfm -init aff_orig.mat -out in</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;"># check that the two differ</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;">fslview ref in</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;"># Now let's pretend we have to images (in,ref) we want to align. First estimate the affine matrix</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;">flirt -in in -ref ref -omat aff.mat -out aff && fslview ref aff</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;"># Then the warp coefficiants (i.e. non-linear alignment). Again these values are for mouse brains, Choose lambda=100 warpres=10,10,10 to speed up things for human brains</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;">fnirt --in=in  --ref=ref --aff=aff.mat --iout=nlin1 --cout=nlin1_warp --logout=/dev/null -v --applyrefmask=1 --applyinmask=1 --subsamp=2 --miter=2 --infwhm=0.3 --reffwhm=0.3 --lambda=3 --estint=1 --warpres=0.5,0.5,0.5 --regmod=bending_energy --intmod=global_non_linear_with_bias --intorder=5 --biasres=10,10,10 --biaslambda=500 && fslview ref aff nlin1</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;"># This should work and the brains should align. You could test that the nlin1_warp is actually correct by using applywarp</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;"># applywarp -i in -r ref -w nlin1_warp -o nlin1b && fslview ref aff nlin1 nlin1b </span><br style="font-family: courier new,monaco,monospace,sans-serif;"><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;"># Now let's use the previously estimated non-linear warp (nlin1_warp) as inwarp for another non-linear iteration</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;">fnirt --in=in  --ref=ref --inwarp=nlin1_warp --iout=nlin2 --cout=nlin2_warp --logout=/dev/null -v --applyrefmask=1 --applyinmask=1 --subsamp=2 --miter=2 --infwhm=0.3 --reffwhm=0.3 --lambda=3 --estint=1 --warpres=0.5,0.5,0.5 --regmod=bending_energy --intmod=global_non_linear_with_bias --intorder=5 --biasres=10,10,10 --biaslambda=500 && fslview ref aff nlin2</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><br style="font-family: courier new,monaco,monospace,sans-serif;"><font size="2"><span style="font-family: courier new,monaco,monospace,sans-serif;"># The alignment works but the output image is moved by the affine part, i.e. the affine transformation didn't make it into the non-linear warp output.</span></font></font><font style="font-family: courier new,monaco,monospace,sans-serif;" size="2"> Images "aff" and "nlin2</font><font size="2"><span style="font-family: courier new,monaco,monospace,sans-serif;">" don't overlap.</span><br style="font-family: courier new,monaco,monospace,sans-serif;"></font><font size="2"><span style="font-family: courier new,monaco,monospace,sans-serif;"><br style="font-family: courier new,monaco,monospace,sans-serif;"></span><span style="font-family: courier new,monaco,monospace,sans-serif;"># Applying the affine transformation in addition to the second non-linear warp yields the correct results (if your system has the bug)</span><br style="font-family: courier new,monaco,monospace,sans-serif;"><span style="font-family: courier new,monaco,monospace,sans-serif;">applywarp -i in -r ref --premat=aff.mat -w nlin2_warp -o nlin2b && fslview ref aff nlin2 nlin2b </span><br></font><br><br><br><br>Jan Scholz, D. Phil.<br>Research Fellow<br><br>Mouse Imaging Centre (MICe)<br>Hospital for Sick Children<br>Toronto Centre for Phenogenomics<br>25 Orde Street<br>Toronto, Ontario, M5T 3H7<br>Tel: 647-837-5811 x4332<br>Fax: 647-837-5832<br><br></body></html>