[Neuroimaging] nibabel.filebasedimages.ImageFileError for large label files

Christopher Markiewicz markiewicz at stanford.edu
Tue Sep 28 11:17:57 EDT 2021

Hi Paul,

Is it possible that the file is not actually gzipped? This is the most common cause of this error that I've seen.


From: Neuroimaging <neuroimaging-bounces+markiewicz=stanford.edu at python.org> on behalf of Paul Reiners via Neuroimaging <neuroimaging at python.org>
Sent: Tuesday, September 28, 2021 10:07
To: neuroimaging at python.org
Cc: Paul Reiners
Subject: [Neuroimaging] nibabel.filebasedimages.ImageFileError for large label files

I am getting the following error when loading a large labeled NIFTI file of size 14.4 MB.

    Traceback (most recent call last):
      File "/home/miran045/reine097/projects2/lab2im/lab2im/dcan/reproduce_load_error.py", line 7, in <module>
        img = nib.load(file_path)
      File "/home/miran045/reine097/.local/lib/python3.7/site-packages/nibabel/loadsave.py", line 55, in load
        raise ImageFileError(f'Cannot work out file type of "{filename}"')
    nibabel.filebasedimages.ImageFileError: Cannot work out file type of "/home/feczk001/shared/data/nnUNet/nnUNet_raw_data_base/nnUNet_raw_data/Task509_Paper/labelsTr1/1mo_sub-375518.nii.gz"

Here is the code:

    import nibabel as nib


    file_path = '/home/feczk001/shared/data/nnUNet/nnUNet_raw_data_base/nnUNet_raw_data/Task509_Paper/labelsTr1/1mo_sub' \
    img = nib.load(file_path)

This does not happen when I try to open such files of smaller size (on the order of KB).  I can open this file in FreeSurfer FreeView without error and it looks fine.  This is happening with version 3.2.1 of NiBabel.

More information about the Neuroimaging mailing list