External Email - Use Caution
Hi Doug,
Thank you for your help! Yes, I have followed the points using vertex indices but there were some that didn't match up. It could be because of the 1-based indexing. Where would I change this? I am using freesurfer_read_surface.m to read in the vertices and faces :function [vertices, faces] = freesurfer_read_surf(fname)% freesurfer_read_surf - FreeSurfer I/O function to read a surface file%% [vertices, faces] = freesurfer_read_surf(fname)%% Reads the vertex coordinates (mm) and face lists from a surface file.
% Copyright (C) 2000 Darren L. Weber% History: 08/2000, Darren.Weber_at_radiology.ucsf.edu%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% There used to be a line here where ver was set to the version of% the file. Without it, "ver" reverts to a matlab defined structure% and generates an error.%fprintf('FREESURFER_READ_SURF [v %s]\n',ver(11:15));if(nargin < 1)help freesurfer_read_surf;return;end%QUAD_FILE_MAGIC_NUMBER = (-1 & 0x00ffffff) ;%NEW_QUAD_FILE_MAGIC_NUMBER = (-3 & 0x00ffffff) ;TRIANGLE_FILE_MAGIC_NUMBER = 16777214;QUAD_FILE_MAGIC_NUMBER = 16777215;% open it as a big-endian filefid = fopen(fname, 'rb', 'b');if (fid < 0),str = sprintf('could not open surface file %s.', fname);error(str);endfprintf('...reading surface file: %s\n', fname);tic;magic = freesurfer_fread3(fid);if (magic == QUAD_FILE_MAGIC_NUMBER),Nvertices = freesurfer_fread3(fid);Nfaces = freesurfer_fread3(fid);fprintf('...reading %d quad file vertices\n',Nvertices);vertices = fread(fid, Nvertices*3, 'int16') ./ 100 ;if (nargout > 1),fprintf('...reading %d quad file faces (please wait)\n',Nfaces);faces = zeros(Nfaces,4);for iface = 1:Nfaces,for n=1:4,faces(iface,n) = freesurfer_fread3(fid) ;endif(~rem(iface, 10000)), fprintf(' %7.0f',iface); endif(~rem(iface,100000)), fprintf('\n'); endendendelseif (magic == TRIANGLE_FILE_MAGIC_NUMBER),fprintf('...reading triangle file\n');tline = fgets(fid); % read creation date text linetline = fgets(fid); % read info text lineNvertices = fread(fid, 1, 'int32'); % number of verticesNfaces = fread(fid, 1, 'int32'); % number of faces% vertices are read in column format and reshaped belowvertices = fread(fid, Nvertices*3, 'float32');% faces are read in column format and reshapedfaces = fread(fid, Nfaces*3, 'int32');faces = reshape(faces, 3, Nfaces)';elsestr = sprintf('unknown magic number in surface file %s.', fname);error(str);endvertices = reshape(vertices, 3, Nvertices)';fclose(fid);fprintf('...adding 1 to face indices for matlab compatibility.\n');faces = faces + 1;t=toc; fprintf('...done (%6.2f sec)\n\n',t);return
ii) Also, I want to transform a section of the inflated surface into a 2D flatmap, and import it into MATLAB while maintaining the same VertexIDs so I know which vertex on the flatmap corresponds to a vertex on a pial surface. Do you know how I can do this? I have created multiple flatmaps in Freeview by :
- Creating a patch on lh.inflated in Freeview and saving it
- Flattening the patch using mris_flatten() in terminal
- Loading lh.inflated in Freeview and then loading the flattened patch which then creates a 2D flatmap
However, I cannot figure out how to load this 2D flatmap into MATLAB. I've tried saving the result in (3) as a surface and then loading it into matlab with freesurfer_read_surf.m. This takes a long time and the result looks a bit distorted. It also does not conserve the VertexIDs. Do you have any recommendations?
Many thanks again for your help,Sarah
_______________________________________________ Freesurfer mailing list Freesurfer@nmr.mgh.harvard.edu https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer