[Neuroimaging] Reading a byte stream into nibabel

Christopher Markiewicz effigies at bu.edu
Wed Feb 22 14:51:43 EST 2017

Hi Valerie,

Assuming that it's not gzipped, you can do something like:

    from io import BytesIO
    from nibabel import FileHolder, Nifti1Image
    fh = FileHolder(fileobj=BytesIO(input_stream))
    img = Nifti1Image.from_filemap({'header': fh, 'image': fh})

If it is gzipped, adjust accordingly:

    from gzip import GzipFile
    fh = FileHolder(fileobj=GzipFile(fileobj=BytesIO(input_stream)))


On Wed, Feb 22, 2017 at 2:22 PM, val hs <valeriehayot at gmail.com> wrote:

> Hi,
> I am trying to process nifti-1 images using HDFS and I was wondering if it
> was possible to read an image's byte stream into nibabel as I want to avoid
> saving the image locally.
> Thanks,
> Valerie
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20170222/7cacba8a/attachment.html>

More information about the Neuroimaging mailing list