Using Gannet just for the calculation of tissue fractions for a T1W image

Hello everyone,

I am trying to use Gannet to calculate the tissue fractions of WM, GM and CSF in a co-registered voxel without using GABA-edited data like HERMES or MEGA-PRESS. Is this possible? The data that is being loaded in is 7T philips sdat data with an act and ref file and a T1w.nii file.

Currently I am using the functions Gannetload, GannetFit, GannetCoRegister and GannetSegment. However the segment part is not running due to there being an “Error using MATLABbatch system”

Anybody had this problem before? Thanks in advance!

Hi @SanderB,

I’m surprised you get past GannetLoad and GannetFit with non-edited data (although perhaps the Philips reader is a bit more tolerant in that regard). Normally I have to somehow trick the reader into even letting me load non-edited data.

Do you have any more detail on the error message (eg, a backtrace)? I’m guessing a bit, but it sounds like this might actually be an issue with your local SPM installation – maybe the tissue probability map isn’t exactly where Gannet expects it. Could you try calling CallSPM12segmentation('/path/to/your/T1w.nii') directly, and see if you get the a similar error?

If you are also having trouble at the GannetLoad stage – might I suggest looking for another tool which is designed to work with non-edited data, and also has similar registration and segmentation abilities? (one which comes to mind is Osprey)


Hi @SanderB,

I recommend using Gannet’s CoRegStandAlone function. With this function, you provide a list of the MRS files and a list of the T1 files, and it performs the coregistration and segmentation. Details and example command are here: CoRegStandAlone



Hi @SanderB,

As @Meredith mentioned, you can use CoRegStandAlone.m for your task. Since this is 7T Philips data, please get in touch should you have issues loading the data as 7T Philips (I assume STEAM or PRESS?) data is treated differently than 3T Philips data in Gannet.


Hello @Meredith,

This seems perfect in my case. Thank you very much!


1 Like

Hi Mark,

Thank you for the reply. Currently I am trying to use CoRegStandAlone.m. However I am having difficulty loading in my SPAR/SDAT data. The codes that I tried are posted below.


data_dir = ‘/Data PVC/Gannet/Gannet-main/Gannet-main/testdata/test’;

metab = {‘test_SVS_14_2_raw_act.sdat’};
metab = fullfile(data_dir, metab);

water = {‘test_SVS_14_2_raw_ref.sdat’};
water = fullfile(data_dir, water);

anat = {‘test_T1w.nii’};
anat = fullfile(data_dir, anat);

MRS = CoRegStandAlone({metab,water},{anat,anat});

Example 2:

MRS = CoRegStandAlone({‘test_SVS_4_2_raw_act.SDAT’,‘test_SVS_4_2_raw_ref.SDAT’},{‘test_T1w.nii’,‘test_T1w.nii’});

Both of these codes do not seem to work. As I do not understand how I can use both my SPAR and SDAT data, which I feel like is needed to make this work properly.

This is listed inside the function:
% MRS_struct = CoRegStandAlone(metabfile, struc)

% metabfile - cell array containing the path(s) to an MRS data file
% in one of the following formats: Philips SDAT/SPAR,
% Siemens TWIX (.dat), Siemens RDA (.rda), GE (.7), or
% DICOM (*.ima, *.dcm).

struc - cell array containing the path(s) to either a NIfTI
% file (*.nii) (for Philips and Siemens data) or a folder
% containing DICOMs (.*dcm) (for GE data).

Kind regards,


I forgot to post the error.

This is the error that I receive for both examples:

Error using fopen
First input must be a file name or a file identifier.

Error in PhilipsRead (line 12)
sparname = fopen(sparname,‘r’);

Error in CoRegStandAlone (line 104)
MRS_struct = PhilipsRead(MRS_struct, metabfile{ii});

Error in Main_script (line 39)
MRS = CoRegStandAlone({metab,water},{anat,anat});

Probably a matter of case sensitivity. Try renaming your .SPAR and .SDAT endings to .spar and .sdat, respectively. I’m sure Mark can fix this in the code, but this might do the trick for now.

The volumes for the metabolite and water acquisitions will also be the same (there is no correction for the chemical shift between them), so you don’t have to include the _ref files - just stick to the _act ones.

In Example 1, the input arguments metab, water, and anat are already cell arrays, so inputting {metab} or {anat} makes them a cell array of a cell array, which will lead to errors in Gannet.

In Example 2, as @admin mentioned, the water files (the _ref files) are not needed for CoRegStandAlone.m.

Try this code:

data_dir = '/Data PVC/Gannet/Gannet-main/Gannet-main/testdata/test';

metab = {'test_SVS_14_2_raw_act.sdat'};
metab = fullfile(data_dir, metab);

anat = {'test_T1w.nii'};
anat = fullfile(data_dir, anat);

MRS = CoRegStandAlone(metab, anat);

Also, make sure the accompanying *.SPAR files are in the same folder as the *.SDAT files.

1 Like

Thank you Mark,

This works perfectly. And the segmentation also works for most of them. Thank you again for providing this toolbox and the help.



Hi mark,

For confirmation of the voxel placement I am trying to compare screenshots and the gannet output of CoRegStandalone. However the screenshots are taken in a typical radiology image where Left = Right and Right = Left.

However Gannet produces an image where Left = Left and Right = Right. (example, not my own data)(Image 2)


Is there and option within gannet to flip this to a typical radialogy view? For better comparison of my data.

Kind regards,


This would require changing the code, specifically the geometry of the images and voxel masks. The simplest solution is to load the images and overlay the masks in an external program that can display in radiological convention.

Strongly recommend GitHub - xiangruili/dicm2nii: DICOM to NIfTI conversion, NIfTI tools