recon-all of freesurfer

10 min read

recon-all is a batch program and runs >30 steps.  It easily takes 30 hours to finish one subject.

Use tkmedit CON14 T1.mgz and tksurfer CON14 lh inflated to visualize images. More about visualization with freesurfer.

Note: commands are in green. They are copied from the log files.

View images for every step here

Before you start, you need to put the structural images into certain directory hierarchy and set environment variable. Assume folder “structural” is where subjects’ structural images are. Under “structural”, you have folders “SUBJ1”, “SUBJ2”, “CON14” etc for every subject. You will have to put your structural images to “structural/SUBJ1/mri/orig/001.mgz”. If you have multiple images for this subject, use “002.mgz” etc. (If you original file format is not mgz, check out how to convert image formats).

structural
    |--SUBJ1
        |--mri
            |--orig
                |--001.mgz
                |--002.mgz

Then set environment variable in linux shell:
setenv SUBJECTS_DIR $PWD

  1. motion correction, and conform
    input: mri/orig/00?.mgz
    output: mri/orig.mgz (through mri/rawavg.mgz)
    If you have multiple structural images (001.mgz, 002.mgz, etc), then motion correction will be done and rawavg.mgz is created. If you have only one image (001.mgz), it simply copies the file and rename to rawavg.mgz.
    cp CON14/mri/orig/001.mgz CON14/mri/rawavg.mgz
    Then conform using mri_convert:
    mri_convert CON14/mri/rawavg.mgz CON14/mri/orig.mgz --conform
    Conform is to make voxel size 1x1x1mm and same number of voxels (256) along x,y,z directions (iso). Data is written to orig.mgz.
  2. non-uniform intensity normalization
    input: mri/orig.mgz
    output: mri/nu.mgz
    mri_nu_correct.mni --i orig.mgz --o nu.mgz --n 2
    Non-parametric Non-uniform intensity Normalization (N3), corrects for intensity non-uniformity in MR data, making relatively few assumptions about the data. This runs the MINC tool ‘nu_correct’. By default, four iterations of nu_correct are run. The flag -nuiterations specification of some other number of iterations.
  3. talairach transformation
    input: mri/nu.mgz
    output: transform/talairach.auto.xfm
    talairach_avi --i nu.mgz --xfm transforms/talairach.auto.xfm
    This computes the affine transform from the orig volume to the MNI305 atlas using the MINC program mritotal (see Collins, et al, 1994) through a FreeSurfer script called talairach. Several of the downstream programs use talairach coordinates as seed points. You can/should check how good the talairach registration is using tkregister2 --s subjid --fstal. tkregister2 allows you to compare the orig volume against the talairach volume resampled into the orig space. Run “tkregister2 –help” for more information. Creates the files mri/transform/talairach.auto.xfm and talairach.xfm.
    This step produces a long log.
  4. intensity normalization
    input: mri/nu.mgz
    output: mri/T1.mgz
    mri_normalize -g 1 nu.mgz T1.mgz
    Performs intensity normalization of the orig volume and places the result in mri/T1.mgz. Attempts to correct for fluctuations in intensity that would otherwise make intensity-based segmentation much more difficult. Intensities for all voxels are scaled so that the mean intensity of the white matter is 110. If there are problems with the normalization, users can add control points. See also Normalization2.
  5. skull strip
    input: mri/nu.mgz
    output: mri/brainmask.mgz, mri/brainmask.auto.mgz
    mri_em_register -skull nu.mgz /usr/local/freesurfer/average/RB_all_withskull_2008-03-26.gca transforms/talairach_with_skull.lta
    Removes the skull from mri/T1.mgz and stores the result in mri/brainmask.auto.mgz and mri/brainmask.mgz. Runs the mri_watershed program. If the strip fails, users can specify seed points (-wsseed) or change the threshold (-wsthresh, -wsmore, -wsless). The -autorecon1 stage ends here.
  6. EM (GCA) Registration (-<no>gcareg)
    input: mri/nu.mgz, mri/brainmask.mgz
    output: mri/transforms/talairach.lta
    mri_em_register -mask brainmask.mgz nu.mgz /usr/local/freesurfer/average/RB_all_2008-03-26.gca transforms/talairach.lta
    Computes transform to align the mri/nu.mgz volume to the default GCA atlas found in FREESURFER_HOME/average (see -gca flag for more info). Creates the file mri/transforms/talairach.lta. The -autorecon2 stage starts here.
  7. CA Normalize (-<no>canorm)
    input: mri/nu.mgz, mri/brainmask.mgz
    output: mri/norm.mgz

    mri_ca_normalize -mask brainmask.mgz nu.mgz /usr/local/freesurfer/average/RB_all_2008-03-26.gca transforms/talairach.lta norm.mgz
    Further normalization, based on GCA model. Creates mri/norm.mgz.

  8. CA Register (-<no>careg)
    input: mri/norm.mgz, mri/brainmask.mgz
    output: talairach.m3z
    mri_ca_register -align-after -nobigventricles -mask brainmask.mgz -T transforms/talairach.lta norm.mgz /usr/local/freesurfer/average/RB_all_2008-03-26.gca transforms/talairach.m3z
    Computes a nonlinear transform to align with GCA atlas. Creates the file mri/transform/talairach.m3z.
    This step is very loooooong (10 hours)
  9. Remove neck (-<no>rmneck)
    input: mri/nu.mgz
    output: mri/nu_noneck.mgz
    mri_remove_neck -radius 25 nu.mgz transforms/talairach.m3z /usr/local/freesurfer/average/RB_all_2008-03-26.gca nu_noneck.mgz
    The neck region is removed from the NU-corrected volume mri/nu.mgz. Makes use of transform computed from prior CA Register stage. Creates the file mri/nu_noneck.mgz.
  10. EM Registration, with Skull (-<no>skull-lta)
    input: mri/nu_noneck.mgz
    output: mri/transforms/talairach_with_skull.lta
    mri_em_register -skull -t transforms/talairach.lta nu_noneck.mgz /usr/local/freesurfer/average/RB_all_withskull_2008-03-26.gca transforms/talairach_with_skull.lta
    Computes transform to align volume mri/nu_noneck.mgz with GCA volume possessing the skull. Creates the file mri/transforms/talairach_with_skull.lta.
  11. CA Label (-<no>calabel)
    input: mri/norm.mgz, mri/transforms/talairach.m3z
    output: mri/aseg.auto.mgz, mri/aseg.mgz, (through mri/aseg.auto_noCCseg.mgz)
    mri_ca_label -align -nobigventricles norm.mgz transforms/talairach.m3z /usr/local/freesurfer/average/RB_all_2008-03-26.gca aseg.auto_noCCseg.mgz
    mri_cc -aseg aseg.auto_noCCseg.mgz -o aseg.auto.mgz CON14
    Labels subcortical structures, based in GCA model. Creates the files mri/aseg.auto.mgz and mri/aseg.mgz.
  12. ASeg Stats (-<no>segstats)
    ?Computes statistics on the segmented subcortical structures found in mri/aseg.mgz. Writes output to file stats/aseg.stats.
  13. Normalization2 (-<no>normalization)
    input: mri/norm.mgz, mri/aseg.mgz, mri/brainmask.mgz
    output: mri/brain.mgz
    mri_normalize -aseg aseg.mgz -mask brainmask.mgz norm.mgz brain.mgz
    mri_mask -T 5 brain.mgz brainmask.mgz brain.finalsurfs.mgz
    Performs a second (major) intensity correction using only the brain volume as the input (so that it has to be done after the skull strip). Intensity normalization works better when the skull has been removed. Creates a new brain.mgz volume. The -autorecon2-cp stage begins here. If -noaseg flag is used, then aseg.mgz is not used by mri_normalize.
  14. WM Segmentation (-<no>segmentation)
    input: brain.mgz
    output: wm.seg.mgz
    mri_segment brain.mgz wm.seg.mgz
    mri_edit_wm_with_aseg -keep-in wm.seg.mgz brain.mgz aseg.mgz wm.asegedit.mgz
    mri_pretess wm.asegedit.mgz wm norm.mgz wm.mgz
    Attempts to separate white matter from everything else. The input is mri/brain.mgz, and the output is mri/wm.mgz. Uses intensity, neighborhood, and smoothness constraints. This is the volume that is edited when manually fixing defects. Calls mri_segment, mri_edit_wm_with_aseg, and mri_pretess. To keep previous edits, run with -keepwmedits. If -noaseg is used, them mri_edit_wm_aseg is skipped.
  15. Cut/Fill (-<no>fill)
    input: wm.mgz
    output: filled.mgz
    mri_fill -a ../scripts/ponscc.cut.log -xform transforms/talairach.lta -segmentation aseg.auto_noCCseg.mgz wm.mgz filled.mgz
    This creates the subcortical mass from which the orig surface is created. The mid brain is cut from the cerebrum, and the hemispheres are cut from each other. The left hemisphere is binarized to 255. The right hemisphere is binarized to 127. The input is mri/wm.mgz and the output is mri/filled.mgz. Calls mri_fill. If the cut fails, then seed points can be supplied (see -cc-crs, -pons-crs, -lh-crs, -rh-crs). The actual points used for the cutting planes in the corpus callosum and pons can be found in scripts/ponscc.cut.log. The stage -autorecon2-wm begins here. This is the last stage of volumetric processing. If -noaseg is used, then aseg.mgz is not used by mri_fill.
  16. Tessellation (-<no>tessellate)
    input: filled.mgz, norm.mgz
    output: surf/lh.orig.nofix (through filled-pretess255.mgz)
    mri_pretess ../mri/filled.mgz 255 ../mri/norm.mgz ../mri/filled-pretess255.mgz
    mri_tessellate ../mri/filled-pretess255.mgz 255 ../surf/lh.orig.nofix
    mris_extract_main_component ../surf/lh.orig.nofix ../surf/lh.orig.nofix
    This is the step where the orig surface (ie, surf/?h.orig.nofix) is created. The surface is created by covering the filled hemisphere with triangles. Runs mri_tessellate. The places where the points of the triangles meet are called vertices. Creates the file surf/?h.orig.nofix Note: the topology fixer will create the surface ?h.orig.
  17. Orig Surface Smoothing (-<no>smooth1, -<no>smooth2)
    input: surf/lh.orig.nofix
    output: surf/lh.smoothwm.nofix
    mris_smooth -nw ../surf/lh.orig.nofix ../surf/lh.smoothwm.nofix
    After tesselation, the orig surface is very jagged because each triangle is on the edge of a voxel face and so are at right angles to each other. The vertex positions are adjusted slightly here to reduce the angle. This is only necessary for the inflation processes. Creates surf/?h.smoothwm(.nofix). Calls mris_smooth. Smooth1 is the step just after tessellation, and smooth2 is the step just after topology fixing.
  18. Inflation (-<no>inflate1, -<no>inflate2)
    input: surf/lh.smoothwm.nofix
    output: surf/lh.inflated.nofix, lh.sulc, lh.curv, lh.area
    mris_inflate -no-save-sulc ../surf/lh.smoothwm.nofix ../surf/lh.inflated.nofix
    Inflation of the surf/?h.smoothwm(.nofix) surface to create surf/?h.inflated. The inflation attempts to minimize metric distortion so that distances and areas are perserved (ie, the surface is not stretched). In this sense, it is like inflating a paper bag and not a balloon. Inflate1 is the step just after tessellation, and inflate2 is the step just after topology fixing. Calls mris_inflate. Creates ?h.inflated, ?h.sulc, ?h.curv, and ?h.area.
  19. QSphere (-<no>qsphere)
    input: lh.inflated.nofix
    output: lh.qsphere.nofix
    mris_sphere -q ../surf/lh.inflated.nofix ../surf/lh.qsphere.nofix
    This is the initial step of automatic topology fixing. It is a quasi-homeomorphic spherical transformation of the inflated surface designed to localize topological defects for the subsequent automatic topology fixer. Calls mris_sphere. Creates surf/?h.qsphere.nofix.
  20. Automatic Topology Fixer (-<no>fix)
    input: qsphere.nofix
    output: lh.orig
    mris_fix_topology -mgz -sphere qsphere.nofix -ga CON14 lh
    mris_euler_number ../surf/lh.orig
    mris_remove_intersection ../surf/lh.orig ../surf/lh.orig
    Finds topological defects (ie, holes in a filled hemisphere) using surf/?h.qsphere.nofix, and changes the orig surface (surf/?h.orig.nofix) to remove the defects. Changes the number of vertices. All the defects will be removed, but the user should check the orig surface in the volume to make sure that it looks appropriate. Calls mris_fix_topology. Creates surf/?h.orig (by iteratively fixing surf/?h.orig.nofix).
  21. Final Surfaces (-<no>finalsurfs)
    input: lh.orig
    output: lh.white, lh.pial, lh.thickness, lh.curv
    mris_make_surfaces -noaparc -mgz -T1 brain.finalsurfs CON14 lh
    Creates the ?h.white and ?h.pial surfaces as well as the thickness file (?h.thickness) and curvature file (?h.curv). The white surface is created by “nudging” the orig surface so that it closely follows the white-gray intensity gradient as found in the T1 volume. The pial surface is created by expanding the white surface so that it closely follows the gray-CSF intensity gradient as found in the T1 volume. Calls mris_make_surfaces.
  22. [need to double check, b/c in the log this step is not here, also find command such as
    mris_calc -o lh.area.mid lh.area add lh.area.pial
    mris_calc -o lh.area.mid lh.area.mid div 2
    mris_calc -o lh.volume lh.area.mid mul lh.thickness]
    Cortical Ribbon Mask (-<no>cortribbon)
    Creates binary volume masks of the cortical ribbon, ie, each voxel is either a 1 or 0 depending upon whether it falls in the ribbon or not. Saved as ?h.ribbon.mgz. Uses mgz regardless of whether the -mgz option is used. The -autorecon2 stage ends here.
  23. Repeat step 17
    output: lh.smoothwm
    mris_smooth -n 3 -nw ../surf/lh.white ../surf/lh.smoothwm
  24. Repeat step 18
    input: lh.smoothwm
    output: lh.inflated
    mris_inflate ../surf/lh.smoothwm ../surf/lh.inflated
    mris_curvature -thresh .999 -n -a 5 -w -distances 10 10 ../surf/lh.inflated
  25. Spherical Inflation (-<no>sphere)
    input: lh.inflated
    output: lh.sphere
    mris_sphere ../surf/lh.inflated ../surf/lh.sphere
    Inflates the orig surface into a sphere while minimizing metric distortion. This step is necessary in order to register the surface to the spherical atlas. (also known as the spherical morph). Calls mris_sphere. Creates surf/?h.sphere. The -autorecon3 stage begins here.
  26. Ipsilateral Surface Registation (Spherical Morph) (-<no>surfreg)
    input: lh.sphere
    output: lh.sphere.reg
    mris_register -curv ../surf/lh.sphere /usr/local/freesurfer/average/lh.average.curvature.filled.buckner40.tif ../surf/lh.sphere.reg
    Registers the orig surface to the spherical atlas through surf/?h.sphere. The surfaces are first coarsely registered by aligning the large scale folding patterns found in ?h.sulc and then fine tuned using the small-scale patterns as in ?h.curv. Calls mris_register. Creates surf/?h.sphere.reg.
  27. [can’t find this step, but find command mris_jacobian ../surf/lh.white ../surf/lh.sphere.reg ../surf/lh.jacobian_white ]Contralateral Surface Registation (Spherical Morph) (-<no>contasurfreg)
    Same as ipsilateral but registers to the contralateral atlas. Creates lh.rh.sphere.reg and rh.lh.sphere.reg.
  28. Average Curvature (-<no>avgcurv)
    input: lh.sphere.reg
    output: lh.avg_curv
    mrisp_paint -a 5 /usr/local/freesurfer/average/lh.average.curvature.filled.buckner40.tif#6 ../surf/lh.sphere.reg ../surf/lh.avg_curv
    Resamples the average curvature from the atlas to that of the subject. Allows the user to display activity on the surface of an individual with the folding pattern (ie, anatomy) of a group. Calls mrisp_paint. Creates surf/?h.avg_curv.
  29. Cortical Parcellation (-<no>cortparc, -<no>cortparc2)
    input: mri/aseg.mgz, surf/lh.sphere.reg
    output: label/lh.aparc.annot
    mris_ca_label -aseg ../mri/aseg.mgz CON14 lh ../surf/lh.sphere.reg /usr/local/freesurfer/average/lh.curvature.buckner40.filled.desikan_killiany.2007-06-20.gcs ../label/lh.aparc.annot
    Assigns a neuroanatomical label to each location on the cortical surface. Incorporates both geometric information derived from the cortical model (sulcus and curvature), and neuroanatomical convention. Calls mris_ca_label. -cortparc creates label/?h.aparc.annot, and -cortparc2 creates /label/?h.aparc.a2005s.annot.
  30. Parcellation Statistics (-<no>parcstats)
    input: stats/lh.aparc.stats, label/lh.aparc.annot
    output: label/aparc.annot.ctab
    mris_anatomical_stats -mgz -f ../stats/lh.aparc.stats -b -a ../label/lh.aparc.annot -c ../label/aparc.annot.ctab CON14 lh
    Runs mris_anatomical_stats to create a summary table of cortical parcellation statistics for each structure, including 1. structure name 2. number of vertices 3. total surface area (mm^2) 4. total gray matter volume (mm^3) 5. average cortical thickness (mm) 6. standard error of cortical thicknessr (mm) 7. integrated rectified mean curvature 8. integrated rectified Gaussian curvature 9. folding index 10. intrinsic curvature index. For -parcstats, the file is saved in stats/?h.aparc.stats. For -parcstats2, the file is saved in stats/?h.aparc.a2005s.stats.
  31. Repeat step 29 (Cortical Parcellation)
    mris_ca_label -aseg ../mri/aseg.mgz CON14 lh ../surf/lh.sphere.reg /usr/local/freesurfer/average/lh.atlas2005_simple.gcs ../label/lh.aparc.a2005s.annot
  32. Repeat step 30 (Parcellation statistics)
    mris_anatomical_stats -mgz -f ../stats/lh.aparc.a2005s.stats -b -a ../label/lh.aparc.a2005s.annot -c ../label/aparc.annot.a2005s.ctab CON14 lh
  33. Repeat step 16-32 for right hemisphere
  34. ASeg Stats
    mri_segstats –seg mri/aseg.mgz –sum stats/aseg.stats –pv mri/norm.mgz –excludeid 0 –brain-vol-from-seg –brainmask mri/brainmask.mgz –in mri/norm.mgz –in-intensity-name norm –in-intensity-units MR –etiv –subject CON14 –surf-wm-vol –ctab /usr/local/freesurfer/ASegStatsLUT.txt
  35. Cortical ribbon mask
    mris_volmask –label_left_white 2 –label_left_ribbon 3 –label_right_white 41 –label_right_ribbon 42 –save_ribbon –save_distance CON14
  36. AParc-to-ASeg
    mri_aparc2aseg –s CON14 –volmask
    mri_aparc2aseg –s CON14 –volmask –a2005s
  37. WMParc
    mri_aparc2aseg –s CON14 –labelwm –hypo-as-wm –rip-unknown –volmask –o mri/wmparc.mgz –ctxseg aparc+aseg.mgz
  38. mri_segstats –seg mri/wmparc.mgz –sum stats/wmparc.stats –pv mri/norm.mgz –excludeid 0 –brain-vol-from-seg –brainmask mri/brainmask.mgz –in mri/norm.mgz –in-intensity-name norm –in-intensity-units MR –etiv –subject CON14 –surf-wm-vol –ctab /usr/local/freesurfer/

