my.Page

faqja.Ime



software
analysis
experiments
writings

Some analysis related things:

Converting images and coordinates from one space to another (ex. Bold to MNI)

If you have done the analysis and you have a transform matrix, for example in fsl, under the *feat/reg/ directory you will have all the transform matrices, then you need to sometimes transform the image back and forth yourself from one space into the other. You can use FSL command flirt to apply the transform which i think it also computed before:
        /usr/apps/fsl/bin/flirt -init subject.feat/reg/highres2standard.mat \
                                -applyxfm  -in  image_to_transform.hdr      \
                                -ref subject.feat/reg/standard.hdr          \
                                -out output_image_transformed.hdr           
     
If on the other hand you only want to transform a list of coordinates (and not the whole image) you can use the rumba tool applytransform to do the task.
     applytransform --inextent 64 64 25 --inorigin 0 0 0                \
                             --outextent 91 109 91 --outorigin 0 0 0    \
                             --indims 3.4375 3.4375 4 --outdims 2 2 2   \
                             -t transform.txt
     
the transform.txt needs to be a one entry per line transform, so if FSL produces a transform.mat like this:
     1.10332  0.0159968  -0.00172184  -32.484
     0.00883753  1.08792  0.251425  -19.1413
     -0.00191523  -0.287296  1.19169  72.9406
     0  0  0  1
     
you need to transform it to this:
      1.10332
      0.0159968
      -0.00172184
      -32.484
      0.00883753
      1.08792
      0.251425
      -19.1413
      -0.00191523
      -0.287296
      1.19169
      72.9406
     
you can do that by doing cat transform.mat | sed 's/ /\n/g' | grep -v "^$" | head -12

When data comes in DICOM format


you will have a bunch of files that look like this:
      MR.1.3.12.2.1107.5.2.7.20415.9.0.906642961265823
      MR.1.3.12.2.1107.5.2.7.20415.9.0.9066431231222363
      MR.1.3.12.2.1107.5.2.7.20415.9.0.9066432719092392
      
so you need to do two things:
    1) since this directory probably holds more than one series of images, you need to run
     dicomsort 
    while being in the directory where this data is located, so make sure you have write access to that directory--dicomsort will separate the MR. files in subdirectories, one per each series (8241, 8242, etc.)
    2) you want to convert the dicom data into analyse.

When magnet produces IMA images


IMA data that comes out of the fMRI magnet is in siemens format (if the files have a ima extension, example 321-3-34.ima) or in dicom format (with extension dcm).

That data needs to be converted into other formats, more specifically to the analyse format with which spm, fsl, and our own rumba-tools work. Here i will do a small summary of the tools and commands to convert from siemens format into analyse.
To do the conversion, we can utilise the rumba tools from our lab.

To make the anatomy image (say we want to call it subj-anat.img) from *-2-*.ima, assuming that *-2-*.ima are the slice-images for the anatomy image (ex. 321-2-14.ima, 321-2-15.ima, 321-2-16.ima ...), do:

      manifoldcat -i *-2-* -o subj-anat.hdr 
      

manifoldcat is the program which concatenates together many input files into a single output file. The files *-2-* are 2D slices so by concatenating them we produce one 3D image.

To find which slices are the ones that belong to the anatomy, we can look in the directory where the .ima images are. We are searching for 2D slices often 256x256 voxels (not always that size though). To do that we can dump information on an image in each series and we do that by doing:

      dumpheader 391-2-4.ima
      
which will produce something like:
      Dimensions: 256x256x1x1
      Spatial voxel size: 0.92x0.92x2
      Dim??: 0
      datatype: 4
      depth: 1
      dimT: 0
      dimX: 0.92
      dimY: 0.92
      dimZ: 2
      .
      .
which means that the image is a 512 by 512 voxels, with dimensions 0.92mmx0.92mm and tell us that this is the anatomical image (spin echo or mprage). To view the image built, use:
      rumbaview subj-anat.hdr
      

To make a 4D (SPACE x TIME) volume (to put all the bold over time into a single file), do:

      manifoldcat -i *-4-* -o 4Dvolume.hdr 
      

To convert the *ima bold images into img for spm processing, assuming that *-4-* are the bold sequence scans, do:

      PREFIX=subject-name
      FLS=-4-

      for i in `ls *$FLS*` ; do
      cmd=babelfish -i $i -o $PREFIX-`echo $i|sed "s/...$FLS//" \
      | sed "s/ima/img/"` ;
      echo $cmd
      eval $cmd
      done;

      
To view an image (2D, 3D, 4D) use rumbaview:
      rumbaview 4Dvolume.img 
      
To list a directory's files in a natural order (aka natural sort), use:
      ls | sort -n | awk '{i = length($0); sizeArr[i] = sizeArr[i] $0 "\n" } \
                  END  { for (i in sizeArr) { print sizeArr[i]; } }'| grep "."
      
as a one liner, this will list: file-1 file-2 file-3 ... instead of file-10 file-11 file-1 file-20 file-21 file-2 ... (which is what 'ls' or 'ls | sort -n' will do).

To check the intensity of the images (and other statistics) you can do:

      FLS=-4-

      for i in `ls *$FLS*` ; do
      manifoldstat -i $i;
      done;

      
This way you can see which images (generally the first six) have a mean greater than all the other images and should be excluded from the analysis.

Note that if the files are in funny order when you do ls (ie not in natural order) then instead of ls *$FLS* use the above one liner to have them sorted in natural order, namely:

      FLS=-4-

      for i in `ls *$FLS* | sort -n | awk  ' \
              { i = length($0); sizeArr[i] = sizeArr[i] $0 "\n" }  END \
              { fo r (i in sizeArr) { print sizeArr[i]; } }'| grep "."` ; do
          manifoldstat -i $i;
      done;