<commit_before># Fetch dataset and load data
from nilearn import datasets
import nibabel
import numpy


z = 26

# Fetch dataset
haxby = datasets.fetch_haxby(n_subjects=1)
labels = numpy.genfromtxt(haxby.session_target[0], skip_header=1, usecols=[0],
                          dtype=basestring)

# Create a function to display an axial slice
import matplotlib.pyplot as plt


def display_axial(brain, i, cmap='hot'):
    plt.figure()
    plt.imshow(brain[:, :, i].T.copy(), origin='lower', interpolation='nearest',
               cmap=cmap)
    plt.axis('off')
    plt.tight_layout()


# Smoothing
from nilearn.image import smooth
img = smooth(haxby.func[0], fwhm=6)
data = img.get_data()
affine = img.get_affine()
display_axial(data.mean(axis=-1), z)

# Run a T-test for face and houses
from scipy import stats
tv, pv = stats.ttest_ind(data[..., labels == 'face'],
                         data[..., labels == 'house'], axis=-1)
pv = - numpy.log10(pv)
pv[numpy.isnan(pv)] = 0.
pv[pv > 10] = 10
display_axial(pv, z)

# Thresholding
pv[pv < 5] = 0
display_axial(pv, z)

# Binarization and intersection with VT mask
pv = (pv != 0)
vt = nibabel.load(haxby.mask_vt[0]).get_data().astype(bool)
pv = numpy.logical_and(pv, vt)
display_axial(pv, z)

# Dilation
from scipy.ndimage import binary_dilation
pv = binary_dilation(pv)
display_axial(pv, z)

# Identification of connected components
from scipy.ndimage import label
labels, n_labels = label(pv)
display_axial(labels, z, 'gnuplot')

# Save the result
nibabel.save(nibabel.Nifti1Image(labels, affine), 'mask.nii')
plt.show()<commit_msg>Add title to figures in image manipulation example.<commit_after># Fetch dataset and load data
from nilearn import datasets
import nibabel
import numpy


z = 26

# Fetch dataset
haxby = datasets.fetch_haxby(n_subjects=1)
labels = numpy.genfromtxt(haxby.session_target[0], skip_header=1, usecols=[0],
                          dtype=basestring)

# Create a function to display an axial slice
import matplotlib.pyplot as plt


def display_axial(brain, i, title, cmap='hot'):
    plt.figure()
    plt.imshow(brain[:, :, i].T.copy(), origin='lower', interpolation='nearest',
               cmap=cmap)
    plt.axis('off')
    plt.title(title)
    plt.tight_layout()


# Smoothing
from nilearn.image import smooth
img = smooth(haxby.func[0], fwhm=6)
data = img.get_data()
affine = img.get_affine()
display_axial(data.mean(axis=-1), z, 'Mean EPI')

# Run a T-test for face and houses
from scipy import stats
tv, pv = stats.ttest_ind(data[..., labels == 'face'],
                         data[..., labels == 'house'], axis=-1)
pv = - numpy.log10(pv)
pv[numpy.isnan(pv)] = 0.
pv[pv > 10] = 10
display_axial(pv, z, 'p-values')

# Thresholding
pv[pv < 5] = 0
display_axial(pv, z, 'Thresholded p-values')

# Binarization and intersection with VT mask
pv = (pv != 0)
vt = nibabel.load(haxby.mask_vt[0]).get_data().astype(bool)
pv = numpy.logical_and(pv, vt)
display_axial(pv, z, 'Intersection with ventral temporal mask')

# Dilation
from scipy.ndimage import binary_dilation
pv = binary_dilation(pv)
display_axial(pv, z, 'Dilated mask')

# Identification of connected components
from scipy.ndimage import label
labels, n_labels = label(pv)
display_axial(labels, z, 'Connected components', 'gnuplot')

# Save the result
nibabel.save(nibabel.Nifti1Image(labels, affine), 'mask.nii')
plt.show()
{'fraction_non_alphanumeric': 0.13597143707229992, 'fraction_numerical': 0.01309134186254091, 'mean_word_length': 4.140672782874618, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '90446', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1196, 'n_words': 310}