openneuropet / PET2BIDS

PET2BIDS helps you convert your PET data into BIDS! raw PET scanner files (e.g. ecat, dicom) and additional side files like .e.g excel sheets -- paper @JOSS https://doi.org/10.21105/joss.06067
https://pet2bids.readthedocs.io
MIT License
25 stars 20 forks source link

BUG: ecatpet2bids.py: negative values overflowing into positive ones #294

Closed nbeliy closed 4 months ago

nbeliy commented 4 months ago

Describe the bug Having an ECAT7 image with negative voxels (we have images reconstructed with FBP), the converted images contains only positive and very large values. Where spm's spm_ecat2nifti shows -2266.532958984375, ecatpet2bids produces 72494.859375

Positive values are the same, comparing with spm.

To Reproduce Convert ECAT image with negative values

Expected behaviour The negative values must be conserved.

Desktop (please complete the following information): Python 3.8.10 pypet2bids==1.3.9

mnoergaard commented 4 months ago

Hi @nbeliy. Thanks for raising this issue. We are of aware of this bug for the python part (https://github.com/openneuropet/PET2BIDS/issues/272), and are currently working on a solution. Matlab version works fine.

nbeliy commented 4 months ago

Ah, ok.

If it could help, problem may come from read_ecat.py:408, where data type 6 is interpreted as unsigned int16 (>H), while nibabel interprets as signed int16. SPM treats all data types as int16.

Nibabel reference some documents on Turku website, but the documents are no longer there.

As I'm here, the lines []():

    if ".gz" in ecat_file:
        ecat_file = decompress(ecat_file)

may cause a crash if the name of file contains .gz somewhere in the middle. It will be better to replace the if by:

    if ecat_file.endswith(".gz"):
        ecat_file = decompress(ecat_file)
bendhouseart commented 4 months ago

Duplicate issue to #272, closing.