Error with cs_convert when performing MRI segmentation

Hello,

I am performing an MRI segmentation using CAT12 and I get this error message right as it is about to finish:

***************************************************************************
** Error: Line 96:   * 
** Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
** 
** Call stack:
** >cs_convert.m at 96
** >in_tess.m at 160
** >import_surfaces.m at 147
** >import_anatomy_cat_2020.m>ImportCatSurf at 587
** >import_anatomy_cat_2020.m at 288
** >import_anatomy_cat.m at 28
** >process_segment_cat12.m>Compute at 382
** >process_segment_cat12.m>ComputeInteractive at 442
** >process_segment_cat12.m at 28
** >bst_call.m at 28
** >tree_callbacks.m>@(h,ev)bst_call(@process_segment_cat12,'ComputeInteractive',iSubject,iAnatomy) at 3085
** 
***************************************************************************

Do you know why this might be happening? The MRI is a T1 NIFTI file with fiducial points marked. Interestingly, after the failed segmentation it becomes somehow corrupted and cannot be visualized anymore (the error message displayed is the same as above) so I have to import it and mark the fiducials again.

Thank you very much in advance for the help.

P.S. For clarification, I have tried this both with and without MNI space normalization, and it gives me the same error.

Are you using the latest version of SPM12 (7771) and CAT12 (2170)?

I would need access to the data in order to identify the problem and try to fix it.
Could you please share:

  1. The original MRI after importing it into the database:
    • Create a new subject
    • Import the MRI, set the fiducials (if this is what you did before)
    • Right-click on the MRI file in the database > File > Show in file explorer
    • Zip the file, upload it somewhere and post the download link here (or send it to me as a private message on this forum if it is not de-identified)
  2. The result of the CAT12 segmentation:
    • Right-click on the MRI you just imported > MRI segmentation > CAT12 > ... (as you did before)
    • Immediately after you get the error message you reported above (do not close Brainstorm, as it would delete the CAT12 output):
    • Zip the folder $HOME/.brainstorm/tmp/cat12
    • Upload it somewhere and share the download link.

Thanks

Hello @Francois, thank you very much for your quick reply. I am indeed using the latest versions of SPM12 and CAT12. I will send you the links for the things you asked as soon as the segmentation finishes and I upload it all to the cloud.

EDIT: as an aside, I have a question somehow related to this. I have many subjects that need MRI segmentation, but each one takes a relatively long time, even though my system still has lots of resources available (both CPU and RAM). Is it possible to open multiple instances of Matlab and then Brainstorm and do the segmentations for multiple subjects in the same database in parallel, or will this corrupt the database somehow?

UPDATE: I think this might have to do with a faulty img + hdr to nii conversion. I used Matlab's niftiread and niftiwrite functions to do this and it fails, but if I do the conversion with MRIcron this error (apparently) does not happen...

Thank you for the example files.
I understood that the CAT12 and SimNIBS segmentation processes were not working properly if the .nii files missed both the sform and qform matrices - which is the case of your .nii volume.

I tried to fix this issue with this commit: https://github.com/brainstorm-tools/brainstorm3/commit/672f30b80418f5f03787535baaa04186a5eeebf0

Update Brainstorm, then try running again CAT12.
You should see close to the start of the process the message:
BST> Adding default world transformation to MRI...
I haven't executed the entire CAT12 segmentation, so maybe there are other related problems downstream.
Please let me know if this is sufficient to fix the problem.

.

Is it possible to open multiple instances of Matlab and then Brainstorm and do the segmentations for multiple subjects in the same database in parallel, or will this corrupt the database somehow?

No, the temporary folder for CAT12 is in your user folder: $HOME/.brainstorm/tmp/cat12.
To execute multiple instances of CAT12 from Brainstorm, you need to run them from different users.
If you are interested in large-scale computation with CAT12, you can either script the computation from Brainstorm and let it run sequentially overnight, or execute multiple CAT12 instances directly (not through Brainstorm) in parallel and then import sequentially the CAT12 output folders as full anatomy folders into the Brainstorm database.

Thank you very much for the quick reply and fix! I ran the full segmentation on the same MRI and it was executed to the end, so it appears to be fixed. I will inform you again if I run into further complications. Thanks again!

(Please feel free to move this to the bugs section)

I automated all my segmentations into a single script, but from time to time I get this error message and I have to run the script again from the last completed subject. This happens in 3 different systems, do you know why this might be happening? it has nothing to do with specific MRIs since running the script again from the last completed subject does not lead to that error in the same T1s.

Exception in thread "Explorer NavigationContext request queue": java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "AWT-EventQueue-0": java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "AWT-EventQueue-0": java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "AWT-EventQueue-0": java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "AWT-EventQueue-0": java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "AWT-EventQueue-0": java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "AWT-EventQueue-0": java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "AWT-EventQueue-0": java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "AWT-EventQueue-0": java.lang.OutOfMemoryError: GC overhead limit exceeded

Increase the Java heap size:
https://www.mathworks.com/help/matlab/matlab_external/java-heap-memory-preferences.html

Thank you very much for the quick reply!

I recently changed the way the temporary files are handled. Now each instance of CAT12 would create a separate subfolder in the temporary folder (cat12_yymmdd_hhmmss), making it possible to have multiple sessions running simultaneously. See these sections for more information:

However, running multiple instances of CAT12 in parallel is not necessarily faster:
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#Parallel_processing

Hi, thank you very much for this! It will really come in handy the next time!