Segmenting with CAT12 becomes unresponsive

Dear BST Community,

I have a large dataset of individuals with MRIs and resting state EEG. For each individual, I want to first import and segment their T1 with CAT12 within Brainstorm, which I've scripted. However, something I've noticed mainly in this year, is that after about 10-12 participants, I begin running into JAVA heap memory issues. This occurs both on a Mac and Windows machine, and typically will occur after 10-12 participants. The first majority of participants will be segmented fine (with their files imported), but then the last couple of participants, their MRIs will be imported into the Brainstorm database, but just a few (and seemingly random grouping) of the CAT12 output files will be imported for the last 1 or 2 participants, before MATLAB simply becomes frozen/unresponsive.

Admittedly, this has been going on for a while now, but it was with smaller datasets, so I did not mind having to pick up from where it froze. However, I am now working on a dataset in the 100s of participants, and the freezing/restarting will prove to add a lot of wasted time.

I've followed the instructions for increasing the JAVA heap memory, but the issue persisted. I'm currently looking into preprocessing the MRIs on their own (with spm/cat12 batch and outside of Brainstorm, but I have no idea if that will overcome this issue). Any help or suggestions as to how to overcome this would be greatly appreciated.

Thank you,
Paul

Thank you for the details, we will try to replicate on our side to find the issue.

Is your script running with Brainstorm GUI open?
Can you try to run your script without GUI?

On Windows cmd
matlab . -batch "brainstorm C:\path\to\YOUR_SCRIPT.m"

On macOS (it should be something like)
matlab . -batch "brainstorm /path/to/YOUR_SCRIPT.m"

On the (Linux) Terminal:
matlab . -nodisplay -r "brainstorm /path/to/YOUR_SCRIPT.m"

Hi Raymundo,

Thank you for the response. I have indeed been running my scripts with the BST GUI open.

I now added this part to my script to specify the protocol since before I would manually switch to it with the GUI before running my script.

ProtocolName = 'CAT_Test';
% Get the protocol index
iProtocol = bst_get('Protocol', ProtocolName);
if isempty(iProtocol)
    error(['Unknown protocol: ' ProtocolName]);
end
% Select the current procotol
gui_brainstorm('SetCurrentProtocol', iProtocol);

I am trying to run it without the GUI, but am running into some issues. I first run the following in the MAC OS terminal (after changing directories to MATLAB_R2023a.app/bin/):

./matlab -batch "brainstorm nogui /Users/prabhjotdhami/Documents/Data Analysis/Youth_RS_2023/bst_testing_cat”

Unfortunately, I am having trouble running Brainstorm from the terminal. Below is the terminal output, where you can see BST stops for some reason.

BST> Starting Brainstorm:

BST> =================================

BST> Version: 24-Oct-2023

BST> Deleting old process reports...

BST> Loading configuration file...

BST> Initializing user interface...

2023-11-02 10:55:00.070 MATLAB_maci64[88215:3174487] CoreText note: Client requested name ".SFNS-Regular", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].

2023-11-02 10:55:00.070 MATLAB_maci64[88215:3174487] CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug.

2023-11-02 10:55:00.074 MATLAB_maci64[88215:3174487] CoreText note: Client requested name ".SFNS-Bold", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].

2023-11-02 10:55:00.084 MATLAB_maci64[88215:3174487] CoreText note: Client requested name ".SFNS-Regular", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].

2023-11-02 10:55:00.084 MATLAB_maci64[88215:3174487] CoreText note: Client requested name ".SFNS-Bold", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].

BST> Starting OpenGL engine... hardware

BST> Reading process folder...

BST> Loading current protocol...

PROGRESS> Set current protocol: Loading protocol...

PROGRESS> Unload all: Closing figures...

PROGRESS> Database explorer: Applying search...

BST> =================================

PROGRESS> Unload all: Closing figures...

PROGRESS> Database auto-save: Saving database...

BST> Brainstorm stopped.

Do you have any suggestions as to what I am doing wrong?

Thank you,
Paul

It looks like the issue is in the script.
I will be able to check on macOS next week

Thank you Raymundo, that would be greatly appreciated.

I was running into the same issues with CAT12 by just calling it within MATLAB (and with my own installation of SPM and using the SPM batch script has provided here: https://neuroimage.usc.edu/brainstorm/Tutorials/SegCAT12#SPM_batch). This was with MATLAB2023a. I decided to try segmenting my files again (with CAT12 with SPM) on MATLAB2022a, and it seems to be running fine (which may also be why I never experienced this issue until this year after upgrading to the 2023 version of Matlab). I'll take a closer look, but I wonder if it may be related to something to do with CAT12 and 2023 versions of MATLAB?