FreeSurfer-Introduction

【摘要】FreeSurfer - Cortical surface and subcortical modelling 皮层表面和皮质下建模

Installation

  • FreeSurfer Download and Install
    Linux:tar -C /usr/local -xzvf freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.0.tar.gz

  • 解决Freesurfer的license问题:可以在官网注册,邮箱会收到license.txt文件,拷贝至FreeSurfer解压目录。比如,我的license已经注册并下载,放在~/Downloads文件夹下。可以执行如下命令拷贝:参考于FSL/FreeSurfer安装教程

    ~/Downloads$ sudo cp license.txt /usr/local/freesurfer/
    
  • 更改subjects文件夹权限

    $ sudo chmod -R 777 /usr/local/freesurfer/subjects
    

Test your FreeSurfer Installation

  • Example 1: Convert the sample-001.mgz to nifti format.

    $> cp $FREESURFER_HOME/subjects/sample-001.mgz .
    $> mri_convert sample-001.mgz sample-001.nii.gz
    ...
    reading from sample-001.mgz...
    TR=7.25, TE=3.22, TI=600.00, flip angle=7.00
    i_ras = (-0, -1, -0)
    j_ras = (-0, 0, -1)
    k_ras = (-1, 0, 0)
    writing to sample-001.nii.gz...
    
  • Example 2: Perform a full recon-all on the nifti file.

    $> export SUBJECTS_DIR=<path to subject directory> # SUBJECTS_DIR变量为存储数据的目录
    $> recon-all -i sample-001.nii.gz -s bert -all (creates a folder called bert in SUBJECTS_DIR)
    
    ...
    Started at 2019年 07月 17日 星期三 20:54:07 CST 
    Ended   at 2019年 07月 18日 星期四 02:37:36 CST
    #@#%# recon-all-run-time-hours 5.725
    recon-all -s bert finished without error at 2019年 07月 18日 星期四 02:37:36 CST
    done
    
    • Process your own data with a command such as this:
    
    recon-all \
      -i  <one slice in the anatomical dicom series> \
      -s  <subject id that you make up> \
      -sd <directory to put the subject folder in> \
      -all
    

    where the input (-i) file is a single file representing a T1-weighted data set. If you have DICOM images, you must find a file in the T1 series to pass. You can do this with the dcmunack command.

  • Example 3: Perform a full recon-all on a pre-existing subject folder

    $> export SUBJECTS_DIR=<path to subject directory>
    $> recon-all -s bert -all
    
    ...
    Started at 2019年 07月 17日 星期三 21:38:11 CST 
    Ended   at 2019年 07月 18日 星期四 02:40:42 CST
    #@#%# recon-all-run-time-hours 5.042
    recon-all -s bert finished without error at 2019年 07月 18日 星期四 02:40:42 CST
    done
    
  • Example 4: View the output volumes, surfaces and subcortical segmentation of the fully recon-ed subject bert.

    $> cd $SUBJECTS_DIR
    $> freeview -v \
        bert/mri/T1.mgz \
        bert/mri/wm.mgz \
        bert/mri/brainmask.mgz \
        bert/mri/aseg.mgz:colormap=lut:opacity=0.2 \
        -f \
        bert/surf/lh.white:edgecolor=blue \
        bert/surf/lh.pial:edgecolor=red \
        bert/surf/rh.white:edgecolor=blue \
        bert/surf/rh.pial:edgecolor=red
    
    Some notes on the above command line:
    
    - bert is the name of the subject
    - The flag -v is used to open some of `the most commonly used volumes` including:
      - brainmask.mgz : skull-stripped volume primarily used for troubleshooting 头骨剥离的卷主要用于故障排除  T1去除颅骨 ➜ brainmask (voxel intensities)
      - wm.mgz : white matter mask also used for troubleshooting 白质掩膜也用于故障排除
      - aseg.mgz : subcortical segmentation loaded with its corresponding color table and at a low opacity. For more information on the subcortical segmentation, see [here](https://surfer.nmr.mgh.harvard.edu/fswiki/SubcorticalSegmentation).皮质下分割加载了相应的颜色表并且低不透明度。 有关皮质下分割的更多信息,请参见此处。 brainmask上色(`遵循皮质下强度边界`) ➜ aseg (labeled structures) 显示皮下结构的分割情况
    
    - The flag -f is used to load surfaces (`遵循灰质和白质边界`)
          - white & pial(软膜的) surfaces are loaded for each hemisphere(半球) & with color indicated by 'edgecolor'
          The `white surface` (blue line) is used to `calculate total white matter volume` and should accurately `follow the boundary between white matter and gray matter`. The `pial surface` (red line) is used to `calculate cortical gray matter volume and should accurately `follow the boundary between the gray matter and the CSF`.
    
    • freeview.bin: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory:Download the shared library from https://packages.ubuntu.com/xenial/amd64/libpng12-0/download

      sudo dpkg -i libpng12-0_1.2.54-1ubuntu1.1_amd64.deb
      
    • freeview.bin: error while loading shared libraries: libjpeg.so.62: cannot open shared object file: No such file or directory

      sudo apt install libjpeg62
      
    • .nii文件 同理查看

      $> freeview -v sample-001.nii.gz
      

FreeSurfer Tutorials

  • Preparation

  • FreeSurfer Tutorial Datasets

  • Introduction to FreeSurfer Output:熟悉freeview界面(快捷键)

    为了帮助验证准确度,请调整亮度和对比度,以便轻松识别灰色和白色物质之间的强度变化。要执行此操作,请在按住“Shift”键的同时左键单击图像并拖动鼠标(Make sure the brainmask volume is highlighted in the left menu in order for this to work.)

    .white和.pial分别可用于计算白质和灰质体积;aseg用于计算皮质下体积的测量

  • we mean wm voxels have an intensity value of somewhere between 100 and 110. And wm voxels are between a value of 85 and 100. In the TroubleshootingData tutorial, we'll go over what to do if there is an intensity normalization error.

  • WM卷:FreeSurfer对白质的初始分割(以灰色显示),并添加了自动拓扑定位器(白色)。

  • 3D view:绿色区域是回旋区域,红色区域是凹陷区域。

  • Notice that all subcortical gray matter is not a part of the surface labels (because again, those areas do not count towards the cortical surface measures).注意,所有皮质下灰质不是表面标签的一部分(因为这些区域不再计入皮质表面测量)。

基本指令说明

$ recon-all

详解

USAGE: recon-all

 Required Arguments:
   -subjid <subjid>
   -<process directive>

 Fully-Automated Directive:
  -all           : performs all stages of cortical reconstruction
  -autorecon-all : same as -all

 Manual-Intervention Workflow Directives:
  -autorecon1    : process stages 1-5 (see below)  # no-use-gpu: about 10 min
  -autorecon2    : process stages 6-23
                   after autorecon2, check white surfaces:
                     a. if wm edit was required, then run -autorecon2-wm
                     b. if control points added, then run -autorecon2-cp
                     c. proceed to run -autorecon3
  -autorecon2-cp : process stages 12-23 (uses -f w/ mri_normalize, -keep w/ mri_seg)
  -autorecon2-wm : process stages 15-23
  -autorecon2-inflate1 : 6-18
  -autorecon2-perhemi : tess, sm1, inf1, q, fix, sm2, inf2, finalsurf, ribbon
  -autorecon3    : process stages 24-34
                     if edits made to correct pial, then run -autorecon-pial
  -hemi ?h       : just do lh or rh (default is to do both)

  Autorecon Processing Stages (see -autorecon# flags above):
    1.  Motion Correction and Conform  # 运动校正和一致
    2.  NU (Non-Uniform intensity normalization)  # 非均匀强度归一化
    3.  Talairach transform computation  #  Talairach变换计算
    4.  Intensity Normalization 1  # 强度归一化
    5.  Skull Strip  # 颅骨去除   

    6.  EM Register (linear volumetric registration)  # EM寄存器(线性体积配准)
    7.  CA Intensity Normalization  # CA强度归一化
    8.  CA Non-linear Volumetric Registration  # CA非线性体积配准
    9.  Remove neck  # 去除颈部
    10. EM Register, with skull  # EM注册,带头骨
    11. CA Label (Aseg: Volumetric Labeling) and Statistics  # CA标签(Aseg:体积标签)和统计

    12. Intensity Normalization 2 (start here for control points) # 强度归一化2(从控制点开始)
    13. White matter segmentation  # 白质细分
    14. Edit WM With ASeg  # 使用ASeg编辑WM
    15. Fill (start here for wm edits)  # 填充(从这里开始编辑wm)
    16. Tessellation (begins per-hemisphere operations)  # 曲面细分(每半球操作开始)
    17. Smooth1
    18. Inflate1
    19. QSphere
    20. Automatic Topology Fixer  # 自动拓扑修复器
    21. White Surfs (start here for brain edits for pial surf)  # 白色Surfs(从这里开始用于脑部冲浪的大脑编辑)
    22. Smooth2
    23. Inflate2

    24. Spherical Mapping  # 球面映射
    25. Spherical Registration  # 球形配准
    26. Spherical Registration, Contralater hemisphere  # 球面配准,Contralater半球
    27. Map average curvature to subject  # 将平均曲率映射到主题
    28. Cortical Parcellation (Labeling)  # 皮质分割(标签)
    29. Cortical Parcellation Statistics  # 皮质分割统计
    30. Pial Surfs  # Pial Surfs
    31. WM/GM Contrast  # WM / GM对比
    32. Cortical Ribbon Mask  # 皮质功能掩膜
    33. Cortical Parcellation mapped to ASeg  # Cortical Parcellation映射到ASeg
    34  Brodmann and exvio EC labels  # Brodmann和exvio EC标签

 Step-wise Directives
  See -help
    ...

$ mri_convert

mri_convert.bin 
                Help

NAME
    mri_convert

SYNOPSIS
    mri_convert [options] <in volume> <out volume>

DESCRIPTION
    mri_convert is a general purpose utility for converting between 
    different file formats. The file type can be specified in two ways. 
    First, mri_convert will try to figure it out on its own from the 
    format of the file name (eg, files that end in .img are assumed to be 
    in spm analyze format). Second, the user can explicity set the type of
    file using --in_type and/or --out_type.
    
    Legal values for --in_tye (-it) and --out_type (-ot) are listed under 
    optional flagged arguments.

$ preproc-cess

FS-FAST Preprocessing

USAGE: preproc-sess

  -per-run : motion cor and reg to middle TP of each run
  -per-session : motion cor and reg to 1st TP of 1st run
  -fwhm FWHM : smoothing level (mm)

  -update        : only run a stage if input is newer than output (default)
  -force         : force reprocessing of all stages (turns off -update)
  -no-update     : same as -force
  -sliceorder so : turn on slice timing correction (STC) with the given slice order
  -ngroups nSliceGroups : number of SMS slice groups for STC
  -surface subject hemi : set hemi to lhrh to do both
  -mni305-2mm    : sample raw data to mni305 at 2mm (same as -mni305)  # useful
  -mni305-1mm    : sample raw data to mni305 at 1mm
  -cvs : sample raw data to cvs_avg35_inMNI152 at 2mm (not with -mni305)

Session Arguments (some combination required)
  -sf sessidfile  ...
  -df srchdirfile ...
  -s  sessid      ...
  -d  srchdir     ...
  -fsd    fsd <bold>
  -rlf    rlf  : run list file (default all runs)

  -init-fsl : use fsl to initialize bbr registration
  -init-spm : use spm to initialize bbr registration (needs matlab)
  -init-header : use geometry to initialize bbr registration
  -bbr-int ifsd istem : use intermediate volume in sess/ifsd/RRR/istem

Other options (probably not too useful)

  -nomc     : don't do motion correction
  -nostc    : don't do slice-timing correction
  -nosmooth : don't do smoothing
  -nomask   : don't create brain mask
  -noreg    : don't do registration
  -noinorm  : don't do inorm
  -no-subcort-mask : do not apply subcortical masking

  -mcin   mcinstem    : stem to use as input  to MC
  -mcout  mcoutstem   : stem to use as output of MC
  -stcin  stcinstem   : stem to use as input  to STC 
  -stcout stcoutstem  : stem to use as output of STC 
  -smin   sminstem    : stem to use as input  to smoothing 
  -smout  sminstem    : stem to use as output of smoothing 
  -mask   maskstem    : <brain>

  -i    instem    : stem to use as overal input <f>
    
    -regfile regfile   : registration file for use with -surf-fwhm (register.dat)
  -projfrac frac : projection fraction for use with -surf-fwhm (0.5)
  -projfrac-avg  : average over ribbon (not with -projfrac)
  -no-cortex-label : do not use cortex label for masking surfaces

Once the data have been arranged in the proper directory structure and naming convention, they are ready to be preprocessed. Preprocessing includes:

1. Template Creation
2. Brain Mask Creation
3. Registration with FreeSurfer Anatomical
4. Motion Correction
5. Slice Timing Correction (if using)
6. Spatial Normalization
7. Masking
8. Spatial Smoothing   # useful

扩展阅读

Fixing a bad skull strip

FsFastTutorialV6.0

mris_ca_train 从一组带注释的主题创建地图集、mris_ca_label 对于单个主题,生成一个注释文件,其中每个皮质表面顶点都分配有一个神经解剖标签、mris_sample_parc 采样

应用场景

颅骨去除

  • mri_watershed (运行时长短,约11s,Recommend)

    $ mri_watershed sample-001.nii.gz output.nii.gz
    # or
    $ mri_watershed sample-001.nii.gz output.nii    # 过程参数有细微差别,轮廓效果基本一致
    

    i. 输入输出维度保持一致.

    ii.freeview -v output.nii 仅显示黑白轮廓图,freeview -v output.nii.gz 会显示内部纹理细节

Linux Freesurfer脑数据分割

mri_watershed -T1 -t 20 input_file output_file

命令行,经过试验,加入-T1会避免由于原图的灰度值范围不对导致的报错,也可以更干净地去除脑壳,阈值选20(加入-T1比不加去得更干净),但可能会误剔除,需测试后再进行批处理操作。

  • recon-all 方法(运行时间长,约10min) 可参考:比较FSL/FreeSurfer/ANTs的脑提取工具

    $ export SUBJECTS_DIR=~/Desktop/subjects
    $ recon-all -i input.nii.gz -s testFreeSurfer -autorecon1
    $ mri_convert --out_orientation RAS -rt nearest --reslice_like input.nii.gz \
     -it mgz ${SUBJECTS_DIR}/testFreeSurfer/mri/brainmask.mgz \
     -ot nii output_brain.nii.gz
    

    数据默认放在 SUBJECTS_DIR 这个变量指定的目录下,FreeSurfer 的输出格式是 mgz,可以使用
    mri_convert 转换成 nifti 格式。同时 mri_convert 也可以改变朝向,如果朝向发生了变化的话。

    输入输出维度保持一致.

对比:两种方法效果基本一致,recon-all提取的输出细节更细腻一点

预处理分割

after-autorecon1, -autorecon2 includes 白质分割、皮下组织分割

Multimodal Integration

  • Multimodal Registration perform multi-modal integration in FreeSurfer using fMRI and dMRI analysis. 可进行手动配准;亦可使用配准文件(例register.lta)进行自动配准

FAQ

  • Runtime is so long. Can we use GPU accelerate? -use-gpu

    $ recon-all -i sample-001.nii.gz -s SkullStrip_FreeSurfer -autorecon1 -use-gpu
    
    Testing for CUDA device:
    /usr/local/freesurfer/bin/mri_em_register_cuda: error while loading shared libraries: libcudart.so.5.0: cannot open shared object file: No such file or directory
    Linux captain-System-Product-Name 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    
    recon-all -s SkullStrip_FreeSurfer exited with ERRORS at 2019年 07月 18日 星期四 18:23:50 CST
    
    For more details, see the log file 
    To report a problem, see http://surfer.nmr.mgh.harvard.edu/fswiki/BugReporting
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,029评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,395评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,570评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,535评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,650评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,850评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,006评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,747评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,207评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,536评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,683评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,342评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,964评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,772评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,004评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,401评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,566评论 2 349