Skip to content

Commit 4703f4d

Browse files
authored
Merge pull request #1059 from vanandrew/cifti_fix
FIX: Reshape CIFTI-2 affines to 4x4 when encoded as row-major sequence
2 parents b8a1039 + 3fb8bc7 commit 4703f4d

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

nibabel/cifti2/parse_cifti2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ def flush_chardata(self):
538538
# conversion to numpy array
539539
c = BytesIO(data.strip().encode('utf-8'))
540540
transform = self.struct_state[-1]
541-
transform.matrix = np.loadtxt(c, dtype=np.float64)
541+
matrix = np.loadtxt(c, dtype=np.float64)
542+
transform.matrix = matrix.reshape(4, 4)
542543
c.close()
543544

544545
elif self.write_to == 'Label':

nibabel/cifti2/tests/test_cifti2io_header.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
datafiles = [DATA_FILE2, DATA_FILE3, DATA_FILE4, DATA_FILE5, DATA_FILE6]
4242

4343

44+
def test_space_separated_affine():
45+
img = ci.Cifti2Image.from_filename(
46+
pjoin(NIBABEL_TEST_DATA, "row_major.dconn.nii"))
47+
48+
4449
def test_read_nifti2():
4550
# Error trying to read a CIFTI-2 image from a NIfTI2-only image.
4651
filemap = ci.Cifti2Image.make_file_map()
1.84 KB
Binary file not shown.

0 commit comments

Comments
 (0)