0

I have a question about creating nifti volume for biomedical images

I usually use nibabel in python to load and create 3D nifti volume, but I recently have a group of images with alter slice thickness (odd number slices are 300 micron (0.3 mm/pixel) and even number slices are 60 micron (0.06 mm/pixel) in terms of thickness).

I usually use the following code to convert the nifti to create 3D numpy array file:

vol = np.zeros((864, 1296, 214))
count = 0
numbers = np.arange(1, 215).tolist()

for i in numbers:
    file_name = 'central_block_{}.nii'.format(i)
    
    img = nib.load(file_name)
    data = img.get_fdata()

    
    #test file size
    if img.shape[0] != vol.shape[0] or img.shape[1] != vol.shape[1]:
        print(file_name+' size is wrong. Resizing...')
        img = xform.resize(img,(vol.shape[0],vol.shape[1]))
    
    vol[:,:,count] = data

    count += 1

and what I usually do after 3D numpy array created:

M = [[0.0232,0,0,0], [0,0.0232,0,0], [0,0,0.232,0], [0,0, 0, 0.3]]

nii = nib.Nifti1Image(vol, None)

But in this case, I don't think the thickness information in each slice will preserve, and slice thickness voxel size will all get set to 0.232 instead.

Is there another way to stack nifti while preserving the individual slice voxel size? or do I have to first change the individual nifti thickness to have a uniform voxel size first? (like changing nifti of 0.3 mm/pixel to 0.01 mm/pixel with 30 in thickness and 0.06 mm/pixel to 0.01 mm/pixel with 6 in thickness)

Thanks in advance

fepegar
  • 595
  • 5
  • 15
LGUMI
  • 23
  • 4
  • as I know, Slice thickness is stored in the header of the nifti images. you can get the slice thickness by using `header.get_zooms()`. later you get volume size by accumelating the count of the slices with each thickness and multiply each count by each thickness. – Bilal Jul 09 '20 at 06:05
  • Thank you for your response! I might try to change the header so that each image have a common pixel size and then do the stacking. @BelalHomaidan – LGUMI Jul 09 '20 at 22:56
  • I'm afraid the nifti header does not have the flexibility to support a variable slice thickness. What's usually reported is the slice distance (how far the centres of successive slices are apart) which is computed as the slice thickness plus a possible slice gap. Could it be that your slice thickness varies, but your slice distance is constant? – alle_meije Sep 03 '21 at 14:32

0 Answers0