Transform Marker coordinate to MRI coordinate Usage: trans_mat = trans_head(marker, mri) --- Input Reference points in Marker cordinate marker(1,:): Left ear marker(2,:): Nose marker(3,:): Right ear Reference points in MRI cordinate mri(1,:): Left ear in MRI mri(2,:): Nose in MRI mri(3,:): Right ear in MRI --- Output trans_mat = Rigid Body Transformation matrix (4 x 3) from Marker coordinate to MRI coordinate x_mri = [x_marker 1]*trans_mat Transform Marker coordinate to MRI coordinate by Rigid Body Transformation (Rotation + Translation) Three point matching (usualy Left/Right ear & Nose are used) Coordinate Transform by trans_mat x_mri = ( x_marker - org_marker )*rot + org_mri = x_marker*rot + (org_mri - org_marker*rot) trans_mat = [rot ; trans_org] (4 x 3) trans_org = org_mri - org_marker*rot 2005-06-07 made by M. Sato Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [trans_mat, marker_mri] = vb_fit_3d_coord(marker, mri) 0002 % Transform Marker coordinate to MRI coordinate 0003 % 0004 % Usage: 0005 % trans_mat = trans_head(marker, mri) 0006 % 0007 % --- Input 0008 % Reference points in Marker cordinate 0009 % 0010 % marker(1,:): Left ear 0011 % marker(2,:): Nose 0012 % marker(3,:): Right ear 0013 % 0014 % Reference points in MRI cordinate 0015 % mri(1,:): Left ear in MRI 0016 % mri(2,:): Nose in MRI 0017 % mri(3,:): Right ear in MRI 0018 % 0019 % --- Output 0020 % trans_mat = Rigid Body Transformation matrix (4 x 3) 0021 % from Marker coordinate to MRI coordinate 0022 % x_mri = [x_marker 1]*trans_mat 0023 % 0024 % Transform Marker coordinate to MRI coordinate 0025 % by Rigid Body Transformation (Rotation + Translation) 0026 % Three point matching (usualy Left/Right ear & Nose are used) 0027 % 0028 % Coordinate Transform by trans_mat 0029 % x_mri = ( x_marker - org_marker )*rot + org_mri 0030 % = x_marker*rot + (org_mri - org_marker*rot) 0031 % 0032 % trans_mat = [rot ; trans_org] (4 x 3) 0033 % trans_org = org_mri - org_marker*rot 0034 % 0035 % 2005-06-07 made by M. Sato 0036 % 0037 % Copyright (C) 2011, ATR All Rights Reserved. 0038 % License : New BSD License(see VBMEG_LICENSE.txt) 0039 0040 % 0041 % XYZ-Axis of MRI cord. 0042 % 0043 0044 % X-axis: mri(1) -> mri(3) : Left->Right ear line 0045 ex = mri(3,:)-mri(1,:); 0046 exx = sqrt(sum(ex.^2)); 0047 ex = ex/exx; 0048 % Z-axis: perpendicular to X & Y-axis 0049 ez = cross(ex,mri(2,:)-mri(1,:)); 0050 ezz = sqrt(sum(ez.^2)); 0051 ez = ez/ezz; 0052 % Y-axis: X axis -> mri(2) :perpendicular to X-axis & path through Nose 0053 ey = cross(ez,ex); 0054 0055 % Unit vectors of XYZ-axis 0056 rot_mri = [ex; ey; ez]; 0057 0058 % Origin 0059 org_mri = sum((mri(2,:)-mri(1,:)).*ex)*ex + mri(1,:); 0060 0061 % 0062 % XYZ-Axis of Marker cord. 0063 % 0064 0065 % X-axis: mri(1) -> mri(3) : Left->Right ear line 0066 ex = marker(3,:)-marker(1,:); 0067 exx = sqrt(sum(ex.^2)); 0068 ex = ex/exx; 0069 % Z-axis: perpendicular to X & Y-axis 0070 ez = cross(ex,marker(2,:)-marker(1,:)); 0071 ezz = sqrt(sum(ez.^2)); 0072 ez = ez/ezz; 0073 % Y-axis: X axis -> mri(2) :perpendicular to X-axis & path through Nose 0074 ey = cross(ez,ex); 0075 0076 % Unit vectors of XYZ-axis 0077 rot_marker = [ex; ey; ez]; 0078 0079 % Origin 0080 org_marker = sum((marker(2,:)-marker(1,:)).*ex)*ex + marker(1,:); 0081 0082 % Rotation matrix from marker cord to MRI cord 0083 rot = rot_marker'*rot_mri; 0084 0085 trans_org = org_mri - org_marker*rot; 0086 trans_mat = [rot ; trans_org]; 0087 0088 marker_mri = [marker ones(3,1)]*trans_mat;