9.4.10. 基于字典学习和功能连接体的区域提取

本人能力有限,如有错误,欢迎指出


9.4.10. 基于字典学习和功能连接体的区域提取

原文:https://nilearn.github.io/auto_examples/03_connectivity/plot_extract_regions_dictlearning_maps.html#sphx-glr-auto-examples-03-connectivity-plot-extract-regions-dictlearning-maps-py

这个例子展示了如何使用nilearn.regions.RegionExtractor从字典学习分解的全脑地图中提取空间受限的脑区,并利用它们构建功能性连接体。
我们从nilearn.datasets.fetch_development_fmri 和 nilearn.decomposition.DictLearning大脑图集中使用了20个电影观看功能数据集。
这个例子也可以启发应用相同的步骤来处理使用ICA图提取的区域。在这种情况下,字典学习将被替换为规范ICA分解( canonical ICA),即:
nilearn.decomposition.CanICA
更多细节请参阅nilearn.regions.RegionExtractor文档。

Note
The use of the attribute components_img_ from dictionary learning estimator is implemented from version 0.4.1. For older versions, unmask the deprecated attribute components_ to get the components image using attribute masker_ embedded in estimator. See the section Inverse transform: unmasking data.

9.4.10.1. 获取大脑发育功能数据集

我们使用nilearn的数据集下载数据

from nilearn import datasets

rest_dataset = datasets.fetch_development_fmri(n_subjects=20)
func_filenames = rest_dataset.func
confounds = rest_dataset.confounds

9.4.10.2. 利用字典学习提取功能网络

#从分解模块中引入字典学习算法,调用对象,将模型拟合到功能数据集
# Import dictionary learning algorithm from decomposition module and call the object and fit the model to the functional datasets
from nilearn.decomposition import DictLearning

#初始化字典学习对象
# Initialize DictLearning object
dict_learn = DictLearning(n_components=8, smoothing_fwhm=6.,
                          memory="nilearn_cache", memory_level=2,
                          random_state=0)
#“喂”数据
# Fit to the data
dict_learn.fit(func_filenames)
#静息态网络/图在属性‘components_img_’中
# Resting state networks/maps in attribute `components_img_`
# Note that this attribute is implemented from version 0.4.1.
# For older versions, see the note section above for details.
components_img = dict_learn.components_img_

#可视化功能网络,使用plotting模块
# Visualization of functional networks
# Show networks using plotting utilities
from nilearn import plotting

plotting.plot_prob_atlas(components_img, view_type='filled_contours',
                         title='Dictionary Learning maps')

在这里插入图片描述

9.4.10.3. 从网络中提取区域

#从区域模块引入区域提取算法
# Import Region Extractor algorithm from regions module
#threshold=0.5表示我们在所有图中保持非零体素的数量,阈值越小意味着非体素的强度越大。
# threshold=0.5 indicates that we keep nominal of amount nonzero voxels across all maps, less the threshold means that more intense non-voxels will be survived.
from nilearn.regions import RegionExtractor

extractor = RegionExtractor(components_img, threshold=0.5,
                            thresholding_strategy='ratio_n_voxels',
                            extractor='local_regions',
                            standardize=True, min_region_size=1350)
#只需调用fit()来进行区域提取,无参数
# Just call fit() to process for regions extraction
extractor.fit()
#提取区域存储在regions_img_
# Extracted regions are stored in regions_img_
regions_extracted_img = extractor.regions_img_
#每个区域的下标存储在index_
# Each region index is stored in index_
regions_index = extractor.index_
# Total number of regions extracted
n_regions_extracted = regions_extracted_img.shape[-1]

#可视化区域提取结果
# Visualization of region extraction results
title = ('%d regions are extracted from %d components.'
         '\nEach separate color of region indicates extracted region'
         % (n_regions_extracted, 8))
plotting.plot_prob_atlas(regions_extracted_img, view_type='filled_contours',
                         title=title)

在这里插入图片描述

9.4.10.4. 计算相关系数

#首先,我们需要对时间序列信号进行提取,然后估计这些信号的相关矩阵。
# First we need to do subjects timeseries signals extraction and then estimating correlation matrices on those signals.
#调用transform()提取时间序列
# To extract timeseries signals, we call transform() from RegionExtractor object  onto each subject functional data stored in func_filenames.
#使用connectcome估计相关矩阵
# To estimate correlation matrices we import connectome utilities from nilearn
from nilearn.connectome import ConnectivityMeasure

correlations = []
# Initializing ConnectivityMeasure object with kind='correlation'
connectome_measure = ConnectivityMeasure(kind='correlation')
for filename, confound in zip(func_filenames, confounds):
    # call transform from RegionExtractor object to extract timeseries signals
    timeseries_each_subject = extractor.transform(filename, confounds=confound)
    # call fit_transform from ConnectivityMeasure object
    correlation = connectome_measure.fit_transform([timeseries_each_subject])
    # saving each subject correlation to correlations
    correlations.append(correlation)

# Mean of all correlations
import numpy as np
mean_correlations = np.mean(correlations, axis=0).reshape(n_regions_extracted,                     n_regions_extracted)

9.4.10.5. 绘制功能连接体

title = 'Correlation between %d regions' % n_regions_extracted

# First plot the matrix
display = plotting.plot_matrix(mean_correlations, vmax=1, vmin=-1,
                               colorbar=True, title=title)

# Then find the center of the regions and plot a connectome
regions_img = regions_extracted_img
coords_connectome = plotting.find_probabilistic_atlas_cut_coords(regions_img)

plotting.plot_connectome(mean_correlations, coords_connectome,
                         edge_threshold='90%', title=title)

在这里插入图片描述

9.4.10.6. 绘制仅从一个特定网络提取的区域

#绘制一个未进行区域提取的、索引为4的网络
# First, we plot a network of index=4 without region extraction (left plot)
from nilearn import image

img = image.index_img(components_img, 4)
coords = plotting.find_xyz_cut_coords(img)
display = plotting.plot_stat_map(img, cut_coords=coords, colorbar=False,
                                 title='Showing one specific network')

在这里插入图片描述现在,我们在提取区域后绘制相同的网络,以显示连接的区域被很好地分离。每个大脑提取的区域被识别为单独的颜色。

#
# For this, we take the indices of the all regions extracted related to original network given as 4.
regions_indices_of_map3 = np.where(np.array(regions_index) == 4)

display = plotting.plot_anat(cut_coords=coords,
                             title='Regions from this network')

# Add as an overlay all the regions of index 4
colors = 'rgbcmyk'
for each_index_of_map3, color in zip(regions_indices_of_map3[0], colors):
    display.add_overlay(image.index_img(regions_extracted_img, each_index_of_map3),
                        cmap=plotting.cm.alpha_cmap(color))

plotting.show()

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值