Problem while using prepare_leadfield with parameterscfg.resolution and cfg.inwardshift

Robert Oostenveld r.oostenveld at FCDONDERS.RU.NL
Tue Apr 22 21:05:23 CEST 2008

Hi Ingmar

On 22 Apr 2008, at 9:52, Ingmar Schneider wrote:
> what you say is completely right and my problem is related to the
> problem described in the FAQ. As I tried to explain in the last
> mail and as you say: A reduction of the inwardshift (i.e. to a
> negative value) results in a leadfield, that covers the whole
> anatomy data. But if I simultaneously try to improve the resolution
> (i.e. to 0.5cm) the resulting field is smaller than the one with
> the default resolution-value of 1cm. I played with some
> combinations, but i never really got a suiting leadfield.

How do you mean "the field is smaller"? The cfg.resolution only
pertains to the distance between neighbouring grid locations at which
dipoles will be positioned (using the fieldtrip/private/
prepare_dipole_grid function). Then the leadfield is computed by
looping over all dipole positions that are marked as being inside the
brain. The "inside the brain" detection is influenced by

If you compare
for the two grids that you have constructed, where
  LFgrid_coarse.pos(i,:)== LFgrid_fine.pos(j,:)
then you should have exactly the same leadfield. However, the number
of dipole positions in the grid should be higher for the fine
resolution than for the coarse resolution (the effect of
cfg.resolution). If you keep the resolution constant but change
cfg.inwardshift, then you will primarily see a change in the number
of dipoles taht is marked inside. Note however that fieldtrip tries
to keep the "box" encompassing the brain compartment as small as
possible, so changing cfg.inwardshift might also affect the total
number of sources (inside+outside).

Perhaps you should do this to clarify it further

insidevol = zeros(LFgrid.dim);
insidevol(LFgrid.inside) = 1;
insidevol(LFgrid.outside) = 0;

for slice=1:LFgrid.dim(3) % probably you dont want this in a for loop
   figure; imagesc(insidevol(:,:,slice));

You can also see that LFgrid.leadfield is empty (i.e. []) for all
"outside" gridpoints (that is to save memory, since ~50% of the
points will be outside the brain).

> I am using data from a VSM MedTech CTF-MEG with 275 channels and
> here's an excerpt of the Matlab-code to further specify my
> analysis. These specifications actually deliver a leadfield, that
> covers most of the anatomy, but in a poor resolution.

The leadfield is usually computed on a relatively coarse grid
(compared to fMRI) because of the computationat time involved, but
also because the spatial resolution of MEG is not so high anyway
(assuming a whole-head beamformer source reconstruction or a
distributed source model). A resolution of 1cm is usually fine to get
a quick first idea, and I consider a resolution of 0.7cm adequate for
almost all applications. Mote that decreasing the resolution from 1
to 0.7 results in 3x so many dipoles and hence 3x longer computations.

best regards,

PS your code looks fine to me

The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also and

More information about the fieldtrip mailing list