Created
November 12, 2016 13:47
-
-
Save ofgulban/46d5c51ea010611cbb53123bb5906ca9 to your computer and use it in GitHub Desktop.
Convert MINC files to Nifti using nibabel.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Convert minc to nifti format.""" | |
import os | |
import numpy as np | |
from nibabel import load, save, Nifti1Image | |
minc = load("/path/to/file.mnc.gz") | |
basename = minc.get_filename().split(os.extsep, 1)[0] | |
affine = np.array([[0, 0, 1, 0], | |
[0, 1, 0, 0], | |
[1, 0, 0, 0], | |
[0, 0, 0, 1]]) | |
out = Nifti1Image(minc.get_data(), affine=affine) | |
save(out, basename + '.nii.gz') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment