Building ROIs in MarsBaR¶
Downloading and installing MarsBaR¶
Defining a (spherical) ROI¶
- Start MarsBaR by clicking Toolbox > MarsBaR, or typing
marsbar
from the Matlab command line. - ROI definition > build
- Type of ROI > sphere
- Centre of sphere (mm) > the XYZ coordinates (for example, 17 -28 -17)
- Sphere radius (mm) > whatever you want the radius to be (typically 3-5 mm)
- 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.)
- Start MarsBaR by clicking Toolbox > MarsBaR, or typing
marsbar
from the Matlab command line. - ROI definition > export
- Export ROI(s) to > image
- (Select ROI)
- 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.
- Directory to save image > (whatever you want)
- Specify filename, and you’re done.
Viewing a MarsBaR (.mat) ROI¶
To look at the fruits of your labor in MarsBaR:
- ROI definition > view
- 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.',