EMSE_MRI2ELEC - Convert mri coordinates to points in head frame [Velec] = emse_mri2elec(vert,reg) vert - the Nx3 (X,Y,Z) MRI coordinates 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 MRI frame (eg, an fMRI activation overlayed onto a high res T1 volume) this function will find the corresponding location in the head space of the electrodes. Symbolically we have P(voxel) and want to find P(head). 1. Use the offset between the MRI coordinate frame and the MRI volume coordinate frame to find P(MRI-voxel). 2. Given P(MRI-voxel) and the voxel size, we can find P(MRI-mm), which is the MRI coordinates expressed in mm 3. The registration file contains the matrix ImageToHeadMatrix, so P(head) = P(MRI-mm)*reg.mri2elec, where P(MRI-mm) is the point in MRI coordinates. This function performs the last calculation. See also: EMSE_OPEN_REG, EMSE_ELEC2MRI
0001 function [V] = emse_mri2elec(vert,reg) 0002 0003 % EMSE_MRI2ELEC - Convert mri coordinates to points in head frame 0004 % 0005 % [Velec] = emse_mri2elec(vert,reg) 0006 % 0007 % vert - the Nx3 (X,Y,Z) MRI coordinates 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 MRI frame (eg, an fMRI activation 0012 % overlayed onto a high res T1 volume) this function will find 0013 % the corresponding location in the head space of the electrodes. 0014 % Symbolically we have P(voxel) and want to find P(head). 0015 % 0016 % 1. Use the offset between the MRI coordinate frame and 0017 % the MRI volume coordinate frame to find P(MRI-voxel). 0018 % 2. Given P(MRI-voxel) and the voxel size, we can find 0019 % P(MRI-mm), which is the MRI coordinates expressed in mm 0020 % 3. The registration file contains the matrix ImageToHeadMatrix, 0021 % so P(head) = P(MRI-mm)*reg.mri2elec, where P(MRI-mm) is the 0022 % point in MRI coordinates. 0023 % 0024 % This function performs the last calculation. 0025 % 0026 % See also: EMSE_OPEN_REG, EMSE_ELEC2MRI 0027 % 0028 0029 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:34 $ 0030 0031 % Licence: GNU GPL, no express or implied warranties 0032 % History: 06/2002, Darren.Weber@flinders.edu.au 0033 % EMSE details thanks to: 0034 % Demetrios Voreades, Ph.D. 0035 % Applications Engineer, Source Signal Imaging 0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0037 0038 fprintf('EMSE_MRI2ELEC: In development. Be careful!\n'); 0039 0040 % elec input is Nx3 matrix that should be represented 0041 % in homogenous coordinates: 0042 vert = [ vert ones(size(vert,1),1) ]; 0043 0044 Velec = vert * reg.mri2elec; 0045 0046 % Note reg.Melec ~= Velec(:,1:3) due to floating point rounding only. 0047 0048 % reg.mri2elec 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, 0057 % the last column is projections (usually 0), 0058 % and the value at 4,4 is the homogenous 0059 % coordinate scale unit, usually 1. 0060 0061 % In homogeneous coordinates, the last column 0062 % is the scale factor, usually 1, but in case 0063 % it is ~= 1 0064 V(:,1) = Velec(:,1) ./ Velec(:,4); 0065 V(:,2) = Velec(:,2) ./ Velec(:,4); 0066 V(:,3) = Velec(:,3) ./ Velec(:,4); 0067 0068 return