@@ -406,6 +406,7 @@ class ErrorMapInputSpec( BaseInterfaceInputSpec ):
406
406
desc = "Reference image. Requires the same dimensions as in_tst." )
407
407
in_tst = File (exists = True , mandatory = True ,
408
408
desc = "Test image. Requires the same dimensions as in_ref." )
409
+ mask = File (exists = True , desc = "calculate overlap only within this mask." )
409
410
method = traits .Enum ( "squared_diff" , "eucl" ,
410
411
desc = '' ,
411
412
usedefault = True )
@@ -439,6 +440,7 @@ def _run_interface( self, runtime ):
439
440
440
441
assert ( ref_data .ndim == tst_data .ndim )
441
442
443
+
442
444
if ( ref_data .ndim == 4 ):
443
445
comps = ref_data .shape [- 1 ]
444
446
mapshape = ref_data .shape [:- 1 ]
@@ -449,6 +451,16 @@ def _run_interface( self, runtime ):
449
451
refvector = ref_data .reshape (- 1 )
450
452
tstvector = tst_data .reshape (- 1 )
451
453
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
+
452
464
diffvector = (tstvector - refvector )** 2
453
465
if ( ref_data .ndim > 1 ):
454
466
diffvector = np .sum ( diffvector , axis = 1 )
0 commit comments