from nisl import datasets, _utils from pynax.core import Mark from pynax.view import ImshowView import pylab as pl import numpy as np nyu = datasets.fetch_nyu_rest(n_subjects=1) func = nyu.func[0] niimg = _utils.check_niimg(func) fig = pl.figure(figsize=(17, 5)) data = niimg.get_data()[..., 0] # Awesome example activation map: threshold data_act = np.ma.MaskedArray(data * 0.8, mask=(data < .6 * np.max(data))) # Display options display_options = {} display_options['interpolation'] = 'nearest' display_options['cmap'] = pl.cm.gray ac_display_options = {} ac_display_options['interpolation'] = 'nearest' ac_display_options['cmap'] = pl.cm.autumn ac_display_options['vmin'] = data_act.min() ac_display_options['vmax'] = data_act.max() # Marks mx = Mark(20, {'color': 'r'}) marks = [] views = [] for i in range(10):
""" Simple example of NiftiMasker use ================================== Here is a simple example of automatic mask computation using the nifti masker. The mask is computed and visualized. """ ### Load nyu_rest dataset ##################################################### from nisl import datasets from nisl.io import NiftiMasker dataset = datasets.fetch_nyu_rest(n_subjects=1) ### Compute the mask ########################################################## nifti_masker = NiftiMasker(memory="nisl_cache", memory_level=2) nifti_masker.fit(dataset.func[0]) mask = nifti_masker.mask_img_.get_data() ### Visualize the mask ######################################################## import pylab as pl import numpy as np import nibabel pl.figure() pl.axis('off') pl.imshow(np.rot90(nibabel.load(dataset.func[0]).get_data()[..., 20, 0]), interpolation='nearest', cmap=pl.cm.gray) ma = np.ma.masked_equal(mask, False) pl.imshow(np.rot90(ma[..., 20]), interpolation='nearest', cmap=pl.cm.autumn, alpha=0.5)