📄 emse_open_reg.html
字号:
0068 <span class="comment">% can be used as described above</span>0069 <span class="comment">% - added reading of most other fields</span>0070 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0071 0072 0073 <span class="keyword">if</span> ~exist(<span class="string">'file'</span>,<span class="string">'var'</span>),0074 fprintf(<span class="string">'No input file - see help open_emse_reg\n'</span>);0075 <span class="keyword">return</span>;0076 <span class="keyword">end</span>0077 0078 [path,name,ext] = fileparts(file);0079 file = fullfile(path,[name ext]);0080 0081 [fid,msg] = fopen(file,<span class="string">'r'</span>);0082 <span class="keyword">if</span> ~isempty(msg), error(msg); <span class="keyword">end</span>0083 0084 fprintf(<span class="string">'OPEN_EMSE_REG: Reading registration data...'</span>);0085 tic0086 fid = fopen(file,<span class="string">'r'</span>,<span class="string">'ieee-le'</span>);0087 reg = <a href="#_sub1" class="code" title="subfunction [reg] = read_reg(fid)">read_reg</a>(fid);0088 fclose(fid);0089 t = toc;0090 fprintf(<span class="string">'done (%6.2f sec).\n'</span>,t);0091 0092 <span class="keyword">return</span>0093 0094 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0095 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0096 <a name="_sub1" href="#_subfunctions" class="code">function [reg] = read_reg(fid)</a>0097 0098 <span class="keyword">while</span> 1,0099 text = fgetl(fid);0100 <span class="keyword">if</span> ~ischar(text), <span class="keyword">break</span>, <span class="keyword">end</span>0101 0102 <span class="keyword">if</span> strmatch(<span class="string">'Offset'</span>,text),0103 <span class="comment">% Offset is the translation in meters along the x, y and z axes</span>0104 <span class="comment">% respectively, from the MRI image frame to head/elec frame.</span>0105 text = strrep(text,sscanf(text,<span class="string">'%c'</span>,8),<span class="string">''</span>);0106 text = strrep(text,<span class="string">']'</span>,<span class="string">''</span>);0107 text = strrep(text,<span class="string">','</span>,<span class="string">''</span>);0108 reg.translation = sscanf(text,<span class="string">'%f'</span>)';0109 <span class="keyword">end</span>0110 <span class="keyword">if</span> strmatch(<span class="string">'Rotation'</span>,text),0111 <span class="comment">% The Rotation vector contains the angles (in radians) about</span>0112 <span class="comment">% the x, y and z axes, also from the MRI image frame to the</span>0113 <span class="comment">% head/elec frame.</span>0114 text = strrep(text,sscanf(text,<span class="string">'%c'</span>,10),<span class="string">''</span>);0115 text = strrep(text,<span class="string">']'</span>,<span class="string">''</span>);0116 text = strrep(text,<span class="string">','</span>,<span class="string">''</span>);0117 reg.rotation = sscanf(text,<span class="string">'%f'</span>)';0118 <span class="keyword">end</span>0119 <span class="keyword">if</span> strmatch(<span class="string">'HeadToImageMatrix'</span>,text),0120 reg.elec2mri = zeros(4,4);0121 <span class="keyword">for</span> i=1:4,0122 text = fgetl(fid);0123 reg.elec2mri(i,:) = sscanf(text,<span class="string">'%f'</span>)';0124 <span class="keyword">end</span>0125 <span class="comment">% The emse matrix requires transposition</span>0126 reg.elec2mri = reg.elec2mri';0127 <span class="comment">% It is more accurate to do this:</span>0128 reg.mri2elec = inv(reg.elec2mri);0129 <span class="keyword">end</span>0130 <span class="comment">% See inverse calculation above to get reg.mri2elec</span>0131 <span class="comment">%if strmatch('ImageToHeadMatrix',text),</span>0132 <span class="comment">% reg.mri2elec = zeros(4,4);</span>0133 <span class="comment">% for i=1:4,</span>0134 <span class="comment">% text = fgetl(fid);</span>0135 <span class="comment">% reg.mri2elec(i,:) = sscanf(text,'%f')';</span>0136 <span class="comment">% end</span>0137 <span class="comment">% % The emse matrix requires transposition</span>0138 <span class="comment">% reg.mri2elec = reg.mri2elec';</span>0139 <span class="comment">%end</span>0140 0141 <span class="comment">% The coordinates of the three fiducials are given in both frames.</span>0142 <span class="comment">% For example, Head lists the fiducial coordinates (taken from the</span>0143 <span class="comment">% electrode data) in the head frame, while Head' are the fiducial</span>0144 <span class="comment">% coordinates from the image data expressed in the head frame.</span>0145 <span class="comment">% Similarly, Image lists the fiducial coordinates from the image</span>0146 <span class="comment">% data in the image frame while Image' lists those from the electrode</span>0147 <span class="comment">% data in the image frame. The two sets of numbers should be close but</span>0148 <span class="comment">% not identical.</span>0149 0150 <span class="keyword">if</span> strmatch(<span class="string">'RPA'</span>,text,<span class="string">'exact'</span>),0151 format = <span class="string">'%7c %f %f %f'</span>;0152 <span class="comment">% Read the Right Preauricular coordinates</span>0153 text = fgetl(fid);0154 tmp = sscanf(text,format)';0155 reg.RPA.Hh = tmp(8:10);0156 text = fgetl(fid);0157 tmp = sscanf(text,format)';0158 reg.RPA.Mh = tmp(8:10);0159 text = fgetl(fid);0160 tmp = sscanf(text,format)';0161 reg.RPA.Mm = tmp(8:10);0162 text = fgetl(fid);0163 tmp = sscanf(text,format)';0164 reg.RPA.Hm = tmp(8:10);0165 <span class="keyword">end</span>0166 0167 <span class="keyword">if</span> strmatch(<span class="string">'LPA'</span>,text,<span class="string">'exact'</span>),0168 format = <span class="string">'%7c %f %f %f'</span>;0169 <span class="comment">% Read the Left Preauricular coordinates</span>0170 text = fgetl(fid);0171 tmp = sscanf(text,format)';0172 reg.LPA.Hh = tmp(8:10);0173 text = fgetl(fid);0174 tmp = sscanf(text,format)';0175 reg.LPA.Mh = tmp(8:10);0176 text = fgetl(fid);0177 tmp = sscanf(text,format)';0178 reg.LPA.Mm = tmp(8:10);0179 text = fgetl(fid);0180 tmp = sscanf(text,format)';0181 reg.LPA.Hm = tmp(8:10);0182 <span class="keyword">end</span>0183 0184 <span class="keyword">if</span> strmatch(<span class="string">'Nasion'</span>,text,<span class="string">'exact'</span>),0185 format = <span class="string">'%7c %f %f %f'</span>;0186 <span class="comment">% Read the Nasion coordinates</span>0187 text = fgetl(fid);0188 tmp = sscanf(text,format)';0189 reg.NAS.Hh = tmp(8:10);0190 text = fgetl(fid);0191 tmp = sscanf(text,format)';0192 reg.NAS.Mh = tmp(8:10);0193 text = fgetl(fid);0194 tmp = sscanf(text,format)';0195 reg.NAS.Mm = tmp(8:10);0196 text = fgetl(fid);0197 tmp = sscanf(text,format)';0198 reg.NAS.Hm = tmp(8:10);0199 <span class="keyword">end</span>0200 0201 <span class="comment">% The Electrode Positions block lists the coordinates (x, y, and z)</span>0202 <span class="comment">% first in the head frame and then in the image frame.</span>0203 <span class="keyword">if</span> strmatch(<span class="string">'Electrode Positions'</span>,text),0204 reg.Helec = zeros(1,3);0205 reg.Melec = zeros(1,3);0206 n = 1;0207 <span class="keyword">while</span> n < 400,0208 <span class="comment">% Read the Head space coordinates</span>0209 text = fgetl(fid);0210 <span class="keyword">if</span> isempty(text), <span class="keyword">break</span>; <span class="keyword">end</span>0211 tmp = sscanf(text,<span class="string">'%f : %f %f'</span>)';0212 reg.Helec(n,1:3) = tmp(2:4);0213 <span class="comment">% Read the MRI space coordinates</span>0214 text = fgetl(fid);0215 tmp = sscanf(text,<span class="string">'%s %f %f %f'</span>)';0216 reg.Melec(n,1:3) = tmp(2:4);0217 n = n + 1;0218 <span class="keyword">end</span>0219 <span class="keyword">end</span>0220 0221 <span class="keyword">end</span>0222 0223 <span class="comment">% Create essential fiducial marker matrices</span>0224 <span class="comment">% The order of these points in the matrices is very</span>0225 <span class="comment">% important if they are used for coregistration</span>0226 reg.fiducials.head = [ reg.NAS.Hh; reg.RPA.Hh; reg.LPA.Hh ];0227 reg.fiducials.mri = [ reg.NAS.Mm; reg.RPA.Mm; reg.LPA.Mm ];0228 0229 0230 <span class="keyword">return</span></pre></div><hr><address>Generated on Fri 21-May-2004 12:38:21 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -