Processing head model: Meshes intersecting

Hi,

I am working on source localizing EEG data to individual anatomical images. While my code runs successfully for some subjects, it consistently generates the same error for others. Could you please help me identify the cause of these issues with certain subjects? For your reference, I'm using MATLAB 2023a on a Mac with an M1 chip.

Thank you!

Have you checked if the surfaces for those subjects are in fact intersecting?

Verify visually if generated BEM surfaces intersect each other: display the Surfaces in a 3D view (double-click on them), then set different colors for the Surfaces and set their transparency to 0%. This evaluation is easier plotting 2 Surfaces at the time.

From visual inspection, it doesn't seem like there's intersection between bem_outerskull_1922V and bem_innerskull_2432V.

By the way, below is the code I'm using to generate BEM (sFiles2) and sFiles11 is the step where I'm getting the above error.
Thank you so much for your time to look into this!

---------------------------------------------------------------
sFiles = [];

%----------------------------------
% Start a new report (sFiles1)
% Process: Import anatomy folder
%----------------------------------
bst_report('Start', sFiles);

% freesurfer folder
AnatFolder      = [path_freesurfer '/' subject '/'];

sFiles1 = bst_process('CallProcess', 'process_import_anatomy', sFiles, [], ...
    'subjectname', subject, ...
    'mrifile',     {AnatFolder, 'FreeSurfer'}, ...
    'nvertices',   15000, ...
    'nas',         [SCS.NAS(1) SCS.NAS(2) SCS.NAS(3)], ...
    'lpa',         [SCS.LPA(1) SCS.LPA(2) SCS.LPA(3)], ...
    'rpa',         [SCS.RPA(1) SCS.RPA(2) SCS.RPA(3)], ...
    'ac',          [0, 0, 0], ...
    'pc',          [0, 0, 0], ...
    'ih',          [0, 0, 0]);

% Save and display report
ReportFile = bst_report('Save', sFiles1);
bst_report('Open', ReportFile);

%----------------------------------
% Start a new report (sFiles2)
% Process: Generate BEM surfaces
%----------------------------------
sFiles2 = bst_process('CallProcess', 'process_generate_bem', [], [], ...
    'subjectname', subject, ...
    'nscalp',      1922, ...
    'nouter',      1922, ...
    'ninner',      2432, ...
    'thickness',   4);

(....)
%------------------------------------------------------
% Process: Low-pass:70Hz
%------------------------------------------------------
sFiles6 = bst_process('CallProcess', 'process_bandpass', sFiles5, [], ...
    'sensortypes', 'MEG, EEG', ...
    'highpass',    0, ...
    'lowpass',     70, ...
    'tranband',    0, ...
    'attenuation', 'strict', ...  % 60dB
    'ver',         '2019', ...  % 2019
    'mirror',      0, ...
    'read_all',    0);

(...)
%------------------------------------------------------
% Process: Compute head model
%------------------------------------------------------
sFiles11 = bst_process('CallProcess', 'process_headmodel', sFiles6, [], ...
    'Comment',     '', ...
    'sourcespace', 1, ...  % Cortex surface
    'meg',         3, ...  % Overlapping spheres
    'eeg',         3, ...  % OpenMEEG BEM
    'ecog',        2, ...  % OpenMEEG BEM
    'seeg',        2, ...  % OpenMEEG BEM
    'openmeeg',    struct(...
    'BemFiles',     {{}}, ...
    'BemNames',     {{'Scalp', 'Skull', 'Brain'}}, ...
    'BemCond',      [1, 0.0125, 1], ...
    'BemSelect',    [1, 1, 1], ...
    'isAdjoint',    0, ...
    'isAdaptative', 1, ...
    'isSplit',      0, ...
    'SplitLength',  4000), ...
    'channelfile', '');

After the

** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
** !!!!!!!!!!! WARNING !!!!!!!!!!!
** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

It is indicated that one of intercepting mesh is ID : 1 which correspond to the bem_outerskull, the other intercepting mesh is not visible in the shared error message.

Please provide the entire error message.

Since it bem_outerskull it could have interceptions with either bem_head or bem_innerskull.

The code seems fine, and does not seems relevant to the problem with the intersecting meshes

Please find the entire error message attached below:

Hi, Thanks for your input in advance. Is there a way I can override this error message to continue or resolve the intersection?

Thanks for sharing the entire error message.
The intersection is between the meshes bem_outerskull (ID1) and bem_innerskull (ID2)

Which version of Brainstorm are you using?
Last year on March we added the option to also compute BEM meshes using FieldTrip.
You may want to check this other method as a solution for the BEM meshes intersection

Another approach to fix the intersection will be:

If it crashes with BEM surfaces generated with Brainstorm, try increasing the number of vertices on the various layers, or try different combination of values for the various layers.

https://neuroimage.usc.edu/brainstorm/Tutorials/TutBem#Errors

1 Like

Hi, increasing the number of vertices on the outer and inner layers worked out!! Thank you so much for your help!