⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ge_series_read.html

📁 mri_toolbox是一个工具用来MRI. 来自于SourceForge, 我上传这个软件,希望能结识对医疗软件感兴趣的兄弟.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
0074 dirFiles = dir(seriesPath);0075 n = 0;0076 <span class="keyword">for</span> i = 1:length(dirFiles),0077     <span class="comment">% check whether this file is a directory</span>0078     <span class="keyword">if</span> ~ dirFiles(i).isdir,0079         <span class="comment">% check whether it ends with .MR</span>0080         <span class="keyword">if</span> findstr(dirFiles(i).name,<span class="string">'.MR'</span>),0081             <span class="comment">%fprintf(sprintf('found *.MR file: %s\n',dirFiles(i).name));</span>0082             n = n + 1;0083             seriesFileNames{n} = dirFiles(i).name;0084             imageFormat = <span class="string">'MR'</span>;0085         <span class="keyword">elseif</span> findstr(dirFiles(i).name,<span class="string">'I.'</span>),0086             <span class="comment">%fprintf(sprintf('found I. file: %s\n',dirFiles(i).name));</span>0087             n = n + 1;0088             seriesFileNames{n} = dirFiles(i).name;0089             imageFormat = <span class="string">'I'</span>;0090         <span class="keyword">end</span>0091     <span class="keyword">end</span>0092 <span class="keyword">end</span>0093 0094 <span class="keyword">if</span> n == 0,0095     msg = sprintf(<span class="string">'...Found %d image files (I.* or *.MR)!\n'</span>,n);0096     error(msg);0097 <span class="keyword">else</span>0098     fprintf(<span class="string">'...Found %d image files\n'</span>,n);0099 <span class="keyword">end</span>0100 0101 <span class="keyword">if</span> isequal(imageFormat,<span class="string">'MR'</span>),0102     0103     fprintf(<span class="string">'...sorting *.MR image files into numerical order\n'</span>);0104     0105     <span class="comment">% extract exam/series/image numbers and sort into numerical order</span>0106     fileName.position.exam   = findstr(seriesFileNames{1},<span class="string">'E'</span>);0107     fileName.position.series = findstr(seriesFileNames{1},<span class="string">'S'</span>);0108     fileName.position.image  = findstr(seriesFileNames{1},<span class="string">'I'</span>);0109     0110     range = [ (fileName.position.exam + 1) : (fileName.position.series - 1) ];0111     examN = seriesFileNames{1}(range);0112     0113     range   = [ (fileName.position.series + 1) : (fileName.position.image - 1) ];0114     seriesN = seriesFileNames{1}(range);0115     0116     <span class="keyword">for</span> i = 1:length(seriesFileNames),0117         range = [ fileName.position.image + 1 ];0118         imageNumbers{i} = seriesFileNames{i}(range:end);0119         imageNumbers{i} = strrep(imageNumbers{i},<span class="string">'.MR'</span>,<span class="string">''</span>);0120     <span class="keyword">end</span>0121     imageNumbers = str2double(imageNumbers);0122     [n,i] = sort(imageNumbers);0123     0124     sortedFileNames = seriesFileNames(i);0125     0126 <span class="keyword">elseif</span> isequal(imageFormat, <span class="string">'I'</span>),0127     0128     fprintf(<span class="string">'...sorting I.* image files into numerical order\n'</span>);0129     0130     <span class="comment">% extract image numbers, which might already be in numerical order</span>0131     0132     <span class="keyword">for</span> i = 1:length(seriesFileNames),0133         imageNumbers{i} = seriesFileNames{i}(3:end);0134     <span class="keyword">end</span>0135     imageNumbers = str2double(imageNumbers);0136     [n,i] = sort(imageNumbers);0137     0138     sortedFileNames = seriesFileNames(i);0139     0140 <span class="keyword">end</span>0141 0142 <span class="comment">% --- Create the name of the first file in examPath</span>0143 firstfile = fullfile(seriesPath,sortedFileNames{1});0144 0145 0146 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0147 <span class="comment">% --- Read the header from the first file in the series</span>0148 ge = <a href="ge_hdr_read.html" class="code" title="function [ ge ] = ge_hdr_read(imageFileName)">ge_hdr_read</a>(firstfile);0149 0150 0151 0152 im_offset = ge.img.offset;  <span class="comment">% this is not so good, as the ge.img is replaced below!</span>0153 0154 0155 0156 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0157 <span class="comment">% --- Read the image data from the GE series files</span>0158 0159 version = <span class="string">'[$Revision: 1.4 $]'</span>;0160 fprintf(<span class="string">'\nGE_SERIES_READ [v%s]\n'</span>,version(12:16));0161 fprintf(<span class="string">'...reading image data\n'</span>);0162 0163 <span class="comment">% initialize some variables</span>0164 nX = ge.hdr.image.imatrix_X; <span class="comment">% X Voxels</span>0165 nY = ge.hdr.image.imatrix_Y; <span class="comment">% Y Voxels</span>0166 nZ = ge.hdr.image.slquant;   <span class="comment">% Z Voxels (slice quantity)</span>0167 0168 sliceSize = nX*nY;0169 ge.img = zeros(nX, nY, nZ);0170 0171 fprintf(<span class="string">'...reading '</span>);0172 0173 <span class="keyword">for</span> i = 1:nZ,0174     0175     imageFile = fullfile(seriesPath,sortedFileNames{i});0176     0177     <span class="comment">% output filename to indicate progress</span>0178     <span class="keyword">if</span> i == 1,0179         backspaces = <span class="string">''</span>;0180     <span class="keyword">else</span>0181         filePreviousLength = length(fullfile(seriesPath,sortedFileNames{i-1}));0182         backspaces = repmat(<span class="string">'\b'</span>,1,filePreviousLength);0183     <span class="keyword">end</span>0184     fprintf([backspaces,<span class="string">'%s'</span>],imageFile);0185     0186     0187     <span class="comment">% Open the file</span>0188     [fid,message] = fopen(imageFile,<span class="string">'r'</span>,<span class="string">'b'</span>); <span class="comment">% big endian</span>0189     <span class="keyword">if</span> (fid == -1)0190         fprintf(<span class="string">'Cannot Open %s (big endian).\n'</span>,imageFile);0191         0192         <span class="comment">% Can try to read little endian (shouldn't be necessary!)</span>0193         fprintf(<span class="string">'Trying to read little endian\n'</span>);0194         [fid,message] = fopen(imageFile,<span class="string">'r'</span>,<span class="string">'l'</span>); <span class="comment">% little endian</span>0195         <span class="keyword">if</span> (fid == -1),0196             fprintf(<span class="string">'Cannot Open %s (little endian).\n'</span>,imageFile);0197             <span class="keyword">break</span>0198         <span class="keyword">end</span>0199     <span class="keyword">end</span>0200     0201     <span class="comment">% Skip the header, goto the data</span>0202     fseek(fid,im_offset,-1);0203     <span class="comment">% Read the slice data</span>0204     buffer = fread(fid,sliceSize,sprintf(<span class="string">'int%d'</span>,ge.hdr.image.screenformat));0205     <span class="comment">% append the slice to the imageSet</span>0206     ge.img(:,:,i) = reshape(buffer, nX, nY);0207     0208     <span class="comment">% Close the file</span>0209     status = fclose(fid);0210     0211     <span class="comment">% Set the lastfile</span>0212     lastfile = imageFile;0213 <span class="keyword">end</span>0214 0215 t=toc; fprintf(<span class="string">'\n...done (%5.2f sec).\n'</span>,t);0216 0217 <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> &copy; 2003</address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -