Last active
January 19, 2017 17:22
-
-
Save adelavega/d07253a0cc6a5b271f3616f85681c37a to your computer and use it in GitHub Desktop.
Plot a subset of clusters from a nifti file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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