Back to the main page.

Bug 2800 - Wrong electrode projection in ft_prepare_vol_sens

Reported 2015-01-06 13:30:00 +0100
Modified 2015-07-15 13:31:26 +0200
Product: FieldTrip
Component: forward
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P5 major
Assigned to: Jan-Mathijs Schoffelen
Depends on:
See also:

Vladimir Litvak - 2015-01-06 13:30:41 +0100

Created attachment 688 Test script I noticed that after ft_prepare_vol_sens electrode locations are wrong and some are projected to the bottom of the head. This didn't happen before on the same example. Please check ASAP as this would completely distort the results. Test data at Vladimir

Robert Oostenveld - 2015-01-07 17:03:00 +0100

*** Bug 2803 has been marked as a duplicate of this bug. ***

Jan-Mathijs Schoffelen - 2015-01-12 12:11:55 +0100

The call to project_elec on line 436 in prepare_vol_sens screws up the electrode positions (in other words the projection onto the skin fails).

Jan-Mathijs Schoffelen - 2015-01-12 12:19:13 +0100

Allow me to fix this ;-) (because it's likely my bad...)

Jan-Mathijs Schoffelen - 2015-01-12 12:59:06 +0100

I identified the culprit: ptriprojn (called on line 43 of project_elec) returns a signed distance. To get the index to the closest triangle on line 45, one should evaluate the abs(dist). I will change this...after today's FT meeting :-).

Jan-Mathijs Schoffelen - 2015-01-12 15:40:35 +0100

[jansch@mentat003 private]$ svn diff project_elec.m Index: project_elec.m =================================================================== --- project_elec.m (revision 10093) +++ project_elec.m (working copy) @@ -42,7 +42,7 @@ for i=1:Nelc [proj,dist] = ptriprojn(pnt(tri(:,1),:), pnt(tri(:,2),:), pnt(tri(:,3),:), elc(i,:), 1); - [mindist, minindx] = min(dist); + [mindist, minindx] = min(abs(dist)); [la, mu] = lmoutr(pnt(tri(minindx,1),:), pnt(tri(minindx,2),:), pnt(tri(minindx,3),:), proj(minindx,:)); smallest_dist = dist(minindx); smallest_tri = minindx; [jansch@mentat003 private]$ svn commit -m "bugfix - identify closest point using the abs of the distance" project_elec.m ../test/test_bug2800.m Sending private/project_elec.m Adding test/test_bug2800.m Transmitting file data .. Committed revision 10094. I traced the change back to an update of lmoutrn on Dec 15, 2014 r10043. @natalia: probably your results are not affected, unless you have re-computed them over the Christmas holidays :-) TODO: write an e-mail to the discussion list

Vladimir Litvak - 2015-01-12 15:44:01 +0100

Good that the bug was only there for a short time mostly overlapping with holidays. That was exactly the window for it to make it into our Aston workshop version but luckily we only showed MEG examples there ;-) Thanks for the excellent detective work! Vladimir

Luis - 2015-01-12 15:50:30 +0100

Wouldn't be better to change the output of ptriprojn inside the function. After all distances should always be positive, right?

Jan-Mathijs Schoffelen - 2015-01-12 15:56:36 +0100

@Luis, the signed distance is intentional, because it gives information (or is intended to do so :-) ) with respect to whether the point is closer to (or further away from) the origin, with respect to its projection on the triangulated surface.

Jan-Mathijs Schoffelen - 2015-01-12 15:57:05 +0100

Message sent to e-mail discussion list, changing status to resolved

Luis - 2015-01-12 16:05:57 +0100

(In reply to Jan-Mathijs Schoffelen from comment #8) Sorry I did not see your message when I added my last comment. Thank you for fixing this!