Brain surface plot with MatLab

1 min read

This is an example of brain activation plotted on surface. In many circumstances surface view is much more straightforward than a slice view. Here is how I created such a plot using MatLab and SPM.

Environment and Tools:

  1. Windows XP
  2. MatLab (v7.6)
  3. SPM (v8)

Step 1. Generate “faces” and “vertices” of the surface using SPM

If you prefer to use SPM’s interface, launch SPM, then click “Render …” box and click “Xtract surface”. You are asked to input an image file. Select an image file and press Done. Select “Save Extracted Surface” and a few seconds later you will find a file called “surf_???.mat” saved in the current directory. Load this mat file and you will find two variables, faces and vertices. These two variables will be used in the future steps.

If you prefer to use command line, you can simple call function

spm_surf(‘xxx.img’, threshold)

About the input image: If you want to plot surface of brain, you should use a segmentation tool (such as FSL) to get the gray matter image, and use this image as input to spm_surf. If you want to plot the surface of skull, you can input the original structural image but with careful choice of threshold.

Step 2. Plot the surface

Plot using MatLab’s patch function. Here is a sample code

p=patch(‘faces’,faces,’vertices’,vertices, ‘facecolor’, ‘flat’,  ‘edgecolor’, ‘none’, ‘facealpha’, 1);
facecolor = repmat([1 1 1], length(faces), 1);
set(p,’FaceVertexCData’,facecolor);

daspect([1 1 1])
view(3); axis tight
view([50 -40 100])
camlight
lighting gouraud

Step 3. Overlay a functional image
The strategy here is that you first get the coordinates of the activated voxels and the corresponding colors you want to use for each voxel (presumablly dependent on the intensity of each voxel). Then find the vertices and faces that are “close” to the coordinates, and change the face color.

a. get coordinates

v = spm_vol(imagefile); % functional image file
m = spm_read_vols(v);
pos = find(m>=threshold);

[xyzcor(:,1) xyzcor(:,2) xyzcor(:,3)] = ind2sub(size(m), pos);
xyz = cor2mni(xyzcor, v.mat);
intensity = m(pos);

b. convert intensity to color

tmp = hot; % using ‘hot’ color scheme
mx = max(intensity);
mn = min(intensity);
intensity = round((intensity – mn)/(mx – mn) * 63 + 1);
colors = tmp(intensity,:);

c. plot

distanceThreshold = 2;
p=patch(‘faces’,faces,’vertices’,vertices, ‘facecolor’, ‘flat’,  ‘edgecolor’, ‘none’, ‘facealpha’, 1);
facecolor = repmat([1 1 1], length(faces), 1);
pos = [];
for ii=1:size(xyz, 1)
tmp = find(abs(vertices(:,1) – xyz(ii, 1)) <= distanceThreshold & abs(vertices(:,2) – xyz(ii, 2)) <= distanceThreshold & abs(vertices(:,3) – xyz(ii, 3)) <= distanceThreshold  );
pos = [tmp];
posf = find(sum(ismember(faces, pos),2)>0);
facecolor(posf,:) = repmat(colors(ii,:), length(posf), 1);
end

set(p,’FaceVertexCData’,facecolor);

daspect([1 1 1])
view(3); axis tight
view([50 -40 100])
camlight
lighting gouraud



写作助手,把中式英语变成专业英文


Want to receive new post notification? 有新文章通知我

第五十期fNIRS Journal Club通知2024/03/30, 10am 王一晖

早期的 STEM 教育对于以后的学习至关重要。现有研究尚未就STEM教学法达成共识,学生先验知识对基于故事的STEM教学法的影响还有待探讨。来自澳门大学张娟教授团队的王一晖将会分享基于fNIRS超扫描
Wanling Zhu
9 sec read

第四十九期fNIRS Journal Club视频 高倩博士

Youtube: https://youtu.be/a2QlCFZUytA优酷: https://v.youku.com/v_show/id_XNjM3MjMyNjUxMg==.html 竞技比赛中,
Wanling Zhu
12 sec read

第四十九期fNIRS Journal Club通知2024/02/24, 10am 高倩博士

竞技比赛中,特别是需要注意高度集中的射击项目中,如何保持稳定的注意控制对运动员的表现至关重要。近期的一项研究调查了赛前短时正念练习是否对运动员在射击比赛中的注意控制具有提升作用。来自北京体育大学心理学
Wanling Zhu
9 sec read

12 Replies to “Brain surface plot with MatLab”

  1. thanks for your information. very usefule. But, what’s the function of cor2mni? Is it a spm function or your private one??

  2. Dear Prof. Cui,
    Thanks for your information. When I use SPM to save extract surface, there is only a file named *.surf.gii,
    not the surf_???.mat file. Could you tell me why
    I can’t get the .mat file? Is there any mistakes with me?

    thanks

    shuixia

  3. Dear xu cui
    thank for usefull informations,i have a 144 jpg brain slices and i managed to reconstruct them into 3d VOLUME using isosurface and patch commands of matlab.now i want display only the 3d surface of this volume using only matlab.wish to hear from u.

  4. Hello Mr Chu, I am new in matlab and SVM coding. Please I want to know how I can obtain the frequency, Scale, Phase etc parameters from Matching Pursuit and Gammatonne Frequency Cepstral Coefficient algorithms in order to detect and recognize environmental sound. Thank you very much as I await your response

  5. Dear Mr Cui, I am new in matlab and SVM coding. Please I want to know how I can obtain the frequency, Scale, Phase etc parameters from Matching Pursuit and Gammatonne Frequency Cepstral Coefficient algorithms in order to feed them into the SVM classifier to detect and recognize environmental sound. Thank you very much as I await your response

  6. @Rosemary
    Rosemary, while I want to help, I am not in your field and have no idea what “Matching Pursuit and Gammatonne Frequency Cepstral Coefficient” are.

Leave a Reply

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