# Create nifti volume with nifti images that have different voxel size

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 follow 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)

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,M)

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 preserve 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), and then stack the 3D volumes together?