Luke, attached is a modified read_surf.m which reads the stuff written after the vertex and face data normally found in the surface binary-formatted file. this was reverse-engineered from the source files 'mrisurf.c' (function MRISwriteTriangularSurface) and 'transform.c' (function writeVolGeom). so the new call is:
[v,f,flags,tags]=read_surf('rh.pial'); you can ignore 'flags', and 'tags' is char array, which can be printed, like this: sprintf('%s',tags) giving output like: ans = valid = 1 # volume info valid filename = ../mri/filled-pretess127.mgz volume = 256 256 256 voxelsize = 1.000000000000000e+00 1.000000000000000e+00 1.000000000000000e+00 xras = -1.000000000000000e+00 0.000000000000000e+00 0.000000000000000e +00 yras = 0.000000000000000e+00 0.000000000000000e+00 -1.000000000000000e +00 zras = 0.000000000000000e+00 1.000000000000000e+00 0.000000000000000e +00 cras = 5.399719238281250e+00 1.800000000000000e+01 0.000000000000000e +00 mris_remove_intersection ../surf/rh.orig ...... the volume geometry will always be the first eight lines of text. unfortunately, being text, you will need to do further parsing to extract what you need. after the volume geometry info are provenance strings. Nick On Thu, 2012-11-08 at 08:21 -0500, Luke Bloy wrote: > Thanks for the reply Nick, > > > Yes mris_info does return information I would need. > > > volume geometry: > extent : (256, 256, 256) > voxel : ( 1.0000, 1.0000, 1.0000) > x_(ras) : (-1.0000, 0.0000, 0.0000) > y_(ras) : ( 0.0000, 0.0000, -1.0000) > z_(ras) : ( 0.0000, 1.0000, 0.0000) > c_(ras) : ( 5.8612, -8.9756, -36.8004) > file : ../mri/filled-pretess255.mgz > > > interestingly even if I move the surface file out of the subject's > surf directory it still returns this info, making me think that it is > in the file somewhere. > > > I was looking at read_surf.m last night and it doesnt seem to do > anything with this info, > and http://wideman-one.com/gw/brain/fs/surfacefileformats.htm doesn't > mention any of this info being in the file. is there an updated spec > file on the file formats? > > > Thanks. > -Luke > > > > > > On Wed, Nov 7, 2012 at 3:26 PM, Nick Schmansky > <ni...@nmr.mgh.harvard.edu> wrote: > Luke, > > A quick answer (w/o looking into it too much): does: > > mris_info rh.pial > > give you the info you need? what i'm not sure of is whether > everything > you see in that output is available in the structure that the > matlab > surface reader loads. > > Nick > > > On Wed, 2012-11-07 at 09:17 -0500, Luke Bloy wrote: > > Hi all, > > > > > > > > I’m not sure where the best place to make this request is… > so I > > thought I’ll put this here. > > > > > > > > I often use freesurfer generated surfaces and images in > other software > > packages (Slicer, Matlab etc) for various things. The MGZ > files > > include the origin in the file headers, meaning that > software can > > correctly interpret the world spaces of these images, > allowing correct > > overlays with other results computed from the same scans. > The problem > > is that the surface files treat the 128,128,128 voxel ( of > the T1.mgz > > and other images) as the origin. But the world coordinates > of this > > origin are, to my knowledge not in the surface files. > > > > > > > > This creates the situation that to correctly interpret these > surfaces > > in relation to other coordinates systems, basically I either > need to > > ignore the world coordinates and do some registration, or I > need to > > load both an mgz file (to get the origin) and surface files > to learn > > correct world coordinates of the surfaces. Ideally it seems > like this > > information should be included in the surface files > themselves. > > > > > > > > Hopefully my description of the problem makes some sense. > > > > > > > > Thanks. > > > > Luke > > > > > > > > > > > _______________________________________________ > > Freesurfer mailing list > > Freesurfer@nmr.mgh.harvard.edu > > https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer > > > > > The information in this e-mail is intended only for the person > to whom it is > addressed. If you believe this e-mail was sent to you in error > and the e-mail > contains patient information, please contact the Partners > Compliance HelpLine at > http://www.partners.org/complianceline . If the e-mail was > sent to you in error > but does not contain patient information, please contact the > sender and properly > dispose of the e-mail. > >
function [vertex_coords, faces, flags, tags] = read_surf(fname) % % [vertex_coords, faces] = read_surf(fname) % reads a the vertex coordinates and face lists from a surface file % note that reading the faces from a quad file can take a very long % time due to the goofy format that they are stored in. If the faces % output variable is not specified, they will not be read so it % should execute pretty quickly. % % % read_surf.m % % Original Author: Bruce Fischl % CVS Revision Info: % $Author: fischl $ % $Date: 2011/09/29 14:20:17 $ % $Revision: 1.5 $ % % Copyright © 2011 The General Hospital Corporation (Boston, MA) "MGH" % % Terms and conditions for use, reproduction, distribution and contribution % are found in the 'FreeSurfer Software License Agreement' contained % in the file 'LICENSE' found in the FreeSurfer distribution, and here: % % https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense % % Reporting: freesurfer@nmr.mgh.harvard.edu % %fid = fopen(fname, 'r') ; %nvertices = fscanf(fid, '%d', 1); %all = fscanf(fid, '%d %f %f %f %f\n', [5, nvertices]) ; %curv = all(5, :)' ; % open it as a big-endian file %QUAD_FILE_MAGIC_NUMBER = (-1 & 0x00ffffff) ; %NEW_QUAD_FILE_MAGIC_NUMBER = (-3 & 0x00ffffff) ; TRIANGLE_FILE_MAGIC_NUMBER = 16777214 ; QUAD_FILE_MAGIC_NUMBER = 16777215 ; fid = fopen(fname, 'rb', 'b') ; if (fid < 0) str = sprintf('could not open curvature file %s.', fname) ; error(str) ; end magic = fread3(fid) ; if(magic == QUAD_FILE_MAGIC_NUMBER) vnum = fread3(fid) ; fnum = fread3(fid) ; vertex_coords = fread(fid, vnum*3, 'int16') ./ 100 ; if (nargout > 1) for i=1:fnum for n=1:4 faces(i,n) = fread3(fid) ; end end end elseif (magic == TRIANGLE_FILE_MAGIC_NUMBER) fgets(fid) ; fgets(fid) ; vnum = fread(fid, 1, 'int32') ; fnum = fread(fid, 1, 'int32') ; vertex_coords = fread(fid, vnum*3, 'float32') ; if (nargout > 1) faces = fread(fid, fnum*3, 'int32') ; faces = reshape(faces, 3, fnum)' ; end flags=fread(fid, 3, 'int32'); tags=fread(fid, 100000, 'char'); end vertex_coords = reshape(vertex_coords, 3, vnum)' ; fclose(fid) ;
_______________________________________________ Freesurfer mailing list Freesurfer@nmr.mgh.harvard.edu https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer The information in this e-mail is intended only for the person to whom it is addressed. If you believe this e-mail was sent to you in error and the e-mail contains patient information, please contact the Partners Compliance HelpLine at http://www.partners.org/complianceline . If the e-mail was sent to you in error but does not contain patient information, please contact the sender and properly dispose of the e-mail.