From this question How to convert Nifti file to Numpy array?, I created a 3D numpy array of a nifti image. I made some modifications to this array (changed depth of the array by adding padding of zeroes).
How can I convert this array back to nifti image?
I tried:
imga = Image.fromarray(img, 'RGB')
imga.save("modified/volume-20.nii")
but it doesn't identify nii
extension. I also tried:
nib.save(img,'modified/volume-20.nii')
this is also not working, because img
must be nibabel.nifti1.Nifti1Image
if I want to use nib.save
feature. In both of the examples above img
is a 3D numpy array.