fsl左右海马体分割+freesurfer合并

背景

需要分割出海马体。可借鉴方法:深度学习(UNet分割),形态学上的开闭,fsl中的分割。
使用fsl种的分割时需要注意,fsl分割分为左海马和右海马
方法:使用fsl中的first命令进行分割。
先在终端输入first查看需要输入的参数:
在这里插入图片描述

可以看到-i 要从哪个文件进行提取-k输出分割文件名称-m 分割的标准文件(*.bmv)-l 做flirt时的变换矩阵
关于*.bmv文件:fsl自带的,在fsl安装目录data/first下面:
在这里插入图片描述

关于这两个文件夹有什么区别不清楚,但是海马在选中的文件夹中。

bash直接运行

命令:

first -i subj.nii -l subjmat.mat -m L_Hipp_bin.bmv -k l_hippo.nii

同样的方法生成右海马:

first -i subj.nii -l subjmat.mat -m R_Hipp_bin.bmv -k r_hippo.nii

使用freesurfer中的mri_concat命令将左海马和右海马合并成整个海马体:

mri_concat --combine l_hippo.nii r_hippo.nii --o hippo.nii

得到hippo.nii就是海马文件:
在这里插入图片描述

python+nipype实现

分割成左右海马体+合并代码

import os
import subprocess
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMessageBox

def hippoSeg(in_file, out_file, out_path):
    '''
	segmentation hippocampus, and show the messagebox.
    :param in_file: subj-T1.nii
    :param out_file: hippo.nii
    :param out_path: /home/xxx/Desktop/test
    :return:
    '''

    l_hippo = os.path.join(out_path, 'L_Hipp_bin.bmv')
    r_hippo = os.path.join(out_path, 'R_Hipp_bin.bmv')

    mat_file = os.path.join(out_path, 'reg.mat') # 配准时输出的矩阵
    l_hippo_out = os.path.join(out_path, 'l_hippo.nii.gz')
    r_hippo_out = os.path.join(out_path, 'r_hippo.nii.gz')

    try:
   		''' 分割左海马体 '''
        l_hippo_cmd = 'first -i {0} -l {1} -m {2} -k {3}'.format(in_file, mat_file, l_hippo, l_hippo_out)
        # 因为是连接的远程环境,所以每次使用fsl中的命令需要重新inport一下,感觉有点繁琐。
        l_cmdline = 'export FSLDIR=/etc/fsl/5.0 && source $FSLDIR/fsl.sh && {0}'.format(l_hippo_cmd)
        task = subprocess.run(l_cmdline, shell=True, stdout=subprocess.PIPE)
    except BaseException as err:
        print('err\n', err)
        QMessageBox.information(QtWidgets.QWidget(), 'messagebox', 'left hippocampus segmentation error, see log file',
                                QMessageBox.Yes)
        return -1

    try:
    	''' 分割右海马体 '''
        r_hippo_cmd = 'first -i {0} -l {1} -m {2} -k {3}'.format(in_file, mat_file, r_hippo, r_hippo_out)
        r_cmdline = 'export FSLDIR=/etc/fsl/5.0 && source $FSLDIR/fsl.sh && {0}'.format(r_hippo_cmd)
        task = subprocess.run(r_cmdline, shell=True, stdout=subprocess.PIPE)
    except BaseException as err:
        print('err\n', err)
        QMessageBox.information(QtWidgets.QWidget(), 'messagebox', 'right hippocampus segmentation error, see log file',
                                QMessageBox.Yes)
        return -1

    try:
    	''' 左右海马体联合 '''
    	# 这条命令可以换成nipype包中的API接口,这里偷懒没有换。
        concat_cmd = 'mri_concat --combine {0} {1} --o {2}'.format(os.path.join(out_path, l_hippo_out), 
                                                                   os.path.join(out_path, r_hippo_out),
                                                                   os.path.join(out_path, out_file))
         ''' 同样需要export一下freesurfer '''
        merge_cmdline = 'export FREESURFER_HOME=/usr/local/freesurfer && source $FREESURFER_HOME/SetUpFreeSurfer.sh &&  {0}'.format(concat_cmd)
        print('start merge')
        task = subprocess.run(merge_cmdline, shell=True, stdout=subprocess.PIPE)
        print('finished!')
        QMessageBox.information(QtWidgets.QWidget(), 'messagebox', 'finished hippocampus ',
                                QMessageBox.Yes)
        return 1
    except BaseException as err:
        print('err\n', err)
        QMessageBox.warning(QtWidgets.QWidget(), 'messagebox', 'hippocampus merge error, see log file',
                                QMessageBox.Yes)
        return -1
  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 13
    评论
FSL是一款功能强大的磁共振成像(MRI)数据分析软件,可以用于分割海马等脑部结构。下面是详细的步骤: 1. 准备数据:将要分析的MRI数据导入到FSL中,包括结构MRI(T1或T2)和功能MRI。确保数据已经被纠正了各种估计偏差,如失真校正、运动校正等。 2. 预处理数据:在FSL中使用不同的工具对MRI数据进行预处理,如去除头骨(BET)、校正运动(MCFLIRT)、矫正场扭曲(TOPUP)等。 3. 分割海马:使用FSL中的工具进行海马分割。常见的工具有Freesurfer和FIRST。 - 使用Freesurfer:在终端中输入以下命令: ``` recon-all -i input.nii.gz -all -hippocampal-subfields-T1 ``` 这将会对输入的MRI数据进行自动分割,并输出包含海马的NIFTI文件。 - 使用FIRST:在FSL中打开FIRST工具,选择要分割的MRI数据和海马模板,然后运行分割程序。输出文件将包含分割后的海马。 4. 可视化和验证:使用FSL中的工具进行可视化和验证,以确保分割结果准确无误。常见的工具有FSLview和FSLeyes。 - 使用FSLview:在终端中输入以下命令: ``` fslview input.nii.gz -l "Random-Rainbow" -t 0.5 -b 0,1000 ``` 这将会打开FSLview并显示MRI数据。可以使用FSLview中的工具来查看分割结果并进行验证。 - 使用FSLeyes:在FSLeyes中打开MRI数据和分割结果,然后可以使用不同的工具进行可视化和验证。 以上是使用FSL分割海马的详细步骤。需要注意的是,这只是一个大致的指南,具操作过程可能因数据类型、处理流程和软件版本而有所不同。因此,在进行MRI数据分析之前,请确保熟悉软件的使用方法并进行充分的数据处理和验证。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

九久呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值