FreeSurfer offers excellent visualisation capabilities with tksurfer
and FreeView
. However, there are endless other possibilities using various different computer graphics software. In previous posts, it was shown here in the blog how to generate cortical and subcortical surfaces that could be imported into these applications, as well as how to generate models with vertexwise and facewise colours, and even a description of common file formats. It was also previously shown how to arbitrarily change the colours of regions for use with FreeSurfer own tools. However, a method to allow rendering cortical regions with different colours in software such as Blender was missing. This is what this post is about.
The idea is simple: splitting the cortical surface into one mesh per parcellation allows each to be imported as an independent object, and so, it becomes straightforward to apply a different colour for each one. To split, the first step is to convert the FreeSurfer annotation file to a data-per-vertex file (*.dpv
). This can be done with the command annot2dpv
.
./annot2dpv lh.aparc.annot lh.aparc.annot.dpv
Before running, be sure that ${FREESURFER_HOME}/matlab
is in the Octave/matlab, path. With the data-per-vertex file ready, do the splitting of the surface with splitsrf
:
./splitsrf lh.white lh.aparc.annot.dpv lh.white_roi
This will create several files names as lh.white_roi*
. Each corresponds to one piece of the cortex, in *.srf
format. To convert to a format that can be read directly into computer graphics software, see the instructions here.
The annot2dpv
and splitsrf
are now included in the package for areal analysis, available here.
With the meshes imported, let your imagination and creativity fly. Once produced, labels can be added to the renderings using software such as Inkscape, to produce images as the one above, of the Desikan-Killiany atlas, which illustrates the paper Cortical Thickness or Gray Matter Volume: The Importance of Selecting the Phenotype for Imaging Genetics Studies.
Another method is also possible, without the need to split the cortex, but instead, painting the voxels. This can be done with the command replacedpx
, also available from the package above. In this case each region index is replaced by its corresponding statistical value (or any other value), then maps are produced with the dpx2map
, shown in an earlier blog post, here. This other method, however, requires that the label indices are known for each region, which in FreeSurfer depends on the rgb colors assigned to them. Moreover, the resulting maps don’t have as sharp and beautiful borders as when the surface is split into independent pieces.
Thanks for posting this. A lot of your posts have been super helpful in the work I’m currently doing (ECoG imaging/visualization).
I can’t get annot2dpv to run though. I’m on ubuntu 12/linux, using freesurfer 5.3.0.
I run ./annot2dpv lh.aparc.annot lh.aparc.annot.dpv and get ./annot2dpv: Command not found.
I have $FREESURFER_HOME defined correctly, and source as well (with annot2dpv executable in cwd). I have also: setenv MATLABPATH $FREESURFER_HOME/matlab/
Any idea on what could be going wrong?
Thanks for your help.
-zack
Hi Zack,
It looks like you need to make the annot2dpv executable (use chmod).
All the best,
Anderson
Hi Dr. Winkler,
I’m pulling up an error when I attempt ./splitsrf lh.white lh.aparc.annot.dpv lh.white_roi
error: fgets: invalid stream number = -1
error: called from:
error: …/areal/share/srfread.m at line 18, column 1
error: …/areal/bin/splitsrf at line 60, column 10
Thanks,
Brett
Hi Brett,
First thing is that the file needs to be in ASCII format. Have a look at this article: https://brainder.org/2011/09/25/braindering-with-ascii-files/
That said, this error seems to be caused by the file lh.white not being found. Double check that it actually exists in the same directory (but even if it exists, an error should be produced, as it’s not ASCII).
All the best,
Anderson
Hi,
I’m having the same issue where the srf2obj script produces a lh.pial.obj file that is Zero bytes in size. Did you find a solution to the issue?
Thanks!
I just replied to your other comment on the same issue in the pertaining article: https://brainder.org/2012/05/08/importing-freesurfer-cortical-meshes-into-blender/
Hi, after I correct for the error Brett mentioned I receive this message:
error: fscanf: invalid size specification
error: called from:
How can I correct for this?
Thanks,
Kevin
I apologize once again, I solved the problem by converting the lh.white file to lh.white.asc.
This is a really nice service to the community interested in making nice looking figures from their data – thanks! I was wondering if you would be willing to share what kind of shader/rendering settings you had for the Karlsgodt et al paper? – I really like that semi-transparent blue look, but from lots of fiddling around in Blender I haven’t been able to get anything even close!
Hi Daniel,
This was long ago, I’d need to search old hard drives. Also, it was before Blender 2.50, which was completely different. That said, Blender offers many possibilities, and there is plenty of documentation online. It shouldn’t be hard to come up with nice, novel ways to show the brain.
All the best,
Anderson
Thanks for the further suggestions. It took a bit of finding as I wasn’t sure how people would describe the look I was searching for – but this page has quite a nice description of a nice effect which works well with Cycles in Blender http://blender.stackexchange.com/questions/28422/how-to-render-a-mesh-transparent-with-a-color-on-its-edges-only-with-nodes
Interesting, thanks for sharing.
Hi Dr. Winkler, I am looking to import tractography data (.vtk files) into Blender. Right now, I am converting the .vtk into .stl with Slicer. I am wondering if you have any other suggestions. Also, since the tractography files are just a series of 3D (x,y,z) coordinates, is there a way to have these points connected into Blender?
Thanks,
Kevin
Hi Kevin,
I don’t have any tool available that would do that, sorry. It should be possible, though.
All the best,
Anderson
Hi Dr. Winkler, I am running the annot2dpv
but I receive this error message:
warning: function name `Read_Brain_Annotation’ does not agree with function file name `/usr/apps/freesurfer/matlab/read_annotation.m’
Reading from version 2
colortable with 36 entries read (originally /autofs/space/terrier_001/users/nicks/freesurfer/average/colortable_desikan_killiany.txt)
error: `dpxwrite’ undefined near line 74 column 1
What should I do? Thanks
Never mind! I added to my octave path. Thanks!
Hi Kevin, I am now facing exactly the same problem. I tried to use addpath(“/usr/local/freesurfer/matlab”) and savepath() to add the matlab path. But the error is still there. What steps did you take to fix it?
Hi Kevin, I am not facing the same problem. I used addpath(“/usr/local/freesurfer/matlab”) and savepath() in octave but the error still appear. What steps did you take to fix this?
Hello. It seems as though srfread.m (called by splitsrf) is not able to read the surface file generated by Freesurfer 5.3 (lh.white). Is this correct?
Hi Tyler,
Yes, correct. That function will only open after files have been converted to ASCII. You’d use mris_convert to convert.
Hope this helps!
All the best,
Anderson
Hi Dr. Winkler, are your functions expected to work for Freesurfer 5.3 surface data? I am having issues reading the faces and vertices in srfread.
Yes, just need conversion as in the answer to the other comment.