当前位置:   article > 正文

mrtrix3简单使用

mrtrix3
#直接输入dwigradcheck出现错误,所以用下面的code
python3 /usr/bin/dwigradcheck
  • 1
  • 2
mrconvert -fslgrad bvecs bvals data.nii.gz raw.mif
  • 1

预处理

#!/bin/bash
path_root="/media/kui/run_disk/fsl_demo/mydata"

cd ${path_root}/sub001

# convert nii to native format MIF
mrconvert -fslgrad DSI_PA.bvec DSI_PA.bval DSI_PA.nii rawdata.mif

# create a mask
dwi2mask rawdata.mif - | maskfilter - dilate preproc_mask.mif -npass 3

#denoising of dwi
dwidenoise rawdata.mif denoise.mif -noise noiselevel.mif -mask preproc_mask.mif

# Gibbs Ring artifact
mrdegibbs denoise.mif degibbs.mif

# motion and distortion correction
# create B0 AP-PA pair
fslroi B0_AP.nii B00_AP.nii 0 1
fslroi DSI_PA.nii DSI_B0_PA.nii 0 1
mrconvert -fslgrad DSI_B0_PA.bvec DSI_B0_PA.bval DSI_B0_PA.nii.gz DSI_B0_PA.mif
mrconvert -fslgrad B00_AP.bvec B00_AP.bval B00_AP.nii.gz B00_AP.mif
mrcat DSI_B0_PA.mif B00_AP.mif B0_pair.mif

# correction
python3 /usr/bin/dwifslpreproc degibbs.mif geomcorr.mif -pe_dir PA -rpe_pair -se_epi B0_pair.mif \
        -eddy_option "--data_is_shelled --slm=linear --niter=5"
                                                                                                                                                                                                                    
# bias field correction
# dwibiascorrect 校正方法有两种:ants or fsl,ants效果更好点
python3 /usr/bin/dwibiascorrect fsl geomcorr.mif biascorr.mif -bias biasfield.mif

#DWI align to T1
dwiextract biascorr.mif -bzero - | mrmath -axis 3 - mean b0.nii

flirt.fsl -dof 6 -cost normmi -ref T1.nii -in b0.nii -omat T_fsl.txt

transformconvert T_fsl.txt b0.nii T1.nii flirt_import T_DWItoT1.txt

mrtransform -linear T_DWItoT1.txt biascorr.mif align.mif

# recon-all T1
recon-all -i T1.nii -subjid sub001 -sd . all
 
# 5tt segmentation 分离5种组织:皮层灰质;皮层下灰质(深部核团);白质;脑脊液;病变组织。
mrconvert sub001/mri/aparc.a2009s+aseg.mgz aparc.a2009s+aseg.nii.gz

python3 /usr/bin/5ttgen freesurfer aparc.a2009s+aseg.nii.gz 5ttseg.mif

5tt2gmwmi 5ttseg.mif 5tt_gmwmi.mif                                                        
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

指标解算

#!/bin/bash
### diffusion tensor imaging ###
#creat a mask
dwi2mask align.mif - | maskfilter - dilate dwi_mask.mif

# create diffusion tensor
dwi2tensor -mask dwi_mask.mif align.mif dt.mif

# calculate eigenvectors and scalar metrics from tensor
tensor2metric dt.mif -fa dt_fa.mif -ad dt_ad.mif 

### constrained spherical deconvolution (CSD) ###
# estimate response function for wm, gm, csf
#bug!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
python3 /usr/bin/dwi2response msmt_5tt align.mif 5ttseg.mif \ 
                              ms_5tt_wm.txt ms_5tt_gm.txt ms_5tt_csf.txt \
                              -voxels ms_5tt_voxels.mif

# estimate fiber orientation distribution FOD
dwi2fod msmt_csd align.mif \
        ms_5ttwm.txt dwi_wmCSD.mif \
        ms_5tt_gm.txt dwi_gmCSD.mif \
        ms_5tt_csf.txt dwi_csfCSD.mif
        
# creat ROIs
mrthreshold -abs 0.2 dt_fa.mif - | mrcalc - dwi_mask.mif -mul dwi_wmMask.mif

# whole brain tractography
tckgen -algo iFOD2 -act 5ttseg.mif -backtrack -crop_at_gmwmi \
       -cutoff 0.05 -angle 45 -minlength 20 -maxlength 200 \ 
       -seed_image dwi_wmMask.mif -select 200k \ 
       dwi_wmCSD.mif \ 
       fibs_200k_angle45_maxlen200_act.tck

# ROI-based tractography
tckgen -algo iFOD2 -cutoff 0.05 -angle 45 \ 
       -minlength 20 -maxlength 100 \ 
       -seed_image lh_thalamus.nii.gz \
       -include lh_cuneus.nii.gz \
       -seed_unidirectional \
       -stop \
       dwi_wmCSD.mif \
       fibs_OR.tck
       
## connectome base on aparc2009
# re-label the parcellation
labelconvert aparc.a2009s+aseg.nii.gz $FREESURFER_HOME/FreeSurferColorLUT.txt \
             ~/Applications/mrtrix3/share/mrtrix3/labelconvert/fs_a2009s.txt \
             aparc.a2009s+aseg_relabel.nii.gz
# generate connectome
tck2connectome -symmetric -zero_diagonal -scale_invnodevol \
               fibs_200k_angle45_maxlen200_act.tck \
               aparc.a2009s+aseg_relabel.nii.gz \
               connectome_a2009s.csv
               -out_assignment assignments_a2009s.csv
mrview aparc.a2009s+aseg_relabel.nii.gz -connectome.init \
       aparc.a2009s+aseg_relabel.nii.gz -connectome.load connectome_a2009s.csv     
# connectome by FA mean
tcksamplefibs_200kangle45_maxlen200_act.tck dt_fa.mif tck_meanFA.txt -state_tck mean

tck2connectome -symmetric -zero_diagonal fibs_200k_angle45_maxlen200_act.tck aparc.a2009s+aseg_relabel.nii.gz connectome_FA.csv -scale_file tck_meanFA.txt -stat_edge mean
        
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62

绘图

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pandas as pd
import seaborn as sns

connect_a2009s = pd.read_csv("connectome_a2009s.csv", header=None)
ax = sns.heatmap(connect_a2009s, vmax=0.05)

connect_fa = pa.read_csv("connectome_FA.csv", header=None)
ax = sns.heatmap(connect_FA)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

bug

# bug 
# dwi2response msmt_5tt
dwi2response: [ERROR] dwi2response tournier dwi.mif wm_ss_response.txt -mask wm_mask.mif -voxels wm_sf_mask.mif -scratch /media/kui/run_disk/fsl_demo/mydata/sub001/dwi2response-tmp-3LVL29/ (msmt_5tt.py:113)
dwi2response: [ERROR] Information from failed command:
dwi2response:
              Traceback (most recent call last):
                File "/usr/lib/mrtrix3/bin/dwi2response", line 126, in <module>
                  import mrtrix3
                File "/usr/lib/mrtrix3/bin/mrtrix3.py", line 18, in <module>
                  from distutils.spawn import find_executable
              ModuleNotFoundError: No module named 'distutils.spawn'
dwi2response:
dwi2response: [ERROR] For debugging, inspect contents of scratch directory: /media/kui/run_disk/fsl_demo/mydata/sub001/dwi2response-tmp-3LVL29/

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

参考:bilibili up: 她唱起歌来了 《MRtrix3-弥散像分析和神经纤维束追踪》系列

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/98211
推荐阅读
相关标签
  

闽ICP备14008679号