[FieldTrip] polhemus-mri coregistration for OPM

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Thu Jul 9 08:08:02 CEST 2026


Hi Kirandeep,

There’s no figure attached, so it’s difficult for me to comment to the point.

My first thought is that the ‘headshape’ is in a coordinate system that is not aligned with what you think it should be.

Can you do

ft_plot_headshape(headshape);

followed by

ft_plot_axes(headshape).

This should give you an image that shows the origin of the 3D-axes in the middle of the point cloud, with the x-axis pointing to the right, y-axis to the front, z-axis to the top. At least, this is what I would expect if you say that the coordinate system is in ’neuromag’ coordinates.

If this is not the case, it would explain the misalignment in the interactive figure when calling ft_volumerealign


Best wishes,
Jan-Mathijs


On 8 Jul 2026, at 18:02, Kirandeep Kaur via fieldtrip <fieldtrip at science.ru.nl> wrote:

Dear all, I am working with Mag4Health OPM data, We are using the polhemus system to create the headshape (which is separately co-registered with opm sensors).

Therefore, we are creating a 'headshape' structure from scratch, and trying to co-register this 'headshape' with mri (.nii format). However, when I try to do this, the polhemus cloud is ~400mm away from the mri surface, and is oriented at 90 degrees to the MRI (in the plottted figure-mri is facing MATLAB's x -axis, polhemus cloud is facing y-axis).
We have already taken steps to ensure that coordinate system/orientation is in 'neuromag' system for both polhemus and mri (+x= right, +y= anterior, +z=superior). So I am quite confused about what is going on.

Shared my code here below:
----------------------------------------------------------------------------------------
% The headshape struct in fieldtrip consiststs of the following fields:
%         pos: [N×3 double]  #in cm to begin with
%         fid: [1×1 struct] # to be left empty for now
%       label: {N×1 cell}
%    coordsys: 'neuromag'
%        unit: 'cm' % converted to mm before coregistration

% From the dopm_calib_coreg.m, we are importing the following fields in
% headshape_H2.mat file: pos [NX3], coordsys, unit.

%% Create the headsape struct
headshape = headshape_H2;

% add dummy labels to the polhemus points
headshape.label = cell(size(headshape.pos, 1),1);
for i = 1:size(headshape.pos, 1)
    headshape.label{i}= sprintf('extra_%d', i);
end

% check once
ft_plot_headshape(headshape)

%% re-align the volume
% re-align the volume to neuromag coordinates as a first step
%mark the n,l,r points, then press q to escape
close all force
cfg=[];
cfg.method='interactive';
cfg.coordsys='neuromag';
mri_neuromag=ft_volumerealign(cfg,mri_orig);

% re-align using the headshape
headshape=ft_convert_units(headshape, 'mm');
cfg=[];
cfg.method='headshape';
cfg.headshape.headshape=headshape;
cfg.headshape.icp='yes';
cfg.headshape.interactive='yes';
cfg.coordsys= 'neuromag';
mri_realigned=ft_volumerealign(cfg, mri_neuromag);
close all force

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20260709/6b425125/attachment.htm>


More information about the fieldtrip mailing list