7

I have a T1 image (NIFTI), already aligned, with dimension 121 x 145 x 121.
The image is loaded by nibabel. The voxel size is 1.5 x 1.5 x 1.5 mm.
I want to down-sample it to an image with 2.0 x 2.0 x 2.0 mm resolution and keep the images aligned.

I have little knowledge in MRI image manipulation. I couldn't find a clear tutorial.

How do I do that ? If you know any other Python library that can do it, it would also work.

RemiDav
  • 463
  • 3
  • 16
  • Can you let me know how do we find the modality of a MRI image using Python? Can you please help me with this? https://stackoverflow.com/questions/56698087/how-to-remove-a-modality-from-mri-image-python-nibabel – The Great Jun 21 '19 at 07:09

1 Answers1

6

I would suggest using Nibabel. It can downsample your nifti file in just a few lines.
Example to resample to an image to a voxel size of 2x2x2:

import nibabel
import nibabel.processing

input_path = r'/input/path/input_img.nii.gz'
output_path = r'/output/path/output_img.nii.gz'
voxel_size = [2, 2, 2]

input_img = nibabel.load(input_path)
resampled_img = nibabel.processing.resample_to_output(input_img, voxel_size)
nibabel.save(resampled_img, output_path)

Just update input_path and output_path to reflect your files. The second argument in the resample_to_output function (voxel_size) needs to either match the dimensions of your input or be a single value, nibabel will then assume you want the same voxel size for all dimensions.

Nibabel info:
Docs: http://nipy.org/nibabel/.
Install instructions: https://anaconda.org/conda-forge/nibabel

Alex
  • 1,064
  • 1
  • 11
  • 16
  • Alex - Can you help me with this post ? https://stackoverflow.com/questions/56698087/how-to-remove-a-modality-from-mri-image-python-nibabel – The Great Jun 21 '19 at 07:09