Anatomical Methods


Jump to: navigation, search

High quality anatomical images (T1-weighted) are important because they images serve as the spatial reference frame in both functional and diffusion-weighted applications. We call the T1-anatomical the reference volume. The T1-anatomical data for a subject are stored in a compressed NIFTI file named t1.nii.gz. For visualization and flattening we segment the T1 data into gray, white and csf regions.

This page is a general overview. There are guides for specific tasks (e.g., alignment to the reference volume, segmenting, flattening) on the Tutorials and Programming pages. There is also a more detailed page for specific Anatomical Processing methods that explain how to combine dicom files into a NIFTI file and align the data.


[edit] Installation

[edit] Software

[edit] Data

There are many anatomical data sets on the system, and many files are created from these anatomical data. It is important to keep them organized. We use a common naming and directory system for storing these files. On Linux, the anatomical data and various processed forms of these data an be found at

  • /biac2/wandell2/data/anatomy/subjectCode

We generally combine multiple T1-weighted SPGRs for each subject. We co-register and average these anatomicals together to improve the gray/white contrast and reduce noise. There is a page describing Anatomical Processing methods for acquiring and combining T1-anatomical data.

The images below illustrate the quality we obtain after averaging 6 scans collected in 3 different scan sessions.
Anat t1 mbs.jpg

