Sct_maths does not handle multi-echo data as expected. (or pebcac)

Dear SCT Devs!

I ran across the following problem:

When adding two multi-echo scans together, the resulting image is not a multi-echo scan, but the sum of both scans and all their echoes, as a single echo scan. In other words, the sum of two 4D acquisitions is not a 4D image, but a 3D one.

I expected the behaviour to work as fls_maths does, eg the sum of a 6-echo MGRE_1 with another 6-echo MGRE_2 is a new 6-echo MGRE, where for each echo, the signal intensity is for each echo is the sum of the signal in MGRE_1 for that echo, and MGRE_2 for the same echo.

Compare the signal intensity and size of the SCT version:
danielpapp@Daniels-MacBook-Pro SCT_maths_test % sct_maths -i ME_scan_1.nii.gz -add ME_scan_2.nii.gz -o out_SCT.nii.gz

image
image

To the output of the FSL version:
danielpapp@Daniels-MacBook-Pro SCT_maths_test % fslmaths ME_scan_1 -add ME_scan_2 out_fsl
image
image

Note that this issue arises when no second image is supplied. The command of
sct_maths -i ME_scan_1.nii.gz -add 0 -o out_SCT_addzero.nii.gz
likewise results in a summation along the 4th (echo) dimension.

Is this behaviour intended? Is it a bug? Is there a flag that toggles between this behaviour and 4D behaviour?

Best

Daniel

Relevant stats:

SCT dependencies:

sct_check_dependencies 
--
SCT info:
- version: git-master-dab0baec2b19c41d7e60405d2307a7f33d80411b
- path: /Users/danielpapp/spinalcordtoolbox
OS: osx (Darwin-21.4.0-x86_64-i386-64bit)
CPU cores: Available: 16, Used by ITK functions: 16
RAM: Total: 32768MB, Used: 15582MB, Available: 15380MB
Check Python executable.............................[OK]
  Using bundled python 3.6.13 |Anaconda, Inc.| (default, Feb 23 2021, 12:58:59) 
[GCC Clang 10.0.0 ] at /Users/danielpapp/spinalcordtoolbox/python/envs/venv_sct/bin/python
Check if data are installed.........................[OK]
Check if colored is installed.......................[OK] (1.4.2)
Check if dipy is installed..........................[OK] (1.3.0)
Check if futures is installed.......................[OK]
Check if h5py is installed..........................[OK] (2.10.0)
Check if Keras (2.1.5) is installed.................[OK] (2.1.5)
Check if ivadomed (2.7.2) is installed..............[OK] (2.7.2)
Check if matplotlib is installed....................[OK] (3.3.4)
Check if nibabel is installed.......................[OK] (3.2.1)
Check if numpy is installed.........................[OK] (1.19.5)
Check if onnxruntime (1.4.0) is installed...........[OK] (1.4.0)
Check if pandas is installed........................[OK] (1.1.5)
Check if psutil is installed........................[OK] (5.8.0)
Check if pyqt5 (5.11.3) is installed................[OK] (5.11.3)
Check if pytest is installed........................[OK] (6.2.2)
Check if pytest-cov is installed....................[OK] (__version__ = '2.11.1')
Check if raven is installed.........................[OK]
Check if requests is installed......................[OK] (2.25.1)
Check if requirements-parser is installed...........[OK] (0.2.0)
Check if scipy is installed.........................[OK] (1.5.4)
Check if scikit-image is installed..................[OK] (0.17.2)
Check if scikit-learn is installed..................[OK] (0.24.1)
Check if tensorflow (1.5.0) is installed............[OK] (1.5.0)
Check if torch (1.5.0) is installed.................[OK] (1.5.0)
Check if torchvision (0.6.0) is installed...........[OK] (0.6.0)
Check if xlwt is installed..........................[OK] (1.3.0)
Check if tqdm is installed..........................[OK] (4.59.0)
Check if transforms3d is installed..................[OK] (0.3.1)
Check if urllib3 is installed.......................[OK] (1.26.3)
Check if pytest_console_scripts is installed........[OK]
Check if spinalcordtoolbox is installed.............[OK]
Check ANTs compatibility with OS ...................[OK]
Check PropSeg compatibility with OS ................[OK]
Check if DISPLAY variable is set....................[OK]
Check if figure can be opened with PyQt.............[OK]

OS version:
MacOS Monterey 12.3.1

FSL version:
6.0.4


Data

Hi @Daniel_Papp,

Thank you for reporting this bug! :slightly_smiling_face:

I have opened an issue on SCT’s GitHub repository for further investigation and debugging. I will reply to this forum post to let you know when a fix has been identified and included in SCT.

Kind regards,
Joshua

Hello! I just wanted to inform you that this feature has now been introduced as of SCT v5.7. :tada: