Skip to content

FileBasedImage.serialize() #639

Closed
@effigies

Description

@effigies

Serializing an image to a bytes object via BytesIO has come up multiple times.

For reference, the following can be done (works for NIFTI; I'd have to check if it works for other images):

from io import BytesIO
import nibabel as nb

# Create an image `img`

bio = BytesIO()
file_map = {'image': nb.FileHolder(fileobj=bio), 'header': nb.FileHolder(fileobj=bio)}
img.to_file_map(file_map)

Would it be worth adding a .serialize() method (or similar) that returns a bytes serialization, rather than forcing users to go through this somewhat convoluted approach?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions