@@ -202,30 +202,24 @@ def inverse(self):
202
202
def ndindex (self ):
203
203
"""List the indexes corresponding to the space grid."""
204
204
if self ._ndindex is None :
205
- indexes = tuple ([np .arange (s ) for s in self ._shape ])
206
- self ._ndindex = np .array (np .meshgrid (* indexes , indexing = "ij" )).reshape (
207
- self ._ndim , self ._npoints
208
- )
205
+ indexes = np .mgrid [0 :self ._shape [0 ], 0 :self ._shape [1 ], 0 :self ._shape [2 ]]
206
+ self ._ndindex = indexes .reshape ((indexes .shape [0 ], - 1 )).T
209
207
return self ._ndindex
210
208
211
209
@property
212
210
def ndcoords (self ):
213
211
"""List the physical coordinates of this gridded space samples."""
214
212
if self ._coords is None :
215
- self ._coords = np .tensordot (
216
- self ._affine ,
217
- np .vstack ((self .ndindex , np .ones ((1 , self ._npoints )))),
218
- axes = 1 ,
219
- )[:3 , ...]
213
+ self ._coords = self .ras (self .ndindex )
220
214
return self ._coords
221
215
222
216
def ras (self , ijk ):
223
217
"""Get RAS+ coordinates from input indexes."""
224
- return _apply_affine (ijk , self ._affine , self ._ndim )
218
+ return _apply_affine (ijk , self ._affine , self ._ndim ). T
225
219
226
220
def index (self , x ):
227
221
"""Get the image array's indexes corresponding to coordinates."""
228
- return _apply_affine (x , self ._inverse , self ._ndim )
222
+ return _apply_affine (x , self ._inverse , self ._ndim ). T
229
223
230
224
def _to_hdf5 (self , group ):
231
225
group .attrs ["Type" ] = "image"
0 commit comments