0

I have list of img/hdr file. Suppose that length of list is 50 and size of img is 60*60*60. I would like to convert it to Nifti1image whose size is (60*60*60*50).

import nibabel
import nipy
img_list=[]
for file in os.listdir(path):
    if file.endswith(".img"):
        temp=nibabel.load(os.path.join(path,file)
        img_list.append(temp)

by above program, I get the list I would like to convert to Nifti1image.Then I try

nipy.save(nipy.list_to_image(img_list),'sample.nii')

But i did not work. Could someone tell me how to do this in python?

kyabaria
  • 13
  • 4
  • Please, can you post the source code of your try? Can you be more specific about your problems? Thank you – alepuzio Dec 13 '18 at 10:49
  • What do you mean with "it did not work"? What happened? Was there an error? If so, post the error and the traceback. – AKX Dec 13 '18 at 11:28
  • (To begin with, there's a syntax error in your source; the `temp=` line is missing one closing paren.) – AKX Dec 13 '18 at 11:28
  • I think `nibabel.load` line (once you add the extra `)`) returns the NIfTI header. Your list will be filled with those. Please refer to the "images and memory documentation page of `nibabel` where it says "Nibabel does not load the image array from the proxy when you load the image. It waits until you ask for the array data. The standard way to ask for the array data is to call the `get_fdata()` method:". – alle_meije Aug 22 '22 at 07:09

0 Answers0