From e7904c8291265819f42380eb9807318f19cc7061 Mon Sep 17 00:00:00 2001 From: ahmedramly Date: Mon, 5 Sep 2022 20:46:58 +0300 Subject: [PATCH] dvars fixing --- findoutlie/metrics.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/findoutlie/metrics.py b/findoutlie/metrics.py index 08ba844..c69a095 100644 --- a/findoutlie/metrics.py +++ b/findoutlie/metrics.py @@ -2,8 +2,8 @@ """ # Any imports you need -# +++your code here+++ - +import numpy as np +import nibabel as nib def dvars(img): """ Calculate dvars metric on Nibabel image `img` @@ -29,4 +29,8 @@ def dvars(img): # You may be be able to solve this in four lines, without a loop. # But solve it any way you can. # This is a placeholder, replace it to write your solution. - raise NotImplementedError('Code up this function') + data = img.get_fdata() + diff = np.diff(data, axis=-1) + dvar = np.sqrt(np.mean(diff.reshape(-1, diff.shape[-1])**2, axis=0)) + + return dvar