0

im trying to load my image with nibabel, but I keep getting an "ImageFileError". kindly note that my image is in .gz format. I get the error "file is not a gzip file":

1

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
a__ys
  • 28
  • 5
  • `assert os.path.exists(image_path), os.getcwd()` – Christoph Rackwitz Oct 16 '22 at 14:45
  • Please [don’t post images of code, error messages, or other textual data.](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557) – tripleee Oct 16 '22 at 16:25
  • Do you know the file exists? Do you know it is in fact gzip-compressed? Tell us; show us. Please [edit] your question to include all pertinent details. – tripleee Oct 16 '22 at 16:27

1 Answers1

0

I had the same issue for a subject from the ADNI (Alzheimer's Disease Neuroimaging Initiative) dataset.

What worked for me was to load it with SimpleITK and saving it again (overwriting) still with SimpleITK. Here's the code:

import SimpleITK as sitk

path_corrupted_nifti = "path/to/img.nii.gz"
sitk_img = sitk.ReadImage(path_corrupted_nifti)  # load with sitk
sitk.WriteImage(sitk_img, path_corrupted_nifti)  # overwrite

after doing this, I was able to load the volume also with nibabel

Tommaso Di Noto
  • 1,208
  • 1
  • 13
  • 24