How to coregister an anatomical MRI with the gradiometer or electrode positions?
In general, anatomical volumes are represented in FieldTrip as a MATLAB-structure, containing the anatomical (and if applicable also the functional) information in a 3D numeric matrix, and a [4×4] affine transformation matrix. The 4×4 homogenous transformation matrix specified how to go from voxel space to source space.
When the anatomical image is read in using ft_read_mri, a transformation is attached to the data structure. This transformation matrix is extracted from the file. If this is not possible, Fieldtrip assumes the transformation to be an identity matrix. Importantly, the assumption is that the transformation matrix and the voxel coordinate system are consistent between one another.
Typically, when doing source reconstruction, we work with real world coordinate systems that are defined relative to the participant's head. When the anatomical images are coming off the scanner, they lack such a coordinate system, so this needs to be added to the data.
Most MEG systems come with software to convert DICOM files to a MEG-system specific MRI file format. That software then also takes care of aligning the MRI with the helmet location. E.g. for CTF this is done with MRIConverter and MRIViewer. FieldTrip can read the MRI files that are generated using the MEG-system specific software, and if you use those, the alignment is taken care of outside FieldTrip. In case the alignment is not done with external software, or if you want to read the DICOM files directly, the ft_volumerealign function can be used after ft_read_mri.
EEG acquisition systems typically do not come with software to deal with anatomical MRIs, so you should read the MRI file(s) with ft_read_mri and use ft_volumerealign to specify the position of the fiducials. The same fiducials should then be specified in ft_electroderealign to ensure that both electrodes and anatomical MRI are expressed in the same head-coordinate system.
See also the FAQ on the definition of the various head and MRI coordinate systems.