Mismatch in Expected Dimensions After Resampling NIfTI Image to 1x1x1 mm³ with Nibabel

Hi all!
I am working with NIfTI MRI images and trying to resample them to a resolution of 1x1x1 mm³ using the nibabel library in Python. Although the resampling process was completed without errors, the resulting image dimensions are not as expected.

Original Image Metadata:

  • Voxel size: 1.5x1.5x3 mm³
  • Image dimensions: 128x128x16 (Width x Height x Depth)

After resampling to a voxel size of 1x1x1 mm³, I expected the dimensions to be 192x192x48 voxels. However, I am getting dimensions of 193x200x114 voxels instead.

The resample_to_output function seems not to be considering the expected dimensions based on the new voxel size. What could be causing this discrepancy, and how can I correct the dimensions of the resampled image to match the intended size?

Here’s the relevant part of my code and the meta data of the original image Any help in understanding and fixing this issue would be greatly appreciated.

import nibabel as nib
from nibabel.processing import resample_to_output

# Load the original T1 image
img_t1 = nib.load('path_to_t1_image.nii.gz')

# Perform resampling
resampled_img_t1 = resample_to_output(img_t1, voxel_sizes=(1, 1, 1))

# Check the dimensions of the resampled image
print('Resampled T1 image shape:', resampled_img_t1.shape)

image

Hi @Hamza_Abbasi ,

I tried with an image of mine with your code and the result seems consistant:

  • input image: 2mm isotropic resolution, dimensions: 97, 115, 97
  • output image: 1mm isotropic resolution, dimensions: 193, 229, 193

Could you display the input and the output images to see if you can visualize what happened for your image? I guess a lot of padding zeros must have been added to the output since the bounding boxes between the input and output are so different!