Building ROIs in MarsBaR

Downloading and installing MarsBaR

See http://marsbar.sourceforge.net/

Defining a (spherical) ROI

  1. Start MarsBaR by clicking Toolbox > MarsBaR, or typing marsbar from the Matlab command line.
  2. ROI definition > build
  3. Type of ROI > sphere
  4. Centre of sphere (mm) > the XYZ coordinates (for example, 17 -28 -17)
  5. Sphere radius (mm) > whatever you want the radius to be (typically 3-5 mm)
  6. It is probably ok to leave the description and label as the defaults, but you can change. Then select where to save this file.

The resulting ROI is a Matlab .mat file that contains information about the region (in this case, sphere). However, it is not tied to any specific MRI image or space. That is, you could use this ROI to extract data from many kinds of images.

Creating an image ROI

Once you have a MarsBaR ROI in .mat format, you may want to create a Nifti image of the ROI. (In a typical ROI image, the voxels in the ROI have a value of >0, everywhere else 0.)

  1. Start MarsBaR by clicking Toolbox > MarsBaR, or typing marsbar from the Matlab command line.
  2. ROI definition > export
  3. Export ROI(s) to > image
  4. (Select ROI)
  5. Space for ROI image > base space for ROIs, or select one of the images you are using in the analysis (e.g., a normalized EPI image for an fMRI study). This is the stage that determines the voxel space and voxel size used for extraction.
  6. Directory to save image > (whatever you want)
  7. Specify filename, and you’re done.

Viewing a MarsBaR (.mat) ROI

To look at the fruits of your labor in MarsBaR:

  1. ROI definition > view
  2. Select one or more .mat ROI files

Viewing an image ROI

To view the binary image ROI in SPM, you can use the Display button.

To view the binary image in mricron, you can overlay it on a built-in template (or any image in the same space as the ROI).

Using a script to create ROIs

If you have a lot of regions, it may be easier to script ROI creationg. Here is a simple script that creates both .mat and .nii ROI files:

%% Use MarsBaR to make spherical ROIs


%% Set general options

outDir = '/Users/peelle/experiments/MBSR/rois/bigbrain264_5mm-radius';
sphereRadius = 5; % mm


% coordinates are nvoxels rows by 3 columns for X,Y,Z
coords = [1 2 3
    4 5 6];


% (alternatively, or better, you could put these in a text file and read
% them in using the dlmread function)



%% Error checking: directory exists, MarsBaR is in path
if ~isdir(outDir)
    mkdir(outDir);
end

if ~exist('marsbar')
    error('MarsBaR is not installed or not in your matlab path.');
end


%% Make rois
fprintf('\n');

for i=1:size(coords,1)
    thisCoord = coords(i,:);

    fprintf('Working on ROI %d/%d...', i, size(coords,1));

    roiLabel = sprintf('%i_%i_%i', thisCoord(1), thisCoord(2), thisCoord(3));

   sphereROI = maroi_sphere(struct('centre', thisCoord, 'radius', sphereRadius));

   outName = fullfile(outDir, sprintf('%dmmsphere_%s_roi', sphereRadius, roiLabel));

   % save MarsBaR ROI (.mat) file
   saveroi(sphereROI, [outName '.mat']);

   % save the Nifti (.nii) file
   save_as_image(sphereROI, [outName '.nii']);

   fprintf('done.\n');

end


fprintf('\nAll done. %d ROIs written to %s.',