Down-sample mri T1 image in python with Nipy
Asked Answered
D

1

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.

Desiccate answered 6/12, 2018 at 0:40 Comment(1)
Can you let me know how do we find the modality of a MRI image using Python? Can you please help me with this? #56698587Ciccia
W
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

Walburga answered 2/1, 2019 at 17:59 Comment(1)
Alex - Can you help me with this post ? #56698587Ciccia

© 2022 - 2024 — McMap. All rights reserved.