Nilearn中的基本操作和查看

本分享为脑机学习者Rose整理发表于公众号:脑机接口社区(微信号:Brain_Computer).QQ交流群:903290195

Nilearn简介

Nilearn是一个Python模块,用于对神经成像数据进行快速、简单的统计学习。它利用scikit-learn python工具箱进行多变量统计,应用程序包括预测建模、分类、解码或连接性分析。

Nilearn操作

下面对它的基本操作进行简要介绍


# 让我们使用nilearn随附的Nifti文件
from nilearn.datasets import MNI152_FILE_PATH
# 注:变量mni152_file_path只是nifti文件的路径
print('Path to MNI152 template: %r' % MNI152_FILE_PATH)

第一步:查看数据

from nilearn import plotting
plotting.plot_img(MNI152_FILE_PATH)

在这里插入图片描述

第二步:平滑操作

让我们使用nilearn中的图像平滑功能:nilearn.image.smooth_img

包含"img"的函数可以使用文件名或图像作为输入。

在这里,我们以毫米为单位输入图像文件名和平滑值

from nilearn import image
smooth_anat_img = image.smooth_img(MNI152_FILE_PATH, fwhm=3)

# 打印平滑
print(smooth_anat_img)

在这里插入图片描述


## 平滑方式一
plotting.plot_img(smooth_anat_img)

在这里插入图片描述


## 平滑方式二
more_smooth_anat_img = image.smooth_img(smooth_anat_img, fwhm=3)
plotting.plot_img(more_smooth_anat_img)

在这里插入图片描述

第三步:保存结果到文件中


## 保存结果到文件中
more_smooth_anat_img.to_filename('more_smooth_anat_img.nii.gz')
plotting.show()

概括说,所有nilearn工具都可以将数据作为文件名或内存中的对象,并将大脑体积作为内存中的对象返回。这些可以传递给其他nilearn工具,或保存到磁盘.

参考
Nilearn中的基本操作和查看

脑机学习者Rose笔记分享,QQ交流群:903290195
更多分享,请关注公众号

发布了168 篇原创文章 · 获赞 45 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/zyb228107/article/details/103543958