Check out recon-all manual in freesurfer wiki.

第十九期 fNIRS Journal Club 通知 2021/05/29,9:30am

美国普渡大学童云杰助理教授,将为大家讲解他们组最近被接受的一篇使用近红外相位信息研究脑血流变化的文章。热烈欢迎大家参与讨论。 时间: 北京时间2021年5月29日上午9:30地点: https://zoom.com房间号: 846 8391 7517密码: 805190 童云杰教授简介:普渡大学 生物医学工程助理教授、博士生导师。主攻方向是多模态脑成像, 包括核磁,fNIRS, EEG。关注脑功能及生理信号的提取与研究。发表论文九十余篇,引用上千次(H-index = 20)。 童教授要讲解的文章如下: Liang Z, Tian H, Yang HC, Arimitsu T, Takahashi...
Xu Cui
12 sec read

第十八期 fNIRS Journal Club 视频

北京时间2021年4月25日10点,北京师范大学的朱朝喆教授为大家讲解了他们最近几年在经颅脑图谱(Transcranial brain Atlas) 方面做的工作。视频如下: Youtube: https://youtu.be/EhYPuBPQ5uI Youku: 该视频在优酷上传后被优酷屏蔽,不清楚什么原因。申诉无效。
Xu Cui
3 sec read

第七届全国近红外光谱脑功能成像学术会议

