EMSE_ELEC2MRI - Convert point in head frame to mri coordinates [vert] = emse_elec2mri(elec,reg) elec - the Nx3 (X,Y,Z) points in a head frame to be converted reg - a structure containing coordinate transform matrices, which is read using emse_open_reg Given a point P(x,y,z) in head frame (eg, an activation point on a cortical mesh) this function will find the corresponding voxel in a vmi file. Symbolically we have P(head) and want to find P(voxel). 1. The registration file contains the matrix HeadToImage, so P(MRI-mm) = P(head)*HeadToImage, where P(MRI-mm) is the point in MRI coordinates. 2. From the voxel size, you can find P(MRI-voxel), which is the MRI coordinates expressed in voxels 3. Use the offset between the MRI coordinate frame and the Image coordinate frame to find P(voxel).
0001 function [V] = emse_elec2mri(elec,reg) 0002 0003 % EMSE_ELEC2MRI - Convert point in head frame to mri coordinates 0004 % 0005 % [vert] = emse_elec2mri(elec,reg) 0006 % 0007 % elec - the Nx3 (X,Y,Z) points in a head frame to be converted 0008 % reg - a structure containing coordinate transform matrices, 0009 % which is read using emse_open_reg 0010 % 0011 % Given a point P(x,y,z) in head frame (eg, an activation point on a 0012 % cortical mesh) this function will find the corresponding voxel in a 0013 % vmi file. Symbolically we have P(head) and want to find P(voxel). 0014 % 0015 % 1. The registration file contains the matrix HeadToImage, 0016 % so P(MRI-mm) = P(head)*HeadToImage, where P(MRI-mm) is the 0017 % point in MRI coordinates. 0018 % 2. From the voxel size, you can find P(MRI-voxel), which 0019 % is the MRI coordinates expressed in voxels 0020 % 3. Use the offset between the MRI coordinate frame and 0021 % the Image coordinate frame to find P(voxel). 0022 % 0023 0024 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:34 $ 0025 0026 % Licence: GNU GPL, no express or implied warranties 0027 % History: 06/2002, Darren.Weber@flinders.edu.au 0028 % EMSE details thanks to: 0029 % Demetrios Voreades, Ph.D. 0030 % Applications Engineer, Source Signal Imaging 0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0032 0033 fprintf('EMSE_ELEC2MRI: In development. Be careful!\n'); 0034 0035 % elec input is Nx3 matrix that should be represented 0036 % in homogenous coordinates: 0037 elec = [ elec ones(size(elec,1),1) ]; 0038 0039 % 1. The registration file contains the matrix HeadToImage, 0040 % so P(MRI) = HeadToImage*P(head), where P(MRI-mm) is the 0041 % point in MRI coordinates. 0042 0043 % However, I've translated HeadToImage, so we now right-multiply, 0044 % which is consistent with a text book account of the subject. 0045 0046 vert = elec * reg.elec2mri; 0047 0048 % reg.elec2mri is a 4x4 matrix, eg: 0049 % 0050 % -0.9525 0.0452 0.3012 0 0051 % -0.0522 -0.9985 -0.0154 0 0052 % 0.3000 -0.0304 0.9534 0 0053 % -0.1295 0.1299 0.0756 1.0000 0054 % 0055 % The first 3x3 cells are the rotations, 0056 % the last row is the translations, and 0057 % the last column is the scale, if any 0058 0059 % In homogeneous coordinates, the last column 0060 % is the scale factor, usually 1 0061 V(:,1) = vert(:,1) ./ vert(:,4); 0062 V(:,2) = vert(:,2) ./ vert(:,4); 0063 V(:,3) = vert(:,3) ./ vert(:,4); 0064 0065 return