Commit f3961fe2 authored by inhuszar's avatar inhuszar
Browse files

Suppress SSD at the mask edge (if mask val is <1e-3)

parent c562a301
......@@ -77,7 +77,7 @@ class CostMIND(CostMSD):
self.truncate = truncate
# Call parent-class initialisation
metaparameters.update(self._metaparameters)
metaparameters.update(**self._metaparameters)
super(CostMIND, self).__init__(
source, target,
target_filter=combine_filters(target_filter, self.mind),
......@@ -86,6 +86,8 @@ class CostMIND(CostMSD):
maskmode=maskmode, matchmode=matchmode, normalise=normalise,
logger=logger, **metaparameters)
self._metaparameters.update(metaparameters)
@property
def ndim(self):
""" This is a read-only property. """
......@@ -192,7 +194,7 @@ class CostMIND(CostMSD):
vc = img.domain.get_voxel_coordinates()
if img.mask is not None:
masked = np.flatnonzero(img.mask == 0)
masked = np.flatnonzero(np.isclose(img.mask, 0, atol=1e-3))
else:
masked = []
......@@ -201,13 +203,13 @@ class CostMIND(CostMSD):
# Shift the image such that the central voxel
# overlaps with the specific neighbour
img_shifted = np.empty_like(img.data)
img_shifted = img.copy()
for axis, vi in zip(img.vaxes, vector):
if vi:
img_shifted[...] = np.roll(img.data, vi, axis)
img_shifted.data[...] = np.roll(img_shifted.data, vi, axis)
# Calculate voxelwise squared differences over the entire image
ssd = (img_shifted - img.data) ** 2
ssd = (img_shifted.data - img.data) ** 2
del img_shifted
# Zero the difference on the edges (Neumann)
......@@ -222,7 +224,7 @@ class CostMIND(CostMSD):
ssd.flat[bindices] = 0
# Treat mask edges the same as image borders
if self.metaparameters.get("ignore_masked_edges"):
if self.metaparameters.get("ignore_masked_edges", False):
tc = np.delete(test_coordinates, bindices, axis=0)
vcc = np.delete(vc, bindices, axis=0)
mindices = np.ravel_multi_index(tc.T, img.vshape)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment