11
11
import numpy as np
12
12
import h5py
13
13
import warnings
14
+ from collections import namedtuple
14
15
from nibabel .loadsave import load as _nbload
15
16
from nibabel import funcs as _nbfuncs
16
17
from nibabel .nifti1 import intent_codes as INTENT_CODES
@@ -92,7 +93,7 @@ def shape(self):
92
93
class ImageGrid (SampledSpatialData ):
93
94
"""Class to represent spaces of gridded data (images)."""
94
95
95
- __slots__ = ["_affine" , "_inverse" , "_ndindex" ]
96
+ __slots__ = ["_affine" , "_inverse" , "_ndindex" , "_header" ]
96
97
97
98
def __init__ (self , image ):
98
99
"""Create a gridded sampling reference."""
@@ -101,6 +102,7 @@ def __init__(self, image):
101
102
102
103
self ._affine = image .affine
103
104
self ._shape = image .shape
105
+ self ._header = getattr (image , "header" , None )
104
106
105
107
self ._ndim = getattr (image , "ndim" , len (image .shape ))
106
108
if self ._ndim >= 4 :
@@ -117,6 +119,11 @@ def affine(self):
117
119
"""Access the indexes-to-RAS affine."""
118
120
return self ._affine
119
121
122
+ @property
123
+ def header (self ):
124
+ """Access the original reference's header."""
125
+ return self ._header
126
+
120
127
@property
121
128
def inverse (self ):
122
129
"""Access the RAS-to-indexes affine."""
@@ -293,12 +300,15 @@ def apply(
293
300
)
294
301
295
302
if isinstance (_ref , ImageGrid ): # If reference is grid, reshape
303
+ hdr = None
304
+ if _ref .header is not None :
305
+ hdr = _ref .header .copy ()
306
+ hdr .set_data_dtype (output_dtype )
296
307
moved = spatialimage .__class__ (
297
308
resampled .reshape (_ref .shape ).astype (output_dtype ),
298
309
_ref .affine ,
299
- spatialimage . header
310
+ hdr ,
300
311
)
301
- moved .set_data_dtype (output_dtype )
302
312
return moved
303
313
304
314
return resampled
0 commit comments