# Nilearn学习笔记3-提取时间序列建立功能连接体

## 1. 基于大脑分区提取时间序列

（Time-series from a brain parcellation or “MaxProb” atlas） 1.1 一般而言，用“硬分区”定义用于提取信号的分区。人脑分区有很多个版本，可以结合自己的数据和自己的研究目的选取合理的分区图谱，用于自己的研究。 代码：（代码中有详细注释）

```# Load fmri image
# Note: functions in learn can accept parameters as: image object or fmri filepath

from nilearn import datasets
dataset = datasets.fetch_atlas_harvard_oxford('cort-maxprob-thr25-2mm')
atlas_filename = dataset.maps
labels = dataset.labels

# Apply atlas to my data
from nilearn.image import resample_to_img

# Gain the TimeSeries
memory='nilearn_cache', verbose=5)

# Extracting times series to build a functional connectome
from nilearn.connectome import ConnectivityMeasure
correlation_measure = ConnectivityMeasure(kind='correlation')
correlation_matrix = correlation_measure.fit_transform([time_series])[0]

# Plot the correlation matrix
import numpy as np
from matplotlib import pyplot as plt
plt.figure(figsize=(10, 10))

# Mask the main diagonal for visualization:
np.fill_diagonal(correlation_matrix, 0)
plt.imshow(correlation_matrix, interpolation="nearest", cmap="RdBu_r",
vmax=0.8, vmin=-0.8)

x_ticks = plt.xticks(range(len(labels) - 1), labels[1:], rotation=90)
y_ticks = plt.yticks(range(len(labels) - 1), labels[1:])
plt.gca().yaxis.tick_right()
plt.show()```

## 2. 通过概率图谱建立时间序列

```'''
extracting TimeSeries from probabilistic atlas
'''
# Note: functions in learn can accept parameters as: image object or fmri filepath

# Retrieve the atlas and the data
from nilearn import datasets
atlas = datasets.fetch_atlas_msdl()
atlas_filename = atlas['maps']
labels = atlas['labels']

# Apply atlas to my data
from nilearn.image import resample_to_img

# Gain the TimeSeries
memory='nilearn_cache', verbose=5)

############################################################################
# Build and display a correlation matrix
from nilearn.connectome import ConnectivityMeasure
correlation_measure = ConnectivityMeasure(kind='correlation')
correlation_matrix = correlation_measure.fit_transform([time_series])[0]

# Display the correlation matrix
import numpy as np
from matplotlib import pyplot as plt
plt.figure(figsize=(10, 10))
# Mask out the major diagonal
np.fill_diagonal(correlation_matrix, 0)
plt.imshow(correlation_matrix, interpolation="nearest", cmap="RdBu_r",
vmax=0.8, vmin=-0.8)
plt.colorbar()
# And display the labels
x_ticks = plt.xticks(range(len(labels)), labels, rotation=90)
y_ticks = plt.yticks(range(len(labels)), labels)

############################################################################
# And now display the corresponding graph
from nilearn import plotting
coords = atlas.region_coords

# We threshold to keep only the 20% of edges with the highest value
# because the graph is very dense
plotting.plot_connectome(correlation_matrix, coords,
edge_threshold="80%", colorbar=True)

plotting.show()```

60 篇文章34 人订阅

0 条评论

## 相关文章

### js登录滑动验证，不滑动无法登陆

js的判断这里是根据滑块的位置进行判断，应该是用一个flag判断 <%@ page language="java" contentType="text/html...

8668

2944

4224

5104

4395

3702

84611

### Miguel de Icaza 细说 Mix 07大会上的Silverlight和DLR

Mono之父Miguel de Icaza 详细报道微软Mix 07大会上的Silverlight和DLR ,上面还谈到了Mono and Silverligh...

2997

### Mix 10 上的asp.net mvc 2的相关Session

Beyond File | New Company: From Cheesy Sample to Social Platform Scott Hansel...

2787

### Kit 3D 更新

Kit3D is a 3D graphics engine written for Microsoft Silverlight. Kit3D was inita...

2936