Skip to content

Commit 757636d

Browse files
committed
Reorder txyz to xyzt (nipy/nibabel#1412)
1 parent fb1b67a commit 757636d

File tree

8 files changed

+9
-0
lines changed

8 files changed

+9
-0
lines changed

Out/RASM1.nii.gz

289 KB
Binary file not shown.

Out/ax2.nii.gz

5.29 KB
Binary file not shown.

Out/axM1.nii.gz

101 KB
Binary file not shown.

Out/cor2.nii.gz

3.52 KB
Binary file not shown.

Out/corM1.nii.gz

54.7 KB
Binary file not shown.

Out/sag2.nii.gz

6.66 KB
Binary file not shown.

Out/sagM1.nii.gz

102 KB
Binary file not shown.

mnc2nii.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import nibabel as nib
44
import os
55
import sys
6+
import h5py
7+
import numpy as np
68

79
def convert_mnc_to_nifti(input_file, output_file=None):
810
if not input_file.endswith('.mnc'):
@@ -15,7 +17,14 @@ def convert_mnc_to_nifti(input_file, output_file=None):
1517
sys.exit(1)
1618
try:
1719
img = nib.load(input_file)
20+
header = img.header
1821
data = img.get_fdata()
22+
if data.ndim == 4:
23+
with h5py.File(input_file, "r") as f:
24+
# MINC2 stores dimensions under 'minc-2.0/image/0/image'
25+
dimorder = f["minc-2.0/image/0/image"].attrs["dimorder"].decode()
26+
if dimorder.startswith("time,"):
27+
data = np.transpose(data, (1, 2, 3, 0))
1928
affine = img.affine
2029
nifti_img = nib.Nifti1Image(data, affine)
2130
nifti_img.header.set_qform(affine)

0 commit comments

Comments
 (0)