Skip to content

Instantly share code, notes, and snippets.

@ofgulban
Created November 12, 2016 13:47
Show Gist options
  • Save ofgulban/46d5c51ea010611cbb53123bb5906ca9 to your computer and use it in GitHub Desktop.
Save ofgulban/46d5c51ea010611cbb53123bb5906ca9 to your computer and use it in GitHub Desktop.
Convert MINC files to Nifti using nibabel.
"""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