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 file fid = fopen(fname, 'rb', 'b'); if (fid < 0), str = sprintf('could not open surface file %s.', fname); error(str); end fprintf('...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) ; end if(~rem(iface, 10000)), fprintf(' %7.0f',iface); end if(~rem(iface,100000)), fprintf('\n'); end end end elseif (magic == TRIANGLE_FILE_MAGIC_NUMBER), fprintf('...reading triangle file\n'); tline = fgets(fid); % read creation date text line tline = fgets(fid); % read info text line Nvertices = fread(fid, 1, 'int32'); % number of vertices Nfaces = fread(fid, 1, 'int32'); % number of faces % vertices are read in column format and reshaped below vertices = fread(fid, Nvertices*3, 'float32'); % faces are read in column format and reshaped faces = fread(fid, Nfaces*3, 'int32'); faces = reshape(faces, 3, Nfaces)'; else str = sprintf('unknown magic number in surface file %s.', fname); error(str); end vertices = 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 :
1. Creating a patch on lh.inflated in Freeview and saving it 2. Flattening the patch using mris_flatten() in terminal 3. 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