Segmentation HOWTO

How-Tos - Segmentation

How do I...

Do segmentation in SPM?

The below instructions are for SPM2. SPM99 is almost identical, with a couple small differences: you'll specify the number of subjects explicitly to start, and you'll be explicitly asked about inhomogenity correction. SPM2 specifies that information in the segmentation defaults, and the options chosen here are roughly the defaults in SPM2.

Hit "Segment" in SPM's main interface.

Select images, subj 1? Choose your anatomical image - V001.img. Hit done.

Select images, subj 2? Hit done (or choose other subjects if you want to do them all at once).

Already spatially normalized? "No" if you're segmenting the original anatomy; "Yes" if you've chosen the wV001.img file (or nV001.img in SPM99).

Modality? Generally T1 MR. Choose T2 MR if you have a T2-weighted anatomical (if gray matter looks bright and white matter looks dark, for example). If you've chosen a functional image - echo-planar or spiral imaging both - choose EPI MR.

(SPM99 only) Attempt to correct intensity inhomogeneities? Choose "Lots of inhomogeneity correction." Inhomogeneity correction (or bias correction) attempts to remove any gradual intensity changes in the image due to scanner effects - say, the middle appears much brighter than the edges. This is a big problem for segmentation algorithms, and SPM's bias correction algorithm does a goob job accounting for the problem. If you notice very strange effects in your segmented images (like gray matter appears to fade in and out across the image irregularly, for example), you can try lessening the inhomogeneity correction or turning it off. But generally it's a good idea to turn it on full-bore, which is the default in SPM2.

(SPM99 only) Write inhomogeneity-corrected image? Choose "Write corrected image." This will actually write the corrected image to disk, which is nice to have around.

The image will now segment, and you'll get at least three images out as output: V001_seg1.img, V001_seg2.img, V001.seg3.img. The first is the gray-matter-only image, the second is the white-matter-only image and the third is the CSF-only image. If you chose to write the bias-corrected image (in SPM99) or if you're using SPM2 (which writes it by default), you'll get a fourth image, mV001.img (or corr_V001.img in SPM99), which is the original image, corrected for any nonlinear biases in its intensity, so it should look much more even and unshaded. Use "Check Reg" to compare the two if you like. The segmented images can now be used in whatever way your little heart desires, so long as it's within the law.

Do skull-stripping (or brain extraction)?

SPM99 had a specific function for doing brain extraction that actually wrote an image file out. But then, in SPM2, they folded a good deal of the code in that function into the segmentation function, but didn't leave any option to write an all-brain mask image. The nice thing, though, is that what made SPM99's skull-stripping necessary was that the gray matter image often left a lot of skull on the image. That's no longer true (supposedly) in SPM2, so you shouldn't have to do skull-stripping there. But you still might want to have an all-brain mask image, or maybe your gray matter mask still has skull on it after all. For whatever reason, you might find yourself still wanting to use the skull-stripper in SPM.

So you have two separate things you can do in SPM. One is to use spm_xbrain, the SPM99 facility. You do this if a) you're using SPM99 and want a skull-stripped gray matter image and/or skull-stripped all-brain mask, or b) you're using SPM2 and you aren't happy with how much skull is left in your gray matter mask.

The second possibility is only for those using SPM2. If you're segmented with SPM2 and you want to have an all-brain mask, you can simply combine the gray and white matter masks together to make one. You can't do this in SPM99, because there's usually skull left on the gray matter mask, and the skull-stripping function automatically writes a combined mask for you. In SPM2, you have to do the combination manually, but you don't have to strip the skull.

Instructions for both are here:

Option 1: Use spm_xbrain, the SPM99 facility. You can use this even if you've been using SPM2 for the other stages of your analysis; you won't need any SPM99-specific files, and it won't do anything tricky to the images. To go this route:

Start SPM99 and hit "Render" in the SPM main interface. Choose "Xtract Brain" in the drop-down menu.

Select gray and white matter images: Select your gray and white matter images - this is V001_seg1.img and V001_seg2.img in your anatomy/inplane directory.

Save what? Save Extracted Brain. The other options are for doing 3-D rendering of your brain if you like.

The rendering will combine the segmented images and erode the skull, to produce a brain_V001.img file in the same directory. If you're feeling extra crazy, you can intersect the brain mask with the gray matter image to skull-strip your gray-matter mask, as follows:

Hit "ImCalc" in the main SPM interface.

Select images to work on : Select inplane/V001_seg1.img, inplane/brain_V001.img, DONE.

Output filename : Type V001_seg1_noskull.

Evaluated function : Select i1.*i2. This will multiply, voxel-by-voxel, the value of the gray matter image with the value of the skull-stripped brain, effectively producing an intersection of the two (since any zero in one will zero out the voxel in the final image).

This will produce a new file, inplane/V001_seg1_noskull.img in anatomy/inplane. Display the image to check how it looks. You can also compared it to inplane/V001_seg1.img using the "Check Reg" button.

Option 2: Combine the gray and white matter masks into an all-brain mask. This is essentially what is done, by the way, by the specmask script (see GablabScripts). specmask also smooths the brain to make extra sure it's got the whole brain; we won't do that, to avoid getting any skull.

Hit "ImCalc" in the main SPM interface.

Select images to work on : Select inplane/V001_seg1.img, inplane/V001_seg2.img, DONE.

Output filename: Type union_V001.img.

Evaluated function: Type i1 + i2. This will add, voxel-by-voxel, the value of the gray matter image with the value of the white matter image, effectively producing the union of the two.

In order to turn this image into a mask image, though, we need to make it binary-valued. So hit "ImCalc" again, and choose union_V001.img as the image to work on.

Output filename: Type brain_V001.img.

Evaluated function: Type i1 > 0.5. This will replace the value of every voxel whose value is greater than 0.5 with 1, and every other voxel with 0. The resulting image file, brain_V001.img, should be a fairly tight mask of the brain-only voxels in your anatomical file. Use "Check Reg" to compare its outlines with the outlines of the brain in your anatomical to make sure.