retinotopy with freesurfer

2 min read

[this post is under frequent updating]

Retinotopy analysis consists two parts, one on high resolution structural images (segmentation, inflation, cut, etc), the other on functional images.

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).


Then set environment variable in linux shell:

  1. Run command recon-all
    recon-all -all -subjid CON14
    to process structural image. This will run for a long time (30 hours). To see what steps are being done, checkout recon-all manual.
  2. Cut occiput surface
    Run command
    tksurfer CON14 lh inflated
    to display the inflated left hemisphere.
    Rotate the brain until the medial surface is facing you.
    Then select points along calcarine fissure and press button “Cut line”.

    Select 3 points to define the cutting plane: 2 on medial side and 1 on lateral side. Choose a 4th point to specify which portion of surface to keep and press button “Cut plane”.

    Save (File > Patch > Save As) as file lh.occip.patch.3d.
    (To know how to cut full brain, check out this PDF)
  3. Flatten occiput surface
    cd to the subject’s “surf” directory and run
    mris_flatten -w 0 -distances 20 7 lh.occip.patch.3d  lh.occip.patch.flat
    To visualize the patch, you can first load the subject’s inflated surface, then File > Patch > Load Patch …
    Flattening takes 1-2 hours.
  4. Repeat step 2 and 3 for the right hemisphere.


  1. Create directory hierarchy
    Create directory “retinotopy”, then under this folder, create directories SUBJ01, SUBJ02, SUBJ03, CON14 etc. Each of these directories is for a subject. Under each subject’s directory, create folder “bold”. In “bold”, create folder “001”, “002” etc, they are folders for runs of a single subject.  Note, the name of run folders has to be 3-digit with padding 0s. Something like “01” or “1” won’t work. Under run folders, put the functional imaging data “f.nii” and paradigm file (rtopy.par) there. If your functional image is not a nii file, check out how to convert functional images to Nifti format.

    Under SUBJ01, create a file called “subjectname” with one line string “SUBJ1” — assuming “SUBJ1” is this subject’s name under “structural” folder. This file is to link this subject’s functional and structural data.

    Create file sessid under retinotopy. In this file each line is the folder’s name for each subject.


    Please refer to freesurfer’s wiki for detailed explanation. And the following diagram is very helpful:

    In rtopy.par file, write two lines
    stimtype eccen
    direction pos

    stimtype polar
    direction neg

  2. Stay in folder “retinotopy”
  3. Create analysis
    Run the following command -a rtopy -TR 2 -designtype retinotopy -paradigm rtopy.par -funcstem fmcsm5 -ncycles 8
    Note: ncycles is the number of periods in each run of either ecc or mm. For example, if you have 10 steps going from a small circle to a big circle in ecc, and repeat this for 4 times, then ncycles=4.
    After running this program, you will find a directory “rtopy” newly created. There you find two files, analysis.cfg and You may want to change some values there for your own data (e.g. -nskip). If you already removed the extra images, you don’t need to specify -nskip.
  4. Preprocess functional data
    Run command
    preproc-sess -sf sessid -fwhm 5
    preproc-sess -s SUBJ01 -fwhm 5
    It takes about 40s for one run. (For xc only: you should run this command on scuttlebutt, not rumor)
  5. Register against structural images
    Before and after registration, you may use tkregister-sess to view how well the functional images are aligned with structural images.
    tkregister-sess -sf sessid -regheader
    Green lines are the cortical surface. Hit button “compare” to see the alignment.
    To run registration, run command
    fslregister-sess -sf sessid
  6. Run the analysis
    sfa-sess -a rtopy -sf sessid
    (for xc: use scuttlebutt. It takes ~2min)
  7. View intermediate results
    sliceview-sess -sf sessid -a rtopy -c eccen -map h -slice mos
    sliceview-sess -sf sessid -a rtopy -c polar -map h -slice mos
  8. Run paint
    paint-sess -a rtopy -sf sessid
    It takes ~1min.
  9. View final result
    surf-sess -sf sessid -a rtopy -retinotopy fieldsign -flat
    surf-sess -sf sessid -a rtopy -retinotopy eccen -flat
    surf-sess -sf sessid -a rtopy -retinotopy polar -flat
    surf-sess -sf sessid -a rtopy -c polar -flat

Receive email notification via email
Don't want to miss new papers in your field? Check out Stork we developed:

fNIRS Journal Club 视频

546个被试的大型实验是怎么做的?近红外超扫描技术如何揭开群体冲突的神经机制?北京时间2020年5月29日周五上午11点,北京师范大学的马燚娜教授(Yina Ma)为大家讲解了她们组刚刚在Nature Neuroscience发表的文章。下面是报告视频。第一个是在Youtube,第二个是在youku。 Youtube: 她讲的文献如下: Within-group synchronization in the prefrontal cortex associates with intergroup conflict. Nature neuroscience 中文摘要(人工智能翻译,仅供参考):陷入群体的个人有时会失去自己的个性,冒着通常会避免的风险,以无端的敌对态度与外界接触。在这项研究中,我们确定了右侧背外侧前额叶皮层(rDLPFC)和右侧颞顶交界处(rTPJ)的组内神经同步是组间敌对性的潜在机制。我们将546个人组织为91个三对三人小组间比赛,诱导了组内亲和,并使用功能性近红外光谱仪测量了神经活动和组内同步。在组内亲和之后,个人给组内成员的钱比给组外成员的钱多,并且捐出更多的钱来击败竞争对手。组内亲和减少了rDLPFC的活动,并增加了rDLPFC和rTPJ之间的功能连接。尤其是在组外攻击期间,组内亲和还增加了rDLPFC和rTPJ中的组内同步,并且组内rDLPFC同步与组间敌对性正相关。组内同步减少前额活动可能可以解释组内联结如何导致对外界的冲动和集体敌视。
Xu Cui
13 sec read

Remote fNIRS

Everytime I met Dr Leanne Hirshfield, I am impressed by her energy and passion with the fNIRS technology. It was a pleasure listening to...
Xu Cui
4 min read

fNIRS Journal Club 通知 2020/5/29, 11am

546个被试的大型实验是怎么做的?近红外超扫描技术如何揭开群体冲突的神经机制?北京时间2020年5月29日周五上午11点,北京师范大学的马燚娜教授(Yina Ma)将为大家讲解她们组刚刚在Nature Neuroscience发表的文章。 欢迎大家参加并参与讨论。 时间: 北京时间2020年5月29日周五上午11点 地点:房间号: 843 2031 0196 密码: 600516 她要讲的文献如下: Within-group synchronization in the prefrontal cortex associates with intergroup conflict....
Xu Cui
7 sec read

One Reply to “retinotopy with freesurfer”

  1. I’v got a problem about the image displayed as the final result in step 9.
    After run ‘surf-sess -sf sessid -a rtopy -retinotopy eccen -flat’or ‘surf-sess -sf sessid -a rtopy -retinotopy polar -flat’, i got a image with color scales, But i don’t know what does it mean by the cold blue or the warm red. Can you give me a clue about it.
    Thanks ~!

Leave a Reply

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