Skip to content

Commit 360e685

Browse files
committed
fix: clean up spm mask generation
1 parent 4afd881 commit 360e685

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

nipype/algorithms/rapidart.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,11 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
374374
for t0 in range(timepoints):
375375
vol = data[:, :, :, t0]
376376
# Use an SPM like approach
377+
mask_tmp = vol > \
378+
(_nanmean(vol) / self.inputs.global_threshold)
379+
g_vol = np.nansum(vol * mask_tmp)/np.nansum(mask_tmp)
377380
mask = mask * \
378-
(vol > (_nanmean(vol) / self.inputs.global_threshold))
381+
(vol > g_vol)
379382
for t0 in range(timepoints):
380383
vol = data[:, :, :, t0]
381384
g[t0] = _nanmean(vol[mask])
@@ -384,10 +387,13 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
384387
g = np.zeros((timepoints, 1))
385388
if not intersect_mask:
386389
iflogger.info('not intersect_mask is True')
390+
mask = np.zeros((x, y, z, timepoints))
387391
for t0 in range(timepoints):
388392
vol = data[:, :, :, t0]
389-
mask = vol > (_nanmean(vol) / 8)
390-
g[t0] = _nanmean(vol[mask])
393+
mask_tmp = vol > \
394+
(_nanmean(vol) / self.inputs.global_threshold)
395+
mask[:, :, :, t0] = mask_tmp
396+
g[t0] = np.nansum(vol * mask_tmp)/np.nansum(mask_tmp)
391397
elif masktype == 'file': # uses a mask image to determine intensity
392398
maskimg = load(self.inputs.mask_file)
393399
mask = maskimg.get_data()

0 commit comments

Comments
 (0)