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 hidden or 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') |
Author
That's right. Thanks for your comment and pointer @neurolabusc !
I saw that I have created this gist 9 years ago, time flies by.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an elegant minimal gist, but by using an identity matrix for the affine the spatial orientation is lost. The script mni2nii.py extends this gist to include spatial transformations.