Hello Francois,
How do the FreeSurfer sphere works in brainstorm ? When importing a FreeSurfer folder, the sphere are imported for all surface regardless of the number of vertex in each surface. How is it done ?
When I look in tess_addsphere it doesn't seem to do any downsampling. But if I execute
sphere_path = fullfile(folder_path,'surf/',"lh.sphere.reg");
SphereVertices = mne_read_surface(sphere_path);
i get:
/Users/edelaire1/Desktop/ICBM512/surf/lh.sphere.reg is a triangle file (nvert = 152495 ntri = 304986)
created by edelaire on Thu Aug 4 22:42:03 2022
Read a surface with 152495 vertices from /Users/edelaire1/Desktop/ICBM512/surf/lh.sphere.reg
But the surface I am working with (that is also linked to this sphere) only has 15 000 vertex.
I think this is linked also the one issue I have with Xhemi; after projecting the scout from left to right hemisphere; the scout is on a surface with 152495 vertex.
( /Users/edelaire1/Desktop/ICBM512/surf/lh.fsaverage_sym.sphere.reg is a triangle file (nvert = 152495 ntri = 304986))
Edit:
So it seems that the sphere are registered with lh/rh pial surface. So when we import a Fs folder, brainstorm import the pial surface, the sphere and then downsample the two :
[iLh, BstTessLhFile, nVertOrigL] = import_surfaces(iSubject, TessLhFile, 'FS', 0);
[TessMat, err] = tess_addsphere(BstTessLhFile, TessLsphFile, 'FS');
[BstTessLhLowFile, iLhLow, xLhLow] = tess_downsize(BstTessLhFile, nVertHemi, 'reducepatch');
and to do that in Tess_downsize:
[NewTessMat.Faces, NewTessMat.Vertices] = reducepatch(TessMat.Faces, TessMat.Vertices, dsFactor);
[tmp, I, J] = intersect(TessMat.Vertices, NewTessMat.Vertices, 'rows');
% Re-order the vertices so that they are in the same order in the output surface
[I, iSort] = sort(I);
newSphVert = TessMat.Reg.Sphere.Vertices(I,:);
NewTessMat.Reg.Sphere.Vertices = newSphVert;
Edit2: Ok so I tried to save the vector I; that is used to sample from the sphere; to then resample other sphere :
sphere_path = fullfile(folder_path,'surf/',"lh.fsaverage_sym.sphere.reg");
[verts, faces] = mne_read_surface(sphere_path);
verts = verts(Idx_L, : );
faces = faces(Idx_L, : );
sphere_path_out = fullfile(folder_path,'bst_label/',"lh.fsaverage_sym.sphere_resample.reg");
mne_write_surface(sphere_path_out,verts,faces,'resampled')
but doesn't work:
$Id: mris_apply_reg.c,v 1.6.2.4 2016/12/08 22:02:40 zkaufman Exp $
cwd /NAS/home/edelaire/Documents/FS_db/ICBM512/bst_label
cmdline mris_apply_reg --src-label scout_precentral_left.label --streg xhemi.lh.fsaverage_sym.sphere_resample.reg lh.fsaverage_sym.sphere_resample.reg --trg scout_precentral_left_right.label
sysname Linux
hostname perf-imglab07
machine x86_64
user edelaire
srcvalfile (null)
trgvalfile scout_precentral_left_right.label
nsurfs 2
jac 0
revmap 0
1 Loading xhemi.lh.fsaverage_sym.sphere_resample.reg
f[732]->v[1] = 7503 - out of range!
I guess the issue might be 'faces = faces(Idx_L, : );';
Edit 3; Found a way using the left-> right sphere coregistration :
Red: Original scout
Green : Projected
Willl clean up the code and make a PR. PR opened here: Scout Projection from one hemisphere to another by Edouard2laire · Pull Request #566 · brainstorm-tools/brainstorm3 · GitHub
Regards,
Edouard