<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hi Dorothy,
<div class=""><br class="">
</div>
<div class="">The best way to do this is indeed to follow the tutorial. If you don’t want to rerun the freesurfer pipeline things only get complicated.</div>
<div class="">The code you pasted is not correct, because of the reslicing step in between. Creating the ’T’ matrix as a combination of two vox2somethingelse transformation matrices is only allowed if the voxel spaces that correspond to each of the transformations
 is identical. </div>
<div class=""><br class="">
</div>
<div class="">Best wishes,</div>
<div class=""><br class="">
</div>
<div class="">Jan-Mathijs</div>
<div class=""><br class="">
</div>
<div class="">PS: If you insist on trying it, the best way to go about this would be to use the T1w.mgz anatomical image from the freesurfer mri folder for the headmodel creation. Before the headmodel creation, you probably would want to coregister this image
 to the coordinate system of your EEG/MEG sensors.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
J.M.Schoffelen, MD PhD<br class="">
Senior Researcher, VIDI-fellow - PI, language in interaction<br class="">
Telephone: +31-24-3614793</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Physical location: room 00.028</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Donders Centre for Cognitive Neuroimaging, Nijmegen, The Netherlands<br class="">
<br class="">
<br class="">
</div>
</div>
</div>
</div>
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 19 Sep 2018, at 22:41, Dorothy Sincasto <<a href="mailto:dsincasto@gmail.com" class="">dsincasto@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">Dear fieldtrippers
<div class=""><br class="">
</div>
<div class="">I would like to align the headmodel of a subject with the freesurfer surface. It seems that this is a bit different than the fieldtrip mne tutorial, as we already have the freesurfer surfaces  (so we did not align the mri, save them and run freesurfer).</div>
<div class=""><br class="">
</div>
<div class="">To try to convert the freesurface surface coordinates to the subjects MEG coordinates I do:</div>
<div class="">
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px">
<span class="gmail-Apple-converted-space"> </span><br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg = [];</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.method = <span class="gmail-s1" style="color:rgb(178,69,243)">'interactive'</span>;</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.coordsys = <span class="gmail-s1" style="color:rgb(178,69,243)">'spm'</span>;</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mri_spm<span class="gmail-Apple-converted-space">    </span>= ft_volumerealign(cfg, mri);</div>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px">
<span class="gmail-Apple-converted-space"> </span><br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg<span class="gmail-Apple-converted-space">            </span>= [];</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.resolution = 1;</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.dim<span class="gmail-Apple-converted-space">        </span>= [256 256 256];</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mri_spm_rs <span class="gmail-Apple-converted-space">    </span>= ft_volumereslice(cfg, mri);</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
transform_vox2spm = mri_spm_rs.transform;</div>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px">
<span class="gmail-Apple-converted-space"> </span><br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg<span class="gmail-Apple-converted-space">          </span>= [];</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.method <span class="gmail-Apple-converted-space">  </span>= <span class="gmail-s1" style="color:rgb(178,69,243)">
'interactive'</span>;</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.coordsys = <span class="gmail-s1" style="color:rgb(178,69,243)">'ctf'</span>;</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mri_ctf_rs <span class="gmail-Apple-converted-space">  </span>= ft_volumerealign(cfg, mri_spm_rs);</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
transform_vox2ctf = mri_ctf_rs.transform;</div>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier;min-height:12px">
<span class="gmail-Apple-converted-space"> </span><br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
T = transform_vox2ctf/transform_vox2spm;</div>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Courier">
</p>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
sourcespace = ft_read_headshape({my_surface}</div>
</div>
<div class="">
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
sourcespace = ft_transform_geometry(T, sourcespace);</div>
</div>
<div class=""><br class="">
</div>
<div class="">However, although the surface and headmodel is quite aligned, the surface is a bit lower and posterior than the headmodel, as can be seen in this screenshot: <a href="https://ibb.co/eEVV2K" class="">https://ibb.co/eEVV2K</a></div>
<div class=""><br class="">
</div>
<div class="">We also tried the transformation matrices from freesurfer outputed with the command mri_info surface.surf</div>
<div class="">
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">voxel to ras transform:</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">              
</span>-1.0000 <span class="gmail-Apple-converted-space">  </span>0.0000<span class="gmail-Apple-converted-space"> 
</span>-0.0000 <span class="gmail-Apple-converted-space">  </span>131.6938</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">               
</span>0.0000 <span class="gmail-Apple-converted-space">  </span>0.0000 <span class="gmail-Apple-converted-space">
  </span>1.0000<span class="gmail-Apple-converted-space">  </span>-111.6126</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">              
</span>-0.0000<span class="gmail-Apple-converted-space">  </span>-1.0000<span class="gmail-Apple-converted-space"> 
</span>-0.0000 <span class="gmail-Apple-converted-space">  </span>157.1196</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">               
</span>0.0000 <span class="gmail-Apple-converted-space">  </span>0.0000 <span class="gmail-Apple-converted-space">
  </span>0.0000 <span class="gmail-Apple-converted-space">    </span>1.0000</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br class="">
</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">voxel-to-ras determinant -1</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br class="">
</div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">ras to voxel transform:</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">              
</span>-1.0000<span class="gmail-Apple-converted-space">  </span>-0.0000<span class="gmail-Apple-converted-space"> 
</span>-0.0000 <span class="gmail-Apple-converted-space">  </span>131.6938</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">               
</span>0.0000<span class="gmail-Apple-converted-space">  </span>-0.0000<span class="gmail-Apple-converted-space"> 
</span>-1.0000 <span class="gmail-Apple-converted-space">  </span>157.1196</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">               
</span>0.0000 <span class="gmail-Apple-converted-space">  </span>1.0000 <span class="gmail-Apple-converted-space">
  </span>0.0000 <span class="gmail-Apple-converted-space">  </span>111.6126</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">              
</span>-0.0000<span class="gmail-Apple-converted-space">  </span>-0.0000<span class="gmail-Apple-converted-space"> 
</span>-0.0000 <span class="gmail-Apple-converted-space">    </span>1.0000</span></div>
<div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<br class="">
</div>
</div>
<div class="">But the results are worse. I am a bit desperate in finding a way to align the surface without having to rerun freesurface on all the subjects. </div>
<div class=""><br class="">
</div>
<div class="">Is there a method to properly align the freesurfer surface to the aligned headmodel?</div>
<div class=""><br class="">
</div>
<div class="">Thank you</div>
<div class="">Dorothy</div>
</div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
https://doi.org/10.1371/journal.pcbi.1002202<br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
<br class="">
<br class="">
</body>
</html>