[Neuroimaging] How to read NifTi files using file-like objects?

Jon Deaton jdeaton at stanford.edu
Fri May 18 03:40:19 EDT 2018


Hello NiBabel mailing list,

I am a student working on the BraTS tumor segmentation challenge. I am
using NiBabel to read images but I am having difficulty loading NIfTI
formatted image files (*.nii) from file-like objects rather than by file
name. So far I have been using the typical interface in nibabel for loading
these files into memory:

import nibabel
data = nibabel.load(image_filename).get_data()

However, the trouble is that nibabel.load accepts filenames but not
file-like objects. I need to use a file-like object because I am loading
the data from Google Cloud Storage inside Google ML Engine, which requires
opening files using tensorflow.python.lib.io.file_io like so:

from tensorflow.python.lib.io import file_io
def load_nifti(image_filename):
    with file_io.FileIO(image_filename, mode='r') as fileobj:
        return # something that extracts the NifTI data from fileobj


I have had a lot of difficulty finding the correct interface in NiBabel to
do this so I was hoping that one of you might be able to help me accomplish
this task

Thank you,
Jon Deaton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20180518/4c13e7a8/attachment.html>


More information about the Neuroimaging mailing list