Skip to content
Snippets Groups Projects
myscript.py 660 B
Newer Older
Paul McCarthy's avatar
Paul McCarthy committed
#!/usr/bin/env fslpython

# That first line up there ensures that your
# script will be executed in the fslpython
# environment. If you are writing a general
# Python script, you should use this line
# instead: #!/usr/bin/env python

# In Python, we need to "import" libraries
# (called modules) before we can use them.
import sys
import nibabel as nib

Paul McCarthy's avatar
Paul McCarthy committed
# We can get to our command
# line arguments via sys.argv
fpath = sys.argv[1]
Paul McCarthy's avatar
Paul McCarthy committed

Paul McCarthy's avatar
Paul McCarthy committed
# We can use nibabel to load
# NIFTI images (and other
# neuroimaging data formats)
img = nib.load(fpath)
data = img.get_data()
Paul McCarthy's avatar
Paul McCarthy committed

Paul McCarthy's avatar
Paul McCarthy committed
# Now we're working with a
# numpy array.
nzmean = data[data != 0].mean()
Paul McCarthy's avatar
Paul McCarthy committed

Paul McCarthy's avatar
Paul McCarthy committed
print('mean:', nzmean)