How to use MRIcron for erasing

Chris Rorden’s MRIcron is a very powerful tool for working with MR images. Just one of its cool features is that you can draw on or erase images. That means you could draw a custom ROI. You could also erase something – like something you wanted to mask out but it didn’t quite work, so you want to clean it up.

Here we’ll go thru my example of erasing a mask that I’ve used for second level fMRI results. This mask includes only gray matter (but gray matter liberally defined) and excludes the cerebellum (because we use a specialized pipeline combining SUIT and CERES on the cerebellum).

The problem is that, when I made this mask I used the SUIT template to mask out the brainstem and cerebellum. This successfully masked out *most* of the brainstem and cerebellum, but left some edges. Knocking out most of these regions may work just fine for whole brain second level analysis purposes — in which we’re not interested in the brainstem and cerebellum, so therefore we don’t want to have to correct for multiple comparisons for these regions. However, we should really erase these edges if we want to be perfect and knock out every voxel from second level that we don’t want to have to account for in multiple comparison correction.

One thought I had was to just dilate the SUIT template so that it’d better grab these edges when I apply it to the gray matter mask. However, the problem is that I don’t want to erase anything more superior in the brain — the superior edge of the SUIT mask looks like it’s doing a perfect job of pulling off only the cerebellum. If I were to dilate the SUIT mask, it’d grab too much of the inferior cortex. Thus, I think my best option is to go in and hand erase in MRIcron.

To do this, first, open the image you’d like to erase as the base image in MRIcron ( File > Open > select NIFTI file ). I get the best display if I set one view as the main image (e.g., View > Display > Sagittal ). Make sure you have your drawing tools turned on ( Draw > Show drawing tools ).

Then, just start coloring over all the regions you’ll want to delete. You can use whichever of the drawing tools you find most helpful:
-Pen tool: draw lines or closed shapes
-Autoclose pen: draw shapes & MRIcron will automatically close them for you
-Fill: fill in the shapes you drew with one of the pens
-CTRL+pen or CTRL+autoclosepen: draw a thicker line with the pen
-Ellipse tool: draw an ellipse
-CTRL+ellipse: draw a square
-SHIFT + pen/autoclosepen/shape: erase your drawing
-CTRL+Z: erase your last mark

Here I mostly used the ellipse tool to cover the region I want to delete in red. Now, I will go through every slice to cover the entirety of the region I’d like to delete. In this case, the easiest way to do this is to just start on the left of the brain, then go through every X slice until you’ve been through and colored on every slice on the sagittal plane.

Eventually, your image will look something like this. I’ve drawn on the sagittal plane, but can see my progress develop in the coronal view.

Once you’re satisfied that you want to erase everything in the red region, you’re ready to save your “volume of interest” (VOI) by selecting Draw > Save VOI . This will save a record of this red region you’d like to erase.

Then, you can mask your image by your VOI. Hit Draw > Mask image with VOI > Delete regions with VOI . This deletes everything in the underlay image that falls within the VOI. Now, go to Draw > Close VOI so that you can see your underlay image, with the VOI regions now deleted.

If you are satisfied, you must save your NIFTI image. Nothing changes about your original underlay image just by playing with erasing in MRIcron. You need to save a new NIFTI file if you’d like to retain these changes. Select File > Save as nifti to save your edited image. Then, you should be done! You should now have a NIFTI image of your original underlay with the regions you colored now deleted.

One more note- depending on how you’d like to use this erased image, you may want to check the values to ensure that you’ve create a binary image. For instance, here, we started with a binary GM mask, but this erasing set all of the erased areas to -1 instead of to 0. This is not what we want — we intended to have a 0/1 binary mask where regions to count in second level analyses = 1, and regions to exclude in second level = 0, not -1.

Thus, in this case, we just need to do one more quick step to binarize this mask before using in second-level analyses. We need to run it through SPM imcalc, fslmaths, or something similar to set these -1 values to 0. Using imcalc, the batch code might look like this:

matlabbatch.spm.util.imcalc.input = <'E:\Scripts\WB_second_level\_Template_ROImasks\Template_1_IXI555_MNI152_GM_noCB_erased2.nii,1'>; matlabbatch.spm.util.imcalc.output = 'Template_1_IXI555_MNI152_GM_noCB_erased2_bin'; matlabbatch.spm.util.imcalc.outdir = <'E:\Scripts\WB_second_level\_Template_ROImasks'>; matlabbatch.spm.util.imcalc.expression = 'i1>0'; matlabbatch.spm.util.imcalc.var = struct('name', <>, 'value', <>); matlabbatch.spm.util.imcalc.options.dmtx = 0; matlabbatch.spm.util.imcalc.options.mask = 0; matlabbatch.spm.util.imcalc.options.interp = 1; matlabbatch.spm.util.imcalc.options.dtype = 4;

Instead of calling matlabbatch by MATLAB command line, I just ran this same code in the SPM imcalc GUI:

By setting the equation to only retain regions >0, we’ll knock out those -1 erased regions. The result looks something like this, where we now have in-brain areas to keep = 1, and everything else = 0. et voilà!