The path to the main anatomy directory differs on Windows and Linux systems. If you typically use one computer, we recommend you store the name of the anatomy directory permanently using the Matlab preference mechanism. Use the command:

  • setpref (‘ VISTA ', ‘ defaultAnatomyPath ', ‘ nameOfYourAnatomyDirectory ')

Preference values, such as the location of this anatomy path, are persistent and maintain their values between MATLAB sessions.
(Programming note: The variable is retrieved in the mrVista function getAnatomyPath();.)

Another source of anatomical data sets is the Human Connectome Project Data which can be accessed at this link. To download the files, first create an account. If prompted to install the Aspera Connect plugin, click on the link and download it. To install it on Linux, open up a terminal and follow the procedure below:

tar -xzf <pluginName>.tar.gz
sh <pluginName>.sh

Log into your account and accept the data use terms by clicking on the button located near the top right of the page. You can now download any of the subject data by clicking on one of the subject options provided near the top of the page.

[edit] The processing pipeline

The standard steps we perform to obtain and segment an anatomy are described on the pages listed below:

  1. Acquisition: this page describes taking the raw anatomical data from the scanner converting to MrVista-compatible formats (including NIFTI format, resampling to an isotropic resolution (usually 1mm), coregistering multiple measurements if you collected more than one, and (optionally) rotating into AC/PC space. (For applications requiring back-compatibility conversion from the MrGray vAnatomy.dat format is also described).
  2. Pre-processing: this page describes using the Oxford FSL package to run automated preprocessing steps, including creating a version of the anatomy containing only the brain, and creating an initial segmentation. These steps are not always done, but can often be useful to get started. They require that FSL be installed.
  3. Gray/White matter segmentation:There pages describe ItkGray and include a step-by-step overview of using ItkGray to produce a high-quality segmentation.
  4. Create a 3D Surface Mesh: A beneit of segmenting is that functional and diffusion data can be visualized on a 3D mesh representing the gray matter surface. This visualization can help scientific understanding greatly. This page describes how to use the classification files to produce 3D mesh files, and how to view the meshes using MrVista utilities.
  5. Flattening (optional): This page describes producing flattened cortical patches from the gray matter representations, for use with the Flat view in analyzing functional data. This is not always used, but can be useful for certain applications, like retinotopic mapping.

We should describe other utilities, most importantly co-registration and atlas-creation, here as well. (BW).
We now have example scripts, courtesy of Reno Bowen, illustrating some of these steps. Those should be mentioned here. (BW).

[edit] Segmentation

We first pre-process the T1-anatomical data into a standard format; we then use ItkGray to identify the gray matter in the T1-anatomical.

Prior to segmenting with ItkGray, we run an auto-segmentation algorithm to generate an initial segmentation. Starting with an initial estimate is easier than creating a segmentation from scratch. To generate the initial estimate, we use the auto-segmentation tools from either FreeSurfer or FSL. We have found recently that FreeSurfer's auto-segmetnation is better and easier to use than FSL's. If the t1 is sufficiently good quality, then the FreeSurfer segmentation is likely to require very minimal hand editing.

Both procedures are described below.

[edit] Preparing for Segmentation with FreeSurfer

  • From a terminal window, call the FreeSurfer segmentation tool:
recon-all -i <PATH_TO_YOUR_T1_NIFTI_FILE> -subjid <subjectID> -all
  • From Matlab, convert the FreeSurfer segmentation to nifti format using our segmentation conventions, e g.:
fs_ribbon2itk(<subjid>, <outfile>, [], <PATH_TO_YOUR_T1_NIFTI_FILE>)

See our FreeSurfer page fore details on installing and running FreeSurfer and on using our FreeSurfer => ItkGray conversion tool.

[edit] Preparing for Segmentation with FSL

Follow the steps on the gray/white segmentation pre-processing pipeline prior to segmenting with ItkGray. This pre-processing pipeline generates an initial segmentation of the white matter, the CSF, and subcortical gray matter, including labels for each of these classifications.

The pre-processing uses FSL tools; the following tools must be on your (linux) path:

  • FIRST (FMRIB's Integrated Registration and Segmentation Tool) - which uses mesh models trained with a large amount of rich hand-segmented training data to segment subcortical brain structures.
  • BET (Brain Extraction Tool) - segments brain from non-brain in structural and functional data, and models skull and scalp surfaces.
  • FAST (FMRIB's Automated Segmentation Tool) - performs the actual brain segmentation into different tissue types and bias field correction.

We also use a Matlab script:

  • mrGrayConvertFirstToClass - This script generates an initial segmentation from the FIRST and FAST outputs. It also coats the cortex with a layer of CSF and creates a label file (*.lbl) which contains the labels for the tissue types (CSF, right white, etc.).

[edit] Segmenting with ItkGray

T1 class.jpg

We use ItkGray for gray/white matter segmentation. This program was developed by Bob Dougherty based on ITKSnap.

[edit] mrGray: (Retired)

For many years we used mrGray to segment gray/white and to visualize 3D brains. That program has been replaced by ItkGray.

[edit] Alignment

There are several methods for aligning Functional or DTI data to the anatomical reference volume. The Alignment page is a gateway to these methods.

[edit] Meshes

The Mesh page contains information for creating, smoothing, and displaying 3-dimensional reconstructions of the cortical surface.

We use these meshes routinely to interact with data in both MrVista and MrDiffusion.

[edit] Quantitative Imaging

This page describes methods related to the collection and analysis of SPGR to get T1 PD TF and aHLF.

[edit] Tips and Tools

This section provides useful information for dealing with common tasks, specifically related to anatomical data.

[edit] Converting vAnatomy.dat to a t1 NIFTI

If you don't have a NIFTI-format T1-weighted image, or the original I-files, but you do have the older vAnatomy.dat file, you can create a new NIFTI format anatomical using

 [vData,mmPerVox] = readVolAnat('path/to/vAnatomy.dat');
 % Convert mrgray sagittal format to our preferred axial format for NIFTI
vData = flipdim(flipdim(permute(vData,[3 2 1]),2),3);
mmPerVox = mmPerVox([3 2 1]);
xform = [diag(1./mmPerVox), size(vData)'/2; 0 0 0 1];
ni = niftiGetStruct(vData, inv(xform));
ni.fname = '/path/to/new/nifti/file.nii.gz';

Or, here's some alternative code if the preceding doesn't work:

  anat = mrLoad('path/to/vAnatomy.dat'); = mrAnatRotateAnalyze(;
mrSave(anat, '/path/to/new/nifti/file.nii.gz');

[edit] Resampling T1 anatomicals (nifti class files)

To resample the T1 & class files use the command

mrGrayResampleNiftiClass(t1File, classFile, outMm)

N.B. We recommend representing the anatomy and class files at 1 mm (isovoxel). Resampling to a very high-resolution (e.g., 0.7 mm), greatly increases the data size and slows down everything. Only do this if you have a good reason.

[edit] Computing Talairach coordinates

Talairach coordinates are often used to compare anatomical locations across labs. The Matlab command computeTalairach launches a GUI to transform vAnatomy (native) coordinates into Talairach coordinates.

Note that the computeTalairach function will give you a talairach coordinate transform. Many labs will report coordinates in MNI space instead. We call this the spatialNorm, which you can generate using the following code:

   ni = readFileNifti('3DAnatomy/t1.nii.gz');  % this assumes you are starting from your mrSESSION directory
[sn,template,inv] = mrAnatComputeSpmSpatialNorm(double(, ni.qto_xyz, 'MNI_T1');
invLUT = rmfield(inv,{'deformX','deformY','deformZ'});

Once you've computed either the Talairach transform or the MNI (spatialNorm) transform, or both, you can simply use the GUI in the mrVista Volume/Gray view. Choose Talairach under ROI, and either: 1) Enter some Talairach (or MNI) coordinates to be transformed into the subject's space. 2) Load Talairach coordinates from file (not sure what this does), or 3) Load an ROI and compute the Talairach/MNI coordinates for this ROI, using the "Compute Talairach coordinates" menu option.

[edit] Image plane conventions

In the relatively short time brain imaging has been around, it's managed to acquire a heap of different conventions for how to store and display 3-dimensional brain data. Consequently, keeping track of what direction in your data matrices corresponds to what direction in the real world can be exhausting. A thorough, and exceedingly well written summary of the various conventions can be found on this excellent page.

For simplicity's sake, here is the break down: the simple processing described above uses data in which increasing (rows, columns, slices) in the data correspond to increasingly (right, anterior, superior) positions, respectively. This is the standard orientation used in the Talairach convention. This is also called the Neurological convention. (Radiological convention is the same, except that left and right are flipped.) This format can be referred to as RAS for "Right-increasing, Anterior-increasing, Superior increasing".

Sometimes, when papers or code refer to "X, Y, or Z" axes, they mean "left <-> right", "posterior <-> anterior", and "inferior <-> superior" axes, respectively. When you display the first slice of an RAS anatomy using MATLAB or another program, it will show an axial slice at the bottom of the brain in which right is down, and the front of the brain to the right.

The file conventions described below, including the mrGray / mrVista vAnatomy.dat file (and the function VOLUME view in mrVista), use an IPR space, in which (rows, columns, slices) are increasingly (inferior, posterior, right) respectively. This isn't that widely used, but a display of the raw data looks nicer. The first slice of an IPR data set will be the left-most sagittal slice, in which the front of the brain is to the left.

[edit] Building vAnatomy.dat


For some calculations mrVista requires a special anatomy file (vAnatomy.dat). This function starts with the NIFTI file you created and produces a standard vAnatomy.dat file and a corresponding UnfoldParams.mat file.

If you omit the arguments, a GUI will allow you to select the name of the t1 nifti file (the average you created above). You may need to change the filter at the bottom to show nifti files, rather than analyze. createVolAnat reads the t1 file and then shows you some example slices and the intensity histogram. The slices and histogram appear in a window. In the subplot for the histogram (upper left), select lower and upper limits to the MR values. The routine shows you the effect on the MR data for these values. Choose upper and lower values that maximize the gray/white contrast, without saturating the white matter completely.

If you don't understand this, click a few times and you will get the idea. After each click you are given the option of keeping (or not) the particular choice. (We should improve the UI here.)

When you accept your selection, the vAnatomy.dat file and the UnfoldParams.mat file will be written to disk. You can select where they are written. The default is the current directory.

The data saved in the volume anatomy file are a 3D volume. The dimensions are (sup-inf, ant-post, left-right). So, to view axial slice 100, specify only sup-inf, you can run

[img,mmPerPix,volSize,fileName] = readVolAnat([fileName])
Axial100 = squeeze(img(100,:,:));
imagesc(Axial100); colormap gray;

To see Coronal (specify only ant-post) or Sagittal (specify only left-right) you can use

Coronal100 = squeeze(img(:,100,:));
Sagittal100 = squeeze(img(:,:,100));

[edit] Resampling vAnatomy.dat

The command 'mrAnatResliceSpm' resamples the anatomical data(SPM tools required). e.g., to isovoxel a vAnatomy, try this:

img = readVolAnat('vAnatomy.dat');
mrAnatResliceSpm(img, eye(4), [], [1 1 1]);

[edit] Converting NIFTI Files to mrGray Files

If you are not able to install the t1_class.nii.gz straight into mrVista and grow the gray, then do the steps outlined below.

Segmentations produced using the newer ITKGray pipeline reside in a single NIFTI file (usually named t1_class.nii.gz), which is convenient; but the interface to use these files within MrVista is unfortunately not fully debugged. Although the code works for some combinations of MATLAB version and operating system, a key part of the code does not work for other versions. (The main issue seems to be a piece of compiled code, grow_gray, which produces a gray matter graph from the t1 class file NIFTI.) It has been an objective to have this MEX file, along with others in the repository, debugged, but it has been on the back burner for a while. Even assessing whether it will work on a given OS / MATLAB is not clear: the best way to know is to try it out, by selecting the t1_class.nii.gz file as the segmentation.

In cases where the new NIFTI files don't work with mrVista, we back-convert these files to the old format using mrGray. Here is one way to do this:

  1. Ensure you've saved the main T1-weighted anatomy as a NIFTI file. If you haven't here is simple MATLAB code to do this. (In this case, the anatomy is named t1.nii.gz, and is not to be confused with t1_class.nii.gz, which is the classification rather than the anatomy.)
    • anat = mrLoad('t1.nii.gz', 'nifti');
    • = mrAnatRotateAnalyze(;
    • mrSave(anat, 'vAnatomy.dat', 'vanat');
  2. Run the function itkGray2mrGrayClass with no arguments. You will be prompted to select the t1_class.nii.gz file. This function will create two new subdirectories, Left/ and Right/, in the same anatomy directory as the NIFTI file. Within the Left/ and Right/ folders will be mrGray classification file, Left/Left.Class and Right/Right.Class.
  3. Open mrGray on a Windows machine. (The path to mrGray in the vistasoft repository is vistasoft/trunk/mrAnatomy/MrGray/mrGray.exe.)
  4. Create a new project, named "Left.mrp" in the left hemsiphere directory.
  5. Select the menus File | Classification | Load, and select the Left.Class file created in step 2.
  6. Select the menu Classification | Grow Gray Matter. Press OK.
  7. Save the gray graph. Select gray matter by holding down Control and left-clicking it. It should change color. Then select File | Save Selected Gray, and choose OK. (Left.Gray is a good default name for it.)
  8. Optional step if you want to flatten the gray matter: Build a 3D Mesh visualisation in mrGray and save it.
    1. Select the menu 3D | Build Visualization.
    2. You will get a dialog box labeled "Visualization Parameters". There will be several tabs at top; the "Structural" tab will be selected first. In this tab, select "White/gray boundary" and set the voxel dimensions appropriately (usually X:1, Y:1, Z:1).
    3. Select the "Smoothing1", "Decimation", and "Smoothing 2" tabs. For each tab, check off the checkbox "Skip this step".
    4. Select the "Output" tab. Check off the options "Save output mesh to file" and "Start viewer on completion".
    5. Press the "Begin" button at bottom.
    6. A blocky, uninflated mesh representation should be built. Verify that this looks approximately like the gray/white bounder for the appropriate hemisphere, and close the 3D window.
    7. The mesh file saved (in the old mrGray format, *.MrM) is needed for the flattening code. (A newer version may not need this, but doing things this way works.)
  9. Repeat steps 3-8 for the Right hemisphere.

Having completed these steps, you can then install a segmentation using the .class and .gray files you just created. Other mrVista options, such as flattening cortical patches, will also be available.

Personal tools