Skip to content

Commit e8f8f5f

Browse files
committed
Added masks support in ErrorMap interface
1 parent db511b6 commit e8f8f5f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

nipype/algorithms/eval.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ class ErrorMapInputSpec( BaseInterfaceInputSpec ):
406406
desc="Reference image. Requires the same dimensions as in_tst.")
407407
in_tst = File(exists=True, mandatory=True,
408408
desc="Test image. Requires the same dimensions as in_ref.")
409+
mask = File(exists=True, desc="calculate overlap only within this mask.")
409410
method = traits.Enum( "squared_diff", "eucl",
410411
desc='',
411412
usedefault=True )
@@ -439,6 +440,7 @@ def _run_interface( self, runtime ):
439440

440441
assert( ref_data.ndim == tst_data.ndim )
441442

443+
442444
if ( ref_data.ndim == 4 ):
443445
comps = ref_data.shape[-1]
444446
mapshape = ref_data.shape[:-1]
@@ -449,6 +451,16 @@ def _run_interface( self, runtime ):
449451
refvector = ref_data.reshape(-1)
450452
tstvector = tst_data.reshape(-1)
451453

454+
if isdefined( self.inputs.mask ):
455+
msk = nb.load( self.inputs.mask ).get_data()
456+
457+
if ( mapshape != msk.shape ):
458+
raise RuntimeError( "Mask should match volume shape")
459+
460+
mskvector = msk.reshape(-1)
461+
refvector = refvector * mskvector[:,np.newaxis]
462+
tstvector = tstvector * mskvector[:,np.newaxis]
463+
452464
diffvector = (tstvector-refvector)**2
453465
if ( ref_data.ndim > 1 ):
454466
diffvector = np.sum( diffvector, axis=1 )

0 commit comments

Comments
 (0)