rordenlab / MRIcroGL

v1.2 GLSL volume rendering. Able to view NIfTI, DICOM, MGH, MHD, NRRD, AFNI format images.
https://www.nitrc.org/plugins/mwiki/index.php/mricrogl:MainPage
Other
204 stars 32 forks source link

MRIcroGL handling complex (MRS) data #34

Closed wtclarke closed 2 years ago

wtclarke commented 2 years ago

Dear Chris,

Would it be possible to include better handling for complex data types in MRIcroGL?

Recently someone reported that MRIcro couldn't load NIfTI-MRS formatted data (created by spec2nii), see spec2nii issue #23. From testing I believe that this arises from MRS data being complex. MRIcroGL reports 'unable to load "my_complex_data.nii.gz"', but will load the same file when the data is non-complex.

Your handling of a 4th time dimension means that (somewhat) meaningful viewing of MRS data can almost be handled. Would you consider loading and simply taking the absolute or real part of the data?

I've attached two very simple files that I tested with. These have 1x1x1x100 random real/complex float data, and in addition a header extension such as NIfTI-MRS uses. n2_float_4dim_hdr.nii.gz n2_cfloat_4dim_hdr.nii.gz

neurolabusc commented 2 years ago

@wtclarke can you try out the macOS build here which will report v1.2.20211007 (or if you prefer Linux/Windows tell me). This should convert the complex value to the absolute.

  1. When a user opens up complex data in FSLeyes, choosing the Time series option from the View menu shows the real component, rather than the absolute. It is easy to show either, but it might be nice to be consistent across tools. Do you have any preference between these two?
  2. I do think most users will be better served with your MRSView FSLeyes plugin. Both tools are free and open source, so users should choose the best tool for the job. It is easy for a developer to add features, but the user interface starts to become very daunting. My sense is that while MRIcroGL and FSLeyes overlap in basic functionality, they serve different niches and overall they complement each other rather than compete.
  3. Your exemplar datatype is in DT_COMPLEX128. Do any of your tools generate DT_COMPLEX64 or DT_COMPLEX256? If so, can you provide examples. Usually I can create different datatypes with fslmaths using the -odt option, but the current version of fslmaths does not support complex data types.

This may reflect the fact that I am using a ARM-based CPU, but I was not able to install the fsleyes-plugin-mrs, and the fmrib gitlab site does not allow outsiders to post issues.

$sysctl -n hw.model
MacBookAir10,1
$ sw_vers
ProductName:    macOS
ProductVersion: 11.5.2
BuildVersion:   20G95
$ conda install -c conda-forge fsleyes-plugin-mrs
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): | WARNING conda.models.version:get_matcher(537): Using .* with relational operator is superfluous and deprecated and will be removed in a future version of conda. Your spec was 2.*, but conda is ignoring the .* and treating it as 2
WARNING conda.models.version:get_matcher(537): Using .* with relational operator is superfluous and deprecated and will be removed in a future version of conda. Your spec was 3.6.*, but conda is ignoring the .* and treating it as 3.6
WARNING conda.models.version:get_matcher(537): Using .* with relational operator is superfluous and deprecated and will be removed in a future version of conda. Your spec was 1.*, but conda is ignoring the .* and treating it as 1
done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: / 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed                                                                                                                                                                      

UnsatisfiableError: The following specifications were found to be incompatible with each other:

Output in format: Requested package -> Available versions
wtclarke commented 2 years ago

That version works as you said it would. Thank you! In answer to your questions:

  1. I think your suggestion of being consistent between the tools makes sense. In which case, can you make it display the real?
  2. I completely understand your point. Displaying spectroscopic data fully would be a significant additional feature to add, and unless you would like to, I'm certainly not requesting that. I was simply hoping to encourage support for complex NIfTI files, beyond throwing slightly cryptic errors for users.
  3. The NIfTI-MRS standard allows for all three complex types as defined in the NIfTI Header. So in theory, yes, all three type could be around. However, all my tools generate DT_COMPLEX128, and I just found that Nibabel only supports DT_COMPLEX128 and DT_COMPLEX64. I've therefore attached two files with the same data, stored as the two types that Nibabel can generate. n2_cfloat64_4dim_hdr.nii.gz n2_cfloat128_4dim_hdr.nii.gz

Thanks for the report with the plugin. We do need to sort the issue tracking (I think a new solution is on its way for FSL tools in general), or I need to make a GitHub mirror. Can I ask how the conda environment was set up, and what version of python? conda list should provide the info.

neurolabusc commented 2 years ago

@wtclarke thanks for the examples. I updated the macOS dmg to display there real component for DT_COMPLEX64 (32) and DT_COMPLEX128 (1792) datatypes. Unless there are any concerns, this will be part of the next release for all platforms.

It does not support DT_COMPLEX256 or DT_FLOAT128, but nor does AFNI. Modern native CPU/GPU instructions (CUDA, Neon, AVX, etc) limit themselves to double precision (64-bit floats), and this precision seems beyond the SNR of MRS datasets.

