Closed
Description
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?