Hi,
There's no need to use this code, as img2stdcoord is a utility in FSL that is designed to do exactly this, and it is more flexible (since it will work with any resolution, not just 2mm). For this application you use it like this:
echo X
Y Z | img2stdcoord -img $FSLDIR/data/standard/MNI152_T1_2mm -std $FSLDIR/data/standard/MNI152_T1_2mm -vox -
Here is the documentation:
If you are trying to do coordinate conversions in MATLAB, and using matrices from FLIRT, then be warned that the FLIRT matrices use an internal FSL coordinate convention that is different from the NIFTI coordinate systems and that this makes working with
them much more difficult. This is why we've provided the above tool (plus img2imgcoord and std2imgcoord).
All the best,
Mark
Below is code sent out to the FSL listserv by Matt Glaser at some point. I recently modified it to convert from MNI to XYZ space using the 2mm brain as my standard. Be sure to check your calculations in FSLview using the standard brain you've
used in your analysis.
----------
#Original code sent by Matt Glasser, modified to divide by 2 by Steffie for 2mm standard brain
# $1 $2 $3 are your input MNI coordinates
x=`echo "($1 * -1 + 90) / 2" | bc`
y=`echo "($2 * 1 + 126) / 2" | bc`
z=`echo "($3 * 1 + 72) / 2 " | bc``
---------