$ conda --version                                  
conda 4.11.0
$ conda list                                       
# packages in environment at /Users/chrisrorden/miniforge3:
#
# Name                    Version                   Build  Channel
brotlipy                  0.7.0           py39h5161555_1003    conda-forge
bzip2                     1.0.8                h3422bc3_4    conda-forge
ca-certificates           2021.10.8            h4653dfc_0    conda-forge
certifi                   2021.10.8        py39h2804cbe_1    conda-forge
cffi                      1.15.0           py39h52b1de0_0    conda-forge
charset-normalizer        2.0.10             pyhd8ed1ab_0    conda-forge
codespell                 2.1.0                    pypi_0    pypi
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
conda                     4.11.0           py39h2804cbe_0    conda-forge
conda-package-handling    1.7.3            py39h5161555_1    conda-forge
cryptography              36.0.1           py39hfb8cd70_0    conda-forge
cycler                    0.10.0                   pypi_0    pypi
cython                    0.29.26                  pypi_0    pypi
dcmstack                  0.8.0                    pypi_0    pypi
dicom                     0.9.9.post1              pypi_0    pypi
dicom2nifti               2.3.0                    pypi_0    pypi
euclid                    1.2                      pypi_0    pypi
glcontext                 2.3.4                    pypi_0    pypi
idna                      3.1                pyhd3deb0d_0    conda-forge
imageio                   2.13.3                   pypi_0    pypi
joblib                    1.1.0              pyhd8ed1ab_0    conda-forge
kiwisolver                1.3.2                    pypi_0    pypi
libblas                   3.9.0           12_osxarm64_openblas    conda-forge
libcblas                  3.9.0           12_osxarm64_openblas    conda-forge
libcxx                    12.0.1               h168391b_1    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libgfortran               5.0.0.dev0      11_0_1_hf114ba7_23    conda-forge
libgfortran5              11.0.1.dev0         hf114ba7_23    conda-forge
liblapack                 3.9.0           12_osxarm64_openblas    conda-forge
libopenblas               0.3.18          openmp_h5dd58f0_0    conda-forge
libzlib                   1.2.11            hee7b306_1013    conda-forge
llvm-openmp               12.0.1               hf3c4609_1    conda-forge
matplotlib                3.4.3                    pypi_0    pypi
moderngl                  5.6.4                    pypi_0    pypi
ncurses                   6.2                  h9aa5885_4    conda-forge
networkx                  2.6.3                    pypi_0    pypi
nibabel                   3.2.1                    pypi_0    pypi
numpy                     1.22.0           py39h61a45d2_0    conda-forge
openssl                   1.1.1l               h3422bc3_0    conda-forge
packaging                 21.0                     pypi_0    pypi
pandas                    1.3.2                    pypi_0    pypi
pillow                    8.3.2                    pypi_0    pypi
pip                       21.3.1             pyhd8ed1ab_0    conda-forge
pycosat                   0.6.3           py39h5161555_1009    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pydicom                   2.2.2              pyh6c4a22f_0    conda-forge
pyfqmr                    0.1.1                    pypi_0    pypi
pyglet                    1.5.21                   pypi_0    pypi
pyopenssl                 21.0.0             pyhd8ed1ab_0    conda-forge
pyparsing                 2.4.7                    pypi_0    pypi
pysocks                   1.7.1            py39h2804cbe_4    conda-forge
python                    3.9.9           h70c1b39_0_cpython    conda-forge
python-dateutil           2.8.2                    pypi_0    pypi
python_abi                3.9                      2_cp39    conda-forge
pytz                      2021.1                   pypi_0    pypi
pywavelets                1.2.0                    pypi_0    pypi
readline                  8.1                  hedafd6a_0    conda-forge
requests                  2.27.1             pyhd8ed1ab_0    conda-forge
ruamel_yaml               0.15.80         py39h5161555_1006    conda-forge
scikit-image              0.19.0                   pypi_0    pypi
scikit-learn              1.0.2            py39hef7049f_0    conda-forge
scipy                     1.7.3            py39h5060c3b_0    conda-forge
seaborn                   0.11.2                   pypi_0    pypi
setuptools                60.5.0           py39h2804cbe_0    conda-forge
simpleitk                 2.1.1                    pypi_0    pypi
six                       1.16.0             pyh6c4a22f_0    conda-forge
sqlite                    3.37.0               h72a2b83_0    conda-forge
threadpoolctl             3.0.0              pyh8a188c0_0    conda-forge
tifffile                  2021.11.2                pypi_0    pypi
tk                        8.6.11               he1e0b03_1    conda-forge
torch                     1.10.1                   pypi_0    pypi
tqdm                      4.62.3             pyhd8ed1ab_0    conda-forge
trimesh                   3.9.36                   pypi_0    pypi
typing-extensions         4.0.1                    pypi_0    pypi
tzdata                    2021e                he74cb21_0    conda-forge
urllib3                   1.26.8             pyhd8ed1ab_1    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
wxpython                  4.1.1                    pypi_0    pypi
xz                        5.2.5                h642e427_1    conda-forge
yaml                      0.2.5                h3422bc3_2    conda-forge
zlib                      1.2.11            hee7b306_1013    conda-forge
pauldmccarthy commented 2 years ago

Hi @neurolabusc and @wtclarke, M1 conda packages have not yet been built for FSLeyes, although I think most if not all dependencies should be available by now, so I should be able to get M1 packages built for the next version.

In the meantime, you should be able to install FSLeyes on an M1 platform by using an x86-based conda distribution.

neurolabusc commented 2 years ago

OK. Closing the issue for both MRIcroGL and the FSLeyes plugin.

wtclarke commented 2 years ago

Thanks @neurolabusc and @pauldmccarthy !