Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filled out the functions #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions spm_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ def spm_global(vol):
g : float
SPM global metric for `vol`
"""
T = np.mean(vol) / 8
return np.mean(vol[vol > T])
M = np.mean(vol)
T = M/8
#- Select voxels greater than T
voxels_within = vol>T
#- Calculate mean
mean_over_T = np.mean(vol[voxels_within])
# Show the result
return mean_over_T


def get_spm_globals(fname):
Expand All @@ -54,8 +60,18 @@ def get_spm_globals(fname):
spm_vals : array
SPM global metric for each 3D volume in the 4D image.
"""
# +++your code here+++
# return
#- Load the image given by "fname".
img = nib.load(fname)
#- Get the data
data = img.get_fdata()
#- Calculate the SPM global value for each volume.
spm_vals = []
for i in range(data.shape[3]): #we could also use -1 here
vol = data[...,i]
x = spm_global(vol) #you can either put this directly inside the append method or
#... you can save a temporary varibale in the same loop
spm_vals.append(x)
return spm_vals


def main():
Expand Down