<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Dear Jan-Mathijs,</p>
<p>thank you very much for your help and taking the time, your code
did the job for me - it looks pretty good now! My electrode set
wasn't in ctf-coordinates, so I had to do it a little bit
different but it worked out well.</p>
<p>Thanks again and have a good start into the weekend soon,</p>
<p>Annika<br>
</p>
<br>
<div class="moz-cite-prefix">On 8/23/2018 2:57 PM, Schoffelen, J.M.
(Jan Mathijs) wrote:<br>
</div>
<blockquote type="cite"
cite="mid:012859F5-86EF-4918-B242-D83ACE9CF8B6@donders.ru.nl">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Dear Annika,
<div class=""><br class="">
</div>
<div class="">It’s a bit unfortunate that you ended up using the
low-level information in the mri.hdr.fiducial field (in
combination with the transformation matrices). I agree with you
that the values are strange, and I am pretty sure that they do
not correspond with the volumetric image in the same data
structure. Note that the mri itself also has a ‘transform’
field, which provides you with the mapping between voxels and
head space (MNI-convention, ACPC-based RAS). If you aim for a
3-point (nas,lpa,rpa) based coregistration between your
electrodes and the templates needed for source reconstruction,
you could use the set of fiducial positions that can be found in
fieldtrip/electrode/standard1005.elc. (an alternative and
possibly better coregistration could be achieved using a
non-linear matching with the ‘template’ method, but that might
be a story of its own).</div>
<div class=""><br class="">
</div>
<div class="">If you do:</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">>> sens=ft_read_sens('standard_1005.elc');</div>
<div class="">>> sens.chanpos(1:3,:)</div>
<div class=""><br class="">
</div>
<div class="">ans =</div>
<div class=""><br class="">
</div>
<div class=""> -86.0761 -19.9897 -47.9860</div>
<div class=""> 85.7939 -20.0093 -48.0310</div>
<div class=""> 0.0083 86.8110 -39.9830</div>
<div class=""><br class="">
</div>
<div class="">(note that this very nicely corresponds with the
template fiducials you reported in your e-mail)</div>
<div class=""><br class="">
</div>
<div class="">>> sens.label(1:3)</div>
<div class=""><br class="">
</div>
<div class="">ans = </div>
<div class=""><br class="">
</div>
<div class=""> 'LPA'</div>
<div class=""> 'RPA'</div>
<div class=""> ‘Nz'</div>
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">you can verify that these three fiducials are
expressed in head coordinates according to the ‘spm’ convention,
i.e. Anterior Commissure is origin, the line through AC and PC
is the y-axis, x-axis pointing to the right etc). This
verification can be done with</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">>>load(‘standard_mri’);,</div>
</div>
<div class=""><br class="">
</div>
<div class="">>>cfg = [];</div>
<div class="">>>cfg.location = sens.chanpos(1,:);</div>
<div class="">>>figure;ft_sourceplot(cfg, mri);</div>
<div class=""><br class="">
</div>
<div class="">Now, if <i class="">your</i> electrodes' coordinate
system is the same as the anatomical mri’s, then you can proceed
to ft_electroderealign.</div>
<div class=""><br class="">
</div>
<div class="">Yet, your electrodes’ coordinate system is
different, because you report that you’d expect the nasion to be
[100 0 0], i.e. the x-axis to go exactly through the nasion, and
the positive y-axis pointing to the left. This is then an
ALS-based coordinate system with the origin somewhere between
the ears (the exact definition depends on whether you are using
the convention that e.g. CTF uses, as compared to the ASA
coordinate system: see ‘help ft_headcoordinates’ and the
fieldtrip wiki’s faq about coordinate systems). </div>
<div class=""><br class="">
</div>
<div class="">Now, if you need to get your electrodes expressed in
the coordinate system that is the same as the one in which the
headmodel is specified (called ‘spm’, or ‘acpc’), then you can
do the following:</div>
<div class=""><br class="">
</div>
<div class="">T =
ft_headcoordinates(sens.chanpos(3,:),sens.chanpos(1,:),sens.chanpos(2,:),’ctf’);
% or ‘asa'</div>
<div class=""><br class="">
</div>
<div class="">This gives you a transformation matrix that maps
from the space in which the ‘fiducials’ are expressed (in this
case: spm) to a ctf/asa-based coordinate system. This you can
verify with </div>
<div class=""><br class="">
</div>
<div class="">ft_warp_apply(T, sens.chanpos(1:3,:));,</div>
<div class=""><br class="">
</div>
<div class="">which will give you the fiducials’ coordinates with
values close to 0, on 2 out of three values. Then, the inv(T) is
transforming from the ctf/asa-based coordinate system into spm’s
convention, so you can do:</div>
<div class=""><br class="">
</div>
<div class="">chanlocs_124_transformed =
ft_transform_geometry(inv(T), chanlocs_124);</div>
<div class=""><br class="">
</div>
<div class="">I think that this already should get you close to
where you want to end up.</div>
<div class=""><br class="">
</div>
<div class="">And yes, coordinate systems are always complicated.</div>
<div class=""><br class="">
</div>
<div class="">Good luck,</div>
<div class=""><br class="">
</div>
<div class="">Jan-Mathijs</div>
<div class=""><br class="">
</div>
<div class="">PS: I have removed the hdr-fields from standard_mri
and standard_seg in the release version of the code, to avoid
any future confusion.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 23 Aug 2018, at 11:06, Annika Thierfelder
<<a href="mailto:athierfelder@tuebingen.mpg.de"
class="" moz-do-not-send="true">athierfelder@tuebingen.mpg.de</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">Hello everyone,<br class="">
<br class="">
short update on my question, that is maybe easier to
answer without going through the code itself.<br
class="">
<br class="">
I believe that the heart of the problem lies (of course)
in the coordinate definitions of the electrodes and the
MRI. So, I experimented a little with the example
electrode set that is aligned to the standard BEM model
that results from the standard MRI. If I try to align
the example electrodes to the MRI (which is not
necessary but it also should not hurt), I discovered
that I get the same shift into the z-direction for the
example electrodes.<br class="">
<br class="">
So, the basic question underlying my problem would be:
How can the MRI and the eletrodes be aligned if their
fiducials are so different, they even seem to be in
different coordinate systems? Shouldn't they be kind of
similar if they are aligned? I did not see any further
coordinate transformation in the BEM computation from
the MRI (except for the conversion into 'acpc' in
ft_volumesegment which doesn't change anything) that
would explain the alignment later on.<br class="">
<br class="">
MRI fiducials:<br class="">
NAS [1, 0, 0]<br class="">
LPA [0, 83, 0]<br class="">
RPA [0, -117, 0]<br class="">
<br class="">
template electrode fiducials are roughly:<br class="">
NAS [0, 87, -40]<br class="">
LPA [-86, -20, -48]<br class="">
RPA [86, -20, -48]<br class="">
<br class="">
Also, the MRI is supposed to be in MNI coordinates,
which I don't understand why, because already the first
dimension doesn't point to the right. I feel like
understanding why the coordinates are this way would be
a crucial step to solve my problem.<br class="">
<br class="">
I'm very thankful for any help on this problem. If I
understand this, I hopefully can figure out the rest
myself.<br class="">
<br class="">
Best regards,<br class="">
Annika<br class="">
<br class="">
On 8/21/2018 6:21 PM, Annika Thierfelder wrote:<br
class="">
<blockquote type="cite" class="">Hello everyone,<br
class="">
<br class="">
I started using fieldtrip last week to do EEG source
analysis and I experienced some issues when trying to
align the EEG to the MRI. Since we don't have MRI
scans for our subjects, I used the standard_mri from
the template folder.<br class="">
<br class="">
The solution that works "best" until now is to align
the electrodes with the MRI fiducials and compute the
BEM from the MRI seperately (I used bemcp for that
since I work on windows, so dipoli doesn't run).
However, when I plot the aligned electrodes together
with the BEM head surface, the electrodes are in the
correct orientation but they have an offset along the
z-axis. I put the code I used below and uploaded the
picture of the electrodes and the head model on google
drive:
<a
href="https://drive.google.com/open?id=1b7Q3YGWGyzaa5oXeE-PfOOHNIDoFaLO1"
class="" moz-do-not-send="true">
https://drive.google.com/open?id=1b7Q3YGWGyzaa5oXeE-PfOOHNIDoFaLO1</a><br
class="">
<br class="">
There are two things I'm wondering about now:<br
class="">
<br class="">
Why are the nasion head coordinates in the MRI
template [1, 0, 0] and not [100, 0, 0], which would
make more sense (at least in my opinion) since the
units are in mm and I thought the nasion is not
supposed to be inside the head? The LPA and RPA values
are [0, 83, 0] and [0, -117, 0] respectively, which
seems perfectly fine to me.<br class="">
<br class="">
I have the feeling that the problem arises because the
two coordinate systems of the data do not have the
same origin. Can I shift the coordinate system of the
electrode space before aligning them? I only found
ways how to change the coordinate system of the MRI. I
also tried to change the MRI coordinate system first
before aligning the electrodes, but I found that I
cannot create the BEM model with 'bemcp' anymore. It
seems to throw an error if I give it an MRI with any
coordinate system that is not 'spm'. So I kind of have
the feeling that I need to get the electrodes into the
'spm' coordinates to match the MRI and BEM head.<br
class="">
<br class="">
Thank you a lot in advance for your support!<br
class="">
<br class="">
Annika<br class="">
<br class="">
PS: I know there has been a similar problem once in
this mailing list, but I checked the suggestions and
they did not work for me, also it seemed as if in the
end it came down to fitting the electrodes manually
there, and I suppose there can be another solution for
this.<br class="">
<br class="">
==================================================================================
<br class="">
<br class="">
Code for the electrode alignment:<br class="">
<br class="">
%This is my how my electrode data looks like:<br
class="">
disp(chanlocs_124)<br class="">
label: {124×1 cell}<br class="">
elecpos: [124×3 double]<br class="">
unit: 'mm'<br class="">
<br class="">
% get fiducials from the MRI template<br class="">
vox_Nas = mri_spm.hdr.fiducial.mri.nas;<br class="">
vox_Lpa = mri_spm.hdr.fiducial.mri.lpa;<br class="">
vox_Rpa = mri_spm.hdr.fiducial.mri.rpa;<br class="">
<br class="">
% I know I can skip this step because I can directly
use the head-coordinates given in the MRI template<br
class="">
% I kept it because it doesn't make a difference<br
class="">
vox2head = mri_spm.hdr.transformMRI2Head;<br class="">
head_Nas = ft_warp_apply(vox2head, vox_Nas,
'homogeneous'); % nasion<br class="">
head_Lpa = ft_warp_apply(vox2head, vox_Lpa,
'homogeneous'); % Left preauricular<br class="">
head_Rpa = ft_warp_apply(vox2head, vox_Rpa,
'homogeneous'); % Right preauricular<br class="">
<br class="">
% save the MRI fiducials as target structure for the
realignment<br class="">
% in our data set, the LPA is named TTP9 and the RPA
is TTP10, so I renamed them<br class="">
elec_mri.elecpos(1,:) = head_Nas;<br class="">
elec_mri.elecpos(2,:) = head_Lpa;<br class="">
elec_mri.elecpos(3,:) = head_Rpa;<br class="">
elec_mri.label = {'Nz', 'TTP9', 'TTP10'};<br class="">
elec_mri.unit = 'mm';<br class="">
<br class="">
% coregister the electrodes to the MRI using fiducials<br
class="">
cfg = [];<br class="">
cfg.method = 'fiducial';<br class="">
cfg.target = elec_mri;<br class="">
cfg.elec = chanlocs_124;<br class="">
cfg.fiducial = {'Nz', 'TTP9', 'TTP10'};<br class="">
chanlocs_124_spm = ft_electroderealign(cfg);<br
class="">
<br class="">
===================================================================================================
<br class="">
Just in case this is also of interest, this is how I
compute the BEM headmodel from the same MRI template:<br
class="">
<br class="">
% segments the MRI into three different tissue parts<br
class="">
% creates binary masks for each point and tissue part<br
class="">
cfg = [];<br class="">
cfg.output = {'brain','skull','scalp'};<br class="">
segmented_mri = ft_volumesegment(cfg, mri_spm);<br
class="">
<br class="">
%% create mesh with different tissues<br class="">
cfg=[];<br class="">
cfg.tissue={'brain','skull','scalp'};<br class="">
cfg.numvertices = [3000 2000 1000];<br class="">
bnd=ft_prepare_mesh(cfg,segmented_mri);<br class="">
<br class="">
% compute headmodel<br class="">
cfg = [];<br class="">
cfg.tissue={'brain','skull','scalp'};<br class="">
cfg.method ='bemcp';<br class="">
vol = ft_prepare_headmodel(cfg, bnd);<br
class="">
<br class="">
_______________________________________________<br
class="">
fieldtrip mailing list<br class="">
<a
href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip"
class="" moz-do-not-send="true">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br
class="">
<a class="moz-txt-link-freetext" href="https://doi.org/10.1371/journal.pcbi.1002202">https://doi.org/10.1371/journal.pcbi.1002202</a><br
class="">
</blockquote>
<br class="">
_______________________________________________<br
class="">
fieldtrip mailing list<br class="">
<a
href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip"
class="" moz-do-not-send="true">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br
class="">
<a class="moz-txt-link-freetext" href="https://doi.org/10.1371/journal.pcbi.1002202">https://doi.org/10.1371/journal.pcbi.1002202</a><br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
fieldtrip mailing list
<a class="moz-txt-link-freetext" href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a>
<a class="moz-txt-link-freetext" href="https://doi.org/10.1371/journal.pcbi.1002202">https://doi.org/10.1371/journal.pcbi.1002202</a>
</pre>
</blockquote>
<br>
</body>
</html>