会议日期:2021年5月22日-24日会议地点:天津师范大学 一、 会议简介       近红外光谱脑功能成像(fNIRS)具有设备购买与使用成本低、可在自然环境条件下使用、具有较高的时间分辨率和空间定位能力等特点,受到了脑科学研究的高度重视。“近红外光谱脑功能成像学术会议”是由北京师范大学认知神经科学与学习国家重点实验室朱朝喆教授发起并组织的全国性学术会议。已连续成功举办六届,共吸引全国近百家高校、科研院所及医院的六百余名学者参加。该会议已成为国内规模和影响力最大的fNIRS脑成像学术活动。       本届会议由北京师范大学与天津师范大学联合主办。会议将延用往届会议将学术报告与研究方法工作坊相结合的模式。学术报告模块(5月22日周六)将邀请心理学与认知神经科学领域、基础与临床医学领域以及工程技术领域知名学者汇报其fNIRS最新研究成果;工作坊模块(5月23-24日)由fNIRS领域一线研究者系统讲授fNIRS成像原理、fNIRS实验设计、fNIRS数据分析与统计、fNIRS论文写作以及fNIRS前沿技术等。除理论讲授外,还设置了fNIRS空间定位与数据分析操作(NIRS-KIT软件)环节,此外还安排充足的研讨答疑时间以便与会人员交流互动。       具体日程与详细内容等最新消息请关注后续通知,可通过天津师范大学心理部网站http://psych.tjnu.edu.cn/或北京师范大学国家重点实验室网站http://brain.bnu.edu.cn/,或者扫描下方二维码关注微信公众号-“fNIRS脑成像实验室”查阅更新信息,期盼在天津师范大学与您相聚! 二、会议组织机构 主办单位:教育部人文社会科学重点研究基地天津师范大学心理与行为研究院、天津师范大学心理学部、北京师范大学认知神经科学与学习国家重点实验室会议主席:白学军、朱朝喆组织委员会:赵春健、杨邵峰、侯鑫、曹正操 三、说明1.        学术报告模块注册费:人民币500元/人;工作坊模块注册费:人民币2500元/人。发票为电子发票,内容均为:“会议费”。两个模块各自独立收费,参会者可根据自己需要进行选择。2.        注册费包括各自模块的资料费、午餐费;其他费用自理。3.        会议报告人免除会议模块注册费,其他费用请自理。4.       ...
Xu Cui
18 sec read

3 Replies to “recon-all of freesurfer”

  1. Hi,
    my name is Martina and I’m a student of biomedical engineering in Rome. I’m doing a brain imaging research for my final exam.
    Thank you for your useful info on your website.
    I’m using freesurfer for registration and segmentation of brain images instead of FSL tools (flirt,bet and fast) and then continue to process the data with FSL. But I have a problem: after converting the image generated with freesurfer mri_convert to “.nii” format it does not overlap with FSL’s reference MNI152.
    I know that freesurfer uses talairach reference. Is it true? May it be the problem?
    How can I superimpose properly the images?
    Do you know any workaround?
    Thank you very much.
    Regards
    Martina Andellini

  2. Dear Xu,

    Thanks for the explanation, would it be possible to help me on the following?

    I want to get the segmented cortex from the Talairach space to the standard space and convert it to a mask so that I can use it to extract the cortex from other scans (T2 and T2*) which have already been co-registered to the original T1 image in its standard space.

    Many thanks
    Ali

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading