I have a io.ByteIO object which represent an uploaded image (.nii), is there a way to obtain an simpleITK object from it ? A bad workaround would be to write the file then read it with simpleITK
Unfortunately SimpleITK's Image IO doesn't work on streams. It will only read from files.
It looks like you could use nibabel to get the read the image from your stream. Then convert it to a numpy array, and then convert the numpy to SimpleITK. It's ugly but at least you're not going back to disk.
Here's a post on reading the stream in nibabel: https://mail.python.org/pipermail/neuroimaging/2017-February/001345.html
Here's how to go from nibabel to numpy: How to convert Nifti file to Numpy array?
And then with the numpy array, you'd call SimpleITK.GetImageFromArray
to create the SimpleITK image.
These steps would not preserve any of the Image meta-information, so you'd have to copy over all the things like image spacing, origin and direction.