Skip to content

Instantly share code, notes, and snippets.

@adelavega
Last active January 19, 2017 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adelavega/d07253a0cc6a5b271f3616f85681c37a to your computer and use it in GitHub Desktop.
Save adelavega/d07253a0cc6a5b271f3616f85681c37a to your computer and use it in GitHub Desktop.
Plot a subset of clusters from a nifti file
from nilearn import plotting as niplt
import nibabel as nib
import seaborn as sns
import numpy as np
def plot_subset(nifti, layers, colors = None, **kwargs):
if not isinstance(nifti, nib.Nifti1Image):
nifti = nib.load(nifti)
data = nifti.get_data()
if colors is None:
colors = sns.color_palette('Set1', len(layers) + 1)
for value in np.unique(np.round(data)):
if np.in1d(value, layers)[0] == False:
data[np.round(data) == value] = 0
niplt.plot_roi(nifti, cmap = ListedColormap(colors),**kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment