Skip to content
Snippets Groups Projects
Commit a4f06be4 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

BF: Call existent parseVersionString function, as opposed to non-existent

variant. applyDeformation/convertDeformationType/Space were assuming voxel
alignment between deformation field and reference image.
parent 54ce09bd
No related branches found
No related tags found
No related merge requests found
...@@ -584,7 +584,8 @@ def convertDeformationType(field, defType=None): ...@@ -584,7 +584,8 @@ def convertDeformationType(field, defType=None):
# we need the coordinates of every voxel # we need the coordinates of every voxel
# in the reference coordinate system. # in the reference coordinate system.
dx, dy, dz = field.shape[:3] dx, dy, dz = field.shape[:3]
xform = field.getAffine('voxel', field.refSpace) xform = affine.concat(field.ref.getAffine('world', field.refSpace),
field .getAffine('voxel', 'world'))
coords = np.meshgrid(np.arange(dx), coords = np.meshgrid(np.arange(dx),
np.arange(dy), np.arange(dy),
...@@ -659,9 +660,12 @@ def convertDeformationSpace(field, from_, to): ...@@ -659,9 +660,12 @@ def convertDeformationSpace(field, from_, to):
refcoords = np.array(refcoords) refcoords = np.array(refcoords)
refcoords = refcoords.transpose((1, 2, 3, 0)).reshape((-1, 3)) refcoords = refcoords.transpose((1, 2, 3, 0)).reshape((-1, 3))
if from_ != 'voxel': xform = affine.concat(
refmat = field.ref.getAffine('voxel', from_) field.ref.getAffine('world', from_),
refcoords = affine.transform(refcoords, refmat) field .getAffine('voxel', 'world'))
if not np.all(np.isclose(xform, np.eye(4))):
refcoords = affine.transform(refcoords, xform)
fieldcoords = srccoords - refcoords fieldcoords = srccoords - refcoords
...@@ -711,6 +715,7 @@ def applyDeformation(image, field, ref=None, order=1, mode=None, cval=None): ...@@ -711,6 +715,7 @@ def applyDeformation(image, field, ref=None, order=1, mode=None, cval=None):
if order is None: order = 1 if order is None: order = 1
if mode is None: mode = 'nearest' if mode is None: mode = 'nearest'
if cval is None: cval = 0 if cval is None: cval = 0
if ref is None: ref = field.ref
# We need the field to contain # We need the field to contain
# absolute source image voxel # absolute source image voxel
...@@ -725,13 +730,22 @@ def applyDeformation(image, field, ref=None, order=1, mode=None, cval=None): ...@@ -725,13 +730,22 @@ def applyDeformation(image, field, ref=None, order=1, mode=None, cval=None):
refSpace='voxel', refSpace='voxel',
defType='absolute') defType='absolute')
# Resample to alternate reference image # If the field is not voxel-aligned
# space if provided - regions of the # to the reference, we need to
# field outside of the reference image # resample the field itself into the
# space will contain -1s, so will be # reference image space (assumed to
# detected as out of bounds by # be world-aligned). If field and ref
# map_coordinates # are not not world aligned, regions
if ref is not None: # of the field outside of the
# reference image space will contain
# -1s, so will be detected as out of
# bounds by map_coordinates below.
#
# This will potentially result in
# truncation at the field boundaries,
# but there's nothing we can do about
# that.
if not field.sameSpace(ref):
field = resample.resampleToReference(field, field = resample.resampleToReference(field,
ref, ref,
order=1, order=1,
......
...@@ -458,8 +458,8 @@ def _readMetadata(group): ...@@ -458,8 +458,8 @@ def _readMetadata(group):
version = group.attrs.get('Version') version = group.attrs.get('Version')
meta = group.attrs.get('Metadata') meta = group.attrs.get('Metadata')
parserver = fslversion.parseVersion(X5_VERSION) parserver = fslversion.parseVersionString(X5_VERSION)
filever = fslversion.parseVersion(version) filever = fslversion.parseVersionString(version)
if (format != X5_FORMAT) or (filever[0] != parserver[0]): if (format != X5_FORMAT) or (filever[0] != parserver[0]):
raise X5Error('Incompatible format/version (required: {}/{}, ' raise X5Error('Incompatible format/version (required: {}/{}, '
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment