📄 ge_series2avw.html
字号:
0087 0088 <span class="comment">% Write the Analyze files (not doing this)</span>0089 <span class="comment">%avw_write(avw,outName);</span>0090 0091 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0092 <span class="comment">% This is the original write code, now replace with above (DLW)...</span>0093 0094 <span class="comment">%outFile = strcat(outName,'.hdr');</span>0095 <span class="comment">%status = ge_writeSPMHeader(outFile,header);</span>0096 <span class="comment">%outFile = [outName sprintf('.img')];</span>0097 <span class="comment">%[fid,message] = fopen(outFile,'w');</span>0098 <span class="comment">%if (fid == -1),</span>0099 <span class="comment">% fprintf('Cannot Open %s for writing.\n',outFile);</span>0100 <span class="comment">% error(message);</span>0101 <span class="comment">%end</span>0102 <span class="comment">%fwrite(fid,reshape(imageVol,1,prod(size(imageVol))),'int16');</span>0103 <span class="comment">%status = fclose(fid);</span>0104 0105 t=toc; fprintf(<span class="string">'...done (%5.2f sec).\n'</span>,t);0106 0107 <span class="keyword">return</span>0108 0109 0110 0111 0112 0113 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0114 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0115 0116 <a name="_sub1" href="#_subfunctions" class="code">function [avw] = ge_reorient(ge, avw)</a>0117 0118 <span class="comment">%ge_reorient - Assigns Analyze header dimensions and volume based on GE orientation</span>0119 <span class="comment">%</span>0120 <span class="comment">% avw = ge_reorient(ge, avw)</span>0121 <span class="comment">%</span>0122 <span class="comment">% reorients the GE 3D volume to be radiological</span>0123 <span class="comment">% orientation (axial LAS, which is SPM compatible)</span>0124 <span class="comment">% based on the GE acquition orientation</span>0125 <span class="comment">%</span>0126 <span class="comment">% This has been tested with Ax,Sag,Cor with slices going</span>0127 <span class="comment">% both ways. Also for Oblique axial. Don't count on double</span>0128 <span class="comment">% obliques or anything really fancy.</span>0129 <span class="comment">%</span>0130 0131 0132 <span class="comment">% Have looked over this orientation code carefully (DLW, 03/2003)</span>0133 <span class="comment">% The above comments are from a previous version, note it</span>0134 <span class="comment">% should be LAS, not RAS !!!! I have found some inconsistencies</span>0135 <span class="comment">% in the code (03/2003) and fixed it as best I can for now. Further</span>0136 <span class="comment">% testing with various volumes is required.</span>0137 0138 0139 series_description = deblank(char(ge.hdr.series.se_desc)'); <span class="comment">% unreliable!</span>0140 0141 fprintf(<span class="string">'...checking GE series data orientation.\n'</span>);0142 0143 <span class="comment">% Determine the GE orientation</span>0144 <span class="comment">% orient is 1=axial, 2=sagittal, 3=coronal</span>0145 <span class="comment">% with opposite sign if backwards slice order</span>0146 ras_start = char(ge.hdr.series.start_ras);0147 ras_end = char(ge.hdr.series.end_ras);0148 <span class="keyword">if</span> strcmp(ras_start,<span class="string">'I'</span>) & strcmp(ras_end,<span class="string">'S'</span>),0149 fprintf(<span class="string">'...slices are axial from inferior to superior.\n'</span>);0150 orient = 1;0151 <span class="keyword">elseif</span> strcmp(ras_start,<span class="string">'S'</span>) & strcmp(ras_end,<span class="string">'I'</span>),0152 fprintf(<span class="string">'...slices are axial from superior to inferior.\n'</span>);0153 orient = -1;0154 <span class="keyword">elseif</span> strcmp(ras_start,<span class="string">'R'</span>) & strcmp(ras_end,<span class="string">'L'</span>),0155 fprintf(<span class="string">'...slices are sagittal from right to left.\n'</span>);0156 orient = 2;0157 <span class="keyword">elseif</span> strcmp(ras_start,<span class="string">'L'</span>) & strcmp(ras_end,<span class="string">'R'</span>),0158 fprintf(<span class="string">'...slices are sagittal from left to right.\n'</span>);0159 orient = -2;0160 <span class="keyword">elseif</span> strcmp(ras_start,<span class="string">'P'</span>) & strcmp(ras_end,<span class="string">'A'</span>),0161 fprintf(<span class="string">'...slices are coronal from posterior to anterior.\n'</span>);0162 orient = 3;0163 <span class="keyword">elseif</span> strcmp(ras_start,<span class="string">'A'</span>) & strcmp(ras_end,<span class="string">'P'</span>),0164 fprintf(<span class="string">'...slices are coronal from anterior to posterior.\n'</span>);0165 orient = -3;0166 <span class="keyword">else</span>,0167 warning(<span class="string">'GE orientation unknown!'</span>);0168 orient = 0;0169 <span class="keyword">end</span>0170 0171 <span class="comment">% Get the GE dimensions</span>0172 nX = ge.hdr.image.imatrix_X;0173 nY = ge.hdr.image.imatrix_Y;0174 nZ = ge.hdr.image.slquant; <span class="comment">% slice quantity (Nslices)</span>0175 pX = ge.hdr.image.pixsize_X;0176 pY = ge.hdr.image.pixsize_Y;0177 pZ = ge.hdr.image.slthick + ge.hdr.image.scanspacing;0178 0179 [vX vY vZ] = size(ge.img);0180 0181 <span class="comment">% Reshape into axial radiological orientation (SPM compatible)</span>0182 <span class="comment">% The default Analyze orientation is +X left, +Y anterior, +Z superior (LAS)</span>0183 0184 <span class="keyword">switch</span> orient,0185 0186 <span class="keyword">case</span> 0, <span class="comment">% Unknown Orientation</span>0187 0188 warning(<span class="string">'avw.img = ge.img without reorientation!\n'</span>);0189 avw.img = ge.img;0190 0191 <span class="keyword">case</span> {1, -1}, <span class="comment">% Axial</span>0192 avw.hdr.dime.dim(2:4) = [ nX nY nZ ];0193 avw.hdr.dime.pixdim(2:4) = [ pX pY pZ ];0194 0195 avw.img = ge.img;0196 <span class="keyword">if</span> orient == 1, <span class="comment">% Axial (I to S)</span>0197 <span class="comment">% checked this (03/2003), not sure of L/R orient</span>0198 avw.img = flipdim(avw.img,2); <span class="comment">% flip to P to A</span>0199 <span class="keyword">elseif</span> orient == -1, <span class="comment">% Axial (S to I)</span>0200 <span class="comment">% have not checked this (03/2003)</span>0201 avw.img = flipdim(avw.img,2); <span class="comment">% flip to P to A</span>0202 avw.img = flipdim(avw.img,3); <span class="comment">% flip to I to S</span>0203 <span class="keyword">end</span>0204 0205 <span class="keyword">case</span> {2, -2}, <span class="comment">% Sagittal</span>0206 0207 avw.hdr.dime.dim(2:4) = [ nZ nX nY ];0208 avw.hdr.dime.pixdim(2:4) = [ pZ pX pY ];0209 0210 avw.img = permute(ge.img,[3 1 2]);0211 <span class="keyword">if</span> orient == 2, <span class="comment">% Sagittal (R to L)</span>0212 <span class="comment">% have not checked this (03/2003)</span>0213 avw.img = flipdim(avw.img,2); <span class="comment">% flip to P to A?</span>0214 avw.img = flipdim(avw.img,3); <span class="comment">% flip to I to S?</span>0215 <span class="keyword">elseif</span> orient == -2, <span class="comment">% Sagittal (L to R)</span>0216 <span class="comment">% checked this (03/2003)</span>0217 avw.img = flipdim(avw.img,1); <span class="comment">% flip to R to L</span>0218 avw.img = flipdim(avw.img,2); <span class="comment">% flip to P to A</span>0219 avw.img = flipdim(avw.img,3); <span class="comment">% flip to I to S</span>0220 <span class="keyword">end</span>0221 0222 <span class="keyword">case</span> {3, -3}, <span class="comment">% Coronal</span>0223 0224 avw.hdr.dime.dim(2:4) = [ nX nZ nY ];0225 avw.hdr.dime.pixdim(2:4) = [ pX pZ pY ];0226 0227 avw.img = permute(ge.img,[1 3 2]);0228 <span class="keyword">if</span> orient == 3, <span class="comment">% Coronal (P to A)</span>0229 <span class="comment">% have not checked this (03/2003), not sure of L/R orient</span>0230 avw.img = flipdim(avw.img,3); <span class="comment">% flip to I to S?</span>0231 <span class="keyword">elseif</span> orient == -3, <span class="comment">% Coronal (A to P)</span>0232 <span class="comment">% have not checked this (03/2003), not sure of L/R orient</span>0233 avw.img = flipdim(avw.img,2); <span class="comment">% flip to P to A?</span>0234 avw.img = flipdim(avw.img,3); <span class="comment">% flip to I to S?</span>0235 <span class="keyword">end</span>0236 0237 <span class="keyword">end</span>0238 0239 <span class="comment">% Set the origin to the center of the volume (not sure this is valid, DLW)</span>0240 <span class="comment">%avw.hdr.dime.originator = [floor(avw.hdr.dime.dim(2)/2) ...</span>0241 <span class="comment">% floor(avw.hdr.dime.dim(3)/2) ...</span>0242 <span class="comment">% floor(avw.hdr.dime.dim(4)/2) 0 0];</span>0243 0244 avw.hdr.dime.glmax = max(max(max(avw.img)));0245 avw.hdr.hist.orient = <span class="string">'0'</span>;0246 0247 <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 + -