"""
The haxby dataset: face vs house in object recognition
=======================================================

A significant part of the running time of this example is actually spent
in loading the data: we load all the data but only use the face and
houses conditions.
"""

### Load Haxby dataset ########################################################
from nisl import datasets
import numpy as np
import nibabel
dataset_files = datasets.fetch_haxby_simple()

# fmri_data and mask are copied to lose the reference to the original data
bold_img = nibabel.load(dataset_files.func)
fmri_data = np.copy(bold_img.get_data())
affine = bold_img.get_affine()
y, session = np.loadtxt(dataset_files.session_target).astype("int").T
conditions = np.recfromtxt(dataset_files.conditions_target)['f0']
mask = dataset_files.mask
# fmri_data.shape is (40, 64, 64, 1452)
# and mask.shape is (40, 64, 64)

### Preprocess data ###########################################################
# Build the mean image because we have no anatomic data
mean_img = fmri_data.mean(axis=-1)

### Restrict to faces and houses ##############################################
==================================================

In this example, the Nifti masker is used to automatically compute a mask.
Using some visualization, one can see that the default parameters of the
nifti masker are not suited for this dataset. They are consequently tweaked
to obtained a decent mask.
"""

import pylab as pl
import numpy as np

import nibabel
from nisl import datasets, io

# Load Haxby dataset
haxby = datasets.fetch_haxby_simple()
haxby_img = nibabel.load(haxby.func)
# Restrict haxby to 150 frames to speed up computation
haxby_func = haxby_img.get_data()[..., :150]
haxby_img = nibabel.Nifti1Image(haxby_func, haxby_img.get_affine())
# Load mask provided by Haxby
haxby_mask = nibabel.load(haxby.mask).get_data().astype(np.bool)

# Display helper
background = np.mean(haxby_func, axis=-1)[..., 27]


def display_mask(background, mask, title):
    pl.axis('off')
    pl.imshow(np.rot90(background), interpolation='nearest', cmap=pl.cm.gray)
    ma = np.ma.masked_equal(mask, False)
Ejemplo n.º 3
0
"""
The haxby dataset: face vs house in object recognition
=======================================================

A significant part of the running time of this example is actually spent
in loading the data: we load all the data but only use the face and
houses conditions.
"""

### Load Haxby dataset ########################################################
from nisl import datasets
import numpy as np
import nibabel
dataset_files = datasets.fetch_haxby_simple()

# fmri_data and mask are copied to break any reference to the original object
bold_img = nibabel.load(dataset_files.func)
fmri_data = np.copy(bold_img.get_data())
affine = bold_img.get_affine()
y, session = np.loadtxt(dataset_files.session_target).astype("int").T
conditions = np.recfromtxt(dataset_files.conditions_target)['f0']
mask = dataset_files.mask
# fmri_data.shape is (40, 64, 64, 1452)
# and mask.shape is (40, 64, 64)

### Preprocess data ###########################################################
# Build the mean image because we have no anatomic data
mean_img = fmri_data.mean(axis=-1)

### Restrict to faces and houses ##############################################
Ejemplo n.º 4
0
==================================================

In this example, the Nifti masker is used to automatically compute a mask.
Using some visualization, one can see that the default parameters of the
nifti masker are not suited for this dataset. They are consequently tweaked
to obtained a decent mask.
"""

import pylab as pl
import numpy as np

import nibabel
from nisl import datasets

# Load Haxby dataset
haxby = datasets.fetch_haxby_simple()
haxby_img = nibabel.load(haxby.func)
# Restrict haxby to 150 frames to speed up computation
haxby_func = haxby_img.get_data()[..., :150]

# haxby_func is a 4D-array, we want to make a Niimg out of it:
haxby_img = nibabel.Nifti1Image(haxby_func, haxby_img.get_affine())

# Display helper
background = np.mean(haxby_func, axis=-1)[..., 27]


def display_mask(background, mask, title):
    pl.axis('off')
    pl.imshow(np.rot90(background), interpolation='nearest', cmap=pl.cm.gray)
    ma = np.ma.masked_equal(mask, False)