Skip to content

Commit

Permalink
add resample_like py function
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoopes committed Mar 23, 2021
1 parent 1f0fcba commit 44b4a2f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions python/freesurfer/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,21 @@ def transform(self, trf, interp_method='linear', indexing='ij'):
resampled.copy_metadata(self)
return resampled

def resample_like(self, target, interp_method='linear'):
'''
Returns a resampled image in the target space.
'''
if target.affine is None or self.affine is None:
raise ValueError("Can't resample volume without geometry information.")

vox2vox = LinearTransform.matmul(self.ras2vox(), target.vox2ras())
resampled_data = resample(self.data, target.shape, vox2vox, interp_method=interp_method)

resampled = Volume(resampled_data)
resampled.copy_geometry(target)
resampled.copy_metadata(self)
return resampled

@property
def image(self):
'''Internal data array. This will be deprecated - just used the Volume.data member.'''
Expand Down

0 comments on commit 44b4a2f

Please sign in to comment.