# Localizing electrodes using a 3D-scanner

This tutorial demonstrates how to construct an electrode model based on a single subject's 3D-scan. This electrode model can be used for creating a BEM or FEM volume conduction model.

This tutorial does not cover how to create a 2-D channel layout for plotting, nor how to do the source estimation itself.

### Background

The quality of EEG source estimates depends on accurate volume conduction models and sensor positions. The volume conduction model comprises a description of the geometry, of the conductivities and of a computational approach for solving Poisson’s equations.

The current golden standard is to measure the head geometry with an MRI and sensor positions with a Polhemus. Measuring the sensor positions with the Polhemus on specific groups can be challenging or even impossible.

In this tutorial we want to focus on creating a electrode based on 3D surface scan of a human head. The 3D-scan device we are using in this tutorial is a http://structure.io device. However, other devices are also feasible as long as the 3D-scan output is written in a FieldTrip supported data format.

This youtube video shows the procedure, which is explained in this tutorial:

In this section we describe the procedure to acquire electrode positions with a 3D-Scanner

### Recording data

For recording with the structure.io we use Scanner - Structure Sensor Sample. This software allows use to capture our subjects head surface by just walking around the subject. Here you can download the example we used in this tutorial.

Before starting with FieldTrip, it is important that you set up your MATLAB path properly.

```cd PATH_TO_FIELDTRIP
ft_defaults```

Then you can load the data (this might take a moment)

```head_surface = ft_read_headshape('Model/Model.obj')
pos: [553494x3 double]
tri: [800000x3 double]
unit: 'm'
color: [553494x3 uint8]```

We convert the units to mm.

`head_surface = ft_convert_units(head_surface,'mm');`

We visualise the mesh surface

`ft_plot_mesh(head_surface)`

Figure 1: Mesh recorded with 3D-scanner

In the next step we will transform our mesh into the ctf-coordinates. For this we have to specify the nasion (NAS), left preauricular (LPA) and right preauricular (RPA) points.

```cfg = [];

With having specified the fiducials we are now able to coregister our head surface to the ctf-coordinates. To easier identify the locations of the fiducials you can also mark the locations on your subject with a coloured pen. Location of the fiducials

```cfg = [];
cfg.method = 'fiducial';
cfg. coordsys = 'ctf';
cfg.fiducial.nas    = fiducials.elecpos(1,:); %position of NAS
cfg.fiducial.lpa    = fiducials.elecpos(2,:); %position of LPA
cfg.fiducial.rpa    = fiducials.elecpos(3,:); %position of RPA

Again we visualise the head surface, but we also plot the axes along with it.

```ft_plot_axes(head_surface)

### Identify electrode locations

The previous made sure that our head model is now in the right coordinate system. This allows us now to identify the electrode locations. With our scanner the texture mapping quality is not fitting the actual structural data, so for identifying the electrode locations we remove the texture mapping.

To localise the electrode we use the crates that are visible on the surface.

```cfg = [];

Identifying electrode locations

### Assign electrode labels

Now we need to assign the correct labels. We used the M10 arrangement.

As ft_electrodeplacement uses the the labelling scheme '1','2',… and so on we need to assign the correct labels the reference, ground and the anatomical landmarks NAS,LPA and RPA.

```elec.label(61:65) = { ...
'GND'
'REF'
'NAS'
'LPA'
'RPA'
};```

### Visualize the electrodes in 3D

A final visualisation showing the electrodes on the color surface mesh of the subject.

```ft_plot_mesh(head_surface)
ft_plot_sens(elec)```

### Moving electrodes inward

The electrode location are now digitised on the outer surface of the cap. In the figures you can see the plastic ring in which you plug in the electrodes. This means we digitised the surface of the ring and not the contact between electrode and skin surface. We can correct for this mismatch by moving the electrode inward according to their normals.

```cfg = [];
cfg.method = 'moveinward'; %'moveinward' moves electrodes inward along their normals
cfg.moveinward = 12;     %cfg.moveinward     = number, the distance that the electrode should be moved
%inward (negative numbers result in an outward move)
cfg.elec = 'elec';
elec = ft_electroderealign(cfg);```

In this tutorial we learned how to process a head surface created by a 3D-Scan. Furthermore we learned how to identify electrode locations to create a electrode model which can be used for volume conduction modelling.