MrGray and MrFlatMesh

This information is very old...most machines where this stuff were installed are gone...still, it is a lot of information, so I'd hate to just delete it when it might be useful to someone, somewhere.  Dianne Patterson 10/25/2006

MrGray runs as a standalone program under MSWindows. MrFlatMesh contains a series of Matlab routines and will run on any machine that has Matlab.


Purpose

MrGray allows one to classify voxels in a brain image into white matter and CSF (using a combination of automatic and manual techniques described in the tutorial) and then "grow" a gray matter layer, to a specified thickness, on the white matter. This gray matter can be saved as a 3d mesh file. MrFlatMesh uses the 3d mesh file generated by mrGray as input for its unfolding operations. NOTE: At this time (12/28/2001) , the software to view unfolded maps or activations on those unfolded maps is not available.


Downloads and Links

Official Documentation: http://white.stanford.edu/~brian/mri/mrGrayDocs/mrGrayTips.html
Download at: http://white.stanford.edu/~brian/mri/segmentUnfold.htm

Locally, we have several useful downloads:

  • A MrGray Tutorial (word document; still under revision, but useful, I hope)
  • MakeMrGrayfun.m (three flavors; this converts functional data from spm into a functional overlay file that MrGray can read)
  • Reorient.m (This spm routine will read the mat file associated with an image and actually flip the image into the described orientation. This is crucial if you want to export an spm image to be read by another program (like MrGray or MRIcro). It also reslices the image into isotropic 1x1x1 voxels. If you get MakeMrGrayfun.m, then you'll need John Ashburner's reorient.m)

Image Conversion

You can use MRIcro (a stand alone PC program) to create an "Analyze format" image from your raw images (spm uses Analyze format, so any spm image volumes will work).

If you need to reorient the image volume you may use MRIcro's "save as" utility. However, if you have nonisotropic voxels, this may result in distortion. In such a case, John Ashburner's reorient.m will use the *.mat file that spm generates to actually reorient the image AND, it will slice the entire image into isotropic 1mm x 1mm x 1mm voxels. Reorient.m requires Matlab and SPM to be installed.

Once you have the Analyze/SPM format *.img and *.hdr files, you can use the Matlab routine (analyze2mrgray.m) provided with the conversion utilities to create the correct 8 bit *.dat file used by mrGray. For example, if you have an 8 or 16 bit image (fred.hdr and fred.img), then the following matlab command will create a *.dat file (only one) and allow you to name it:

>>analyze2mrGray fred.hdr

This program will convert 8 or 16 bit images to the correct format. It will assume the images are 8 or 16 bit big-endian unless you tell it to expect little endian. Analyze2mrGray uses routines that come with mrFlatMesh and the SPM99 spm_vol command to parse the header. It requires Matlab. Alternatively, MRIcro can convert the image from 16 to 8 bit, using the "Save As" function.


Make Mr. Gray Fun

Read the tutorial document listed above to learn more about the format of functional overlay files in MrGray. The three MakeMrgrayFun m-files are all slightly different. All of them depend on Matlab, SPM and reorient.m.

Preprocessing Steps

1) Flip the 3D image to put it in the same orientation as the functionals.

2) Apply reorient.m to the 3D structural after you have flipped it.

3) Coregister your functional images to the 3d structural image resulting from #2:

  • coregister only
  • Target: T1 MRI
  • Object: Mean EPI
  • Other: The rest of the functionals

The direction of coregistration is important because you want a pristine 3D file with no attached mat file that might describe additional orientation changes. The functionals will end up with the mat files.

4) Generate a write filtered image of the activations from the SPM Results (after displaying the results of your analysis in SPM, select "write filtered" and name the output file. We will call this output file "activity".


Three ways to Make Mr. Gray Fun

makeMrGrayFun.m
First, apply reorient.m to activity.img:

>>reorient activity.img

(This will create ractivity.img)

>>makeMrGrayFun

(This will present an SPM gui interface for you to find and select "ractivity". The program will produce an output called, in this case, ractivity.fun. The result will map all activations into 4 levels of color). The output is a text file which you can open and examine.

makeMrGrayFundump.m
This is like makemrGrayFun except that it will print 6 columns of voxel coordinates. The first three columns are x,y and z in SPM. The next three columns are the x,y,z coordinates in Mrgray. This allows one to check the output and it allows one to generate a text file of all the suprathreshold voxels in SPM.

makeMrGrayFun1.m
This does not require the user to apply reorient.m to the activity.img. In fact, it will probably run out of memory and bomb if you do apply reorient.m to the activity file, because the underlying algorithm is not very efficient. makeMrGrayFun1 asks the user to identify both the activity file and the 3D anatomical. It then maps from the native voxel space of the functional image to the voxel space of the coregistered 3D image. An interesting side effect of this is that the program will choose only one voxel in the 3D image to represent each voxel in the functional image and thus generate far fewer activations in the text file. The visual effect of this is that the activations appear much smaller when displayed on the 3D image.

Overall, we prefer makeMrGrayFun.m, but the other two may have interesting applications and are thus made available.