sam_coreg is an algorithm which refines the coregistration between the MEG dataset and the MRI data using a cortical atlas derived from freesurfer. In a traditional unconstrained SAM analysis, the orientation of each source voxel would be determined by choosing the direction that maximizes the power. Intuitively, this algorithm utilizes the known orientations, derived from the FreeSurfer surface reconstruction, to determine the best fit with the MEG data.
The algorithm is based upon the relationship between the error in the LCMV beamformer moment vector error and signal power (z^2). There is a known monotonic [statistical] relationship between source resolution & z^2 has been published. The accuracy of the linear solution for the moment vector is a function of z^2.
This is a brute-force algorithm that iterates on successive translations & rotations of the MEG sensors (both primary & reference) to maximize the [inverse of the] product-moment correlation coefficent of angular error with z^2. For each vertex in the atlas, two LCMV beamformer solutions are performed - one using only the MEG data to solve the linear solution for the unconstrained moment vector and the other using the normal vector for that vertex to compute z^2. The difference between these two vectors is the "angular error". The variance of this error over the vertices) should have a monotonic relationship with z^2 if the MEG and MRI are coregistered. In this version, the negative product-moment correlation of angular error (the arc cosine of the dot product of the unconstrained & constrained moment vectors) with z^2 from the constrained solution is used. For each pass, the program selects the transform giving the maximum correlation. In order to make the algorithm complete in a reasonable amount of time, a random subset of cortical normals is sampled for each iteration. Since a different random mesh is selected for each pass, one cannot expect correlation to improve with each pass. However, the average values of translation and rotation will converge to their best values.
This program assumes that a high-quality atlas of the cortex has been segmented from an MRI of each subject being studied. The pial surface is recommended. Before running sam_coreg, the initial surface vertices are generated by FSnormals.py. It us recommended that the the 17-25 Hz frequency band is used for coregistration, because the signal to noise is maximal in that band.
Currently, this program is rather slow (on the order of 18-24 hours per subject). Future releases will (hopefully) include parallelization.
sam_coreg -r <dataset_name> -m <parameter_file> [options]
The -r flag designates the dataset name (with or without the .ds suffix), and -m designates the parameter file name.
-v Verbose mode, without this flag sam_wts works silently except for error messages -p Output angular error and Z^2 for every vertex in each pass to a .txt file -h Show help
Atlas: File containing cortical normals, generated using FSNormals.py SurfaceType: type of surface used to generate the Atlas file Model: Head model, must be Nolte MRIDirectory: Specify where to locate the necessary MRI files, including Atlas file
MRIDirectory: Specify where to locate the necessary MRI files PrefixLength: Specify characters used for identifying MRI and headmodel files.
The sam_coreg program produces a rigid body transform that can be applied to the MEG sensors to bring them into precise alignment with the MRI data. The transformation is written into the SAM subdirectory of the dataset so that subsequent beamformer solutions can read the transformation using the parameter keyword "Transform". The default name for this file is Transform.xfm. A Transform.txt file is also produced, which gives the correlation of angular error and Z^2 for each translation and rotation tried. Optionally, a Meshnn.txt file can be created which gives the angular error and Z^2 for each individual vertex for each pass which can be visualized as a scatterplot.