0

I have a .nii file and I've tried to convert it to 2d sliced tiff file, this is what I do:

import nibabel as nib
import numpy as np
from tifffile import imsave
import tifffile as tiff

#load nii
a = nib.load('/a.nii').get_fdata()
print(np.shape(a)) #output: (512, 512, 300)

#some process need to be done(?)

#right away save the a into tiff file 
imsave('/2da.tiff', a)

at first I thought above process will work but when i load the tiffile it is still in 3d dim

tiffedA = tiff.imread('/2da.tiff')
print(tiddefA) #output: (512, 512, 300)

I expected the shape will be (300, 512, 512). I realized there is some needed process first but I don't know how, any idea to covert this 3d .nii to 2d sliced .tif in the right way?

timrau
  • 22,578
  • 4
  • 51
  • 64
  • Why do you expect reading back a (300, 512, 512) array after writing a (512, 512, 300) array? The (512, 512, 300) array is stored as a 512 pages of (512, 300). – cgohlke Jun 09 '22 at 03:23
  • from my understanding .tif file pages is in the front not in the back (?), when i open my (512, 512, 300) with imageJ, image j will read that my picture have 512 slide with 512 x 300 size (where it should be 300 slide, with 512 x 512 size) – M Hamid Asn Jun 09 '22 at 04:12

0 Answers0