📄 cor2avw.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head> <title>Description of cor2avw</title> <meta name="keywords" content="cor2avw"> <meta name="description" content="cor2avw - Read Freesurfer MRI data (COR-001 to COR-256)"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="generator" content="m2html © 2003 Guillaume Flandin"> <meta name="robots" content="index, follow"> <link type="text/css" rel="stylesheet" href="../m2html.css"></head><body><a name="_top"></a><div><a href="../index.html">Home</a> > <a href="index.html">mri_toolbox</a> > cor2avw.m</div><!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td><td align="right"><a href="index.html">Index for mri_toolbox <img alt=">" border="0" src="../right.png"></a></td></tr></table>--><h1>cor2avw</h1><h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="box"><strong>cor2avw - Read Freesurfer MRI data (COR-001 to COR-256)</strong></div><h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="box"><strong>function [ avw, machine ] = cor2avw(path,machine) </strong></div><h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="fragment"><pre class="comment"> cor2avw - Read Freesurfer MRI data (COR-001 to COR-256)
[ avw, machine ] = cor2avw(path, machine)
path - the full path to the COR-??? image files. If empty,
this function uses uigetfile to locate COR-001.
machine - a string, see machineformat in fread for details.
The default here is 'ieee-le' but the routine
will automatically switch between little and big
endian to read any such Analyze header. It
reports the appropriate machine format and can
return the machine value.
This function returns an Analyze data structure, with fields:
avw.hdr - a struct with image data parameters.
avw.img - a 3D matrix of image data (double precision).
See also: <a href="avw2cor.html" class="code" title="function avw2cor(avw,CORpath)">avw2cor</a>, <a href="avw_read.html" class="code" title="function [ avw, machine ] = avw_read(fileprefix,IMGorient,machine)">avw_read</a>, <a href="avw_img_read.html" class="code" title="function [ avw, machine ] = avw_img_read(fileprefix,IMGorient,machine)">avw_img_read</a>, <a href="avw_hdr_read.html" class="code" title="function [ avw, machine ] = avw_hdr_read(fileprefix, machine)">avw_hdr_read</a></pre></div><!-- crossreference --><h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>This function calls:<ul style="list-style-image:url(../matlabicon.gif)"><li><a href="avw_hdr_make.html" class="code" title="function [ avw ] = avw_hdr_make">avw_hdr_make</a> AVW_HDR_MAKE - Create Analyze format data header (avw.hdr)</li></ul>This function is called by:<ul style="list-style-image:url(../matlabicon.gif)"></ul><!-- crossreference --><h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><ul style="list-style-image:url(../matlabicon.gif)"><li><a href="#_sub1" class="code">function [ avw ] = read_image(avw,path,machine)</a></li></ul><h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [ avw, machine ] = cor2avw(path,machine)</a>0002 0003 <span class="comment">% cor2avw - Read Freesurfer MRI data (COR-001 to COR-256)</span>0004 <span class="comment">%</span>0005 <span class="comment">% [ avw, machine ] = cor2avw(path, machine)</span>0006 <span class="comment">%</span>0007 <span class="comment">% path - the full path to the COR-??? image files. If empty,</span>0008 <span class="comment">% this function uses uigetfile to locate COR-001.</span>0009 <span class="comment">%</span>0010 <span class="comment">% machine - a string, see machineformat in fread for details.</span>0011 <span class="comment">% The default here is 'ieee-le' but the routine</span>0012 <span class="comment">% will automatically switch between little and big</span>0013 <span class="comment">% endian to read any such Analyze header. It</span>0014 <span class="comment">% reports the appropriate machine format and can</span>0015 <span class="comment">% return the machine value.</span>0016 <span class="comment">%</span>0017 <span class="comment">% This function returns an Analyze data structure, with fields:</span>0018 <span class="comment">%</span>0019 <span class="comment">% avw.hdr - a struct with image data parameters.</span>0020 <span class="comment">% avw.img - a 3D matrix of image data (double precision).</span>0021 <span class="comment">%</span>0022 <span class="comment">% See also: avw2cor, avw_read, avw_img_read, avw_hdr_read</span>0023 <span class="comment">%</span>0024 0025 <span class="comment">% $Revision: 1.3 $ $Date: 2004/02/07 01:41:51 $</span>0026 0027 <span class="comment">% Licence: GNU GPL, no express or implied warranties</span>0028 <span class="comment">% History: 06/2002, Darren.Weber_at_radiology.ucsf.edu</span>0029 <span class="comment">%</span>0030 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0031 0032 0033 <span class="comment">% Create the file header, 256^3, 1 mm^3, uchar, etc</span>0034 avw = <a href="avw_hdr_make.html" class="code" title="function [ avw ] = avw_hdr_make">avw_hdr_make</a>;0035 0036 avw.hdr.dime.dim = int16([4 256 256 256 1 0 0 0]);0037 avw.hdr.dime.pixdim = single([0 1 1 1 0 0 0 0]);0038 0039 0040 version = <span class="string">'[$Revision: 1.3 $]'</span>;0041 fprintf(<span class="string">'\ncor2avw [v%s]\n'</span>,version(12:16));0042 0043 <span class="keyword">if</span> ~exist(<span class="string">'path'</span>,<span class="string">'var'</span>),0044 fprintf(<span class="string">'No input path - see help cor2avw\n'</span>);0045 [file, path] = uigetfile({<span class="string">'*.*'</span>},<span class="string">'Select COR-001 File'</span>);0046 <span class="keyword">end</span>0047 <span class="keyword">if</span> ~exist(<span class="string">'machine'</span>,<span class="string">'var'</span>), machine = <span class="string">'ieee-le'</span>; <span class="keyword">end</span>0048 0049 [path,name,ext] = fileparts(strcat(path,filesep,<span class="string">'COR-001'</span>));0050 file = fullfile(path,[name ext]);0051 fid = fopen(file,<span class="string">'r'</span>,machine);0052 0053 <span class="keyword">if</span> fid < 0,0054 fprintf(<span class="string">'Cannot open file %s\n'</span>,file);0055 fclose(fid);0056 <span class="keyword">else</span>0057 fclose(fid);0058 avw = <a href="#_sub1" class="code" title="subfunction [ avw ] = read_image(avw,path,machine)">read_image</a>(avw,path,machine);0059 <span class="keyword">end</span>0060 0061 <span class="keyword">return</span>0062 0063 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0064 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>0065 <a name="_sub1" href="#_subfunctions" class="code">function [ avw ] = read_image(avw,path,machine)</a>0066 0067 tic;0068 0069 PixelDim = double(avw.hdr.dime.dim(2));0070 RowDim = double(avw.hdr.dime.dim(3));0071 SliceDim = double(avw.hdr.dime.dim(4));0072 0073 <span class="comment">% Allocate memory for the image</span>0074 avw.img = zeros(PixelDim,SliceDim,RowDim);0075 0076 fprintf(<span class="string">'...reading '</span>);0077 0078 <span class="comment">% Read one file/slice at a time</span>0079 <span class="keyword">for</span> y = 1:SliceDim,0080 0081 <span class="keyword">if</span> y > 1,0082 backspaces = repmat(<span class="string">'\b'</span>,1,22);0083 <span class="keyword">else</span>0084 backspaces = <span class="string">''</span>;0085 <span class="keyword">end</span>0086 file = sprintf(<span class="string">'COR-%03d'</span>,y);0087 fprintf([backspaces,<span class="string">'%s %s image.'</span>],machine,file); 0088 0089 [path,name,ext] = fileparts(strcat(path,filesep,file));0090 file = fullfile(path,[name ext]);0091 0092 <span class="comment">% read the whole image into matlab (faster)</span>0093 fid = fopen(file,<span class="string">'r'</span>,machine); fseek(fid,0,<span class="string">'bof'</span>);0094 tmp = fread(fid,inf,<span class="string">'uchar=>double'</span>);0095 fclose(fid);0096 0097 <span class="comment">% Arrange image into avw.img xyz matrix</span>0098 <span class="comment">% For Freesurfer COR files (coronal) the voxels are stored with</span>0099 <span class="comment">% Pixels in 'x' axis (varies fastest) - from patient right to left</span>0100 <span class="comment">% Rows in 'z' axis - from patient superior to inferior</span>0101 <span class="comment">% Slices in 'y' axis - from patient posterior to anterior</span>0102 0103 n = 1;0104 <span class="keyword">for</span> z = RowDim:-1:1,0105 x = 1:PixelDim;0106 avw.img(x,y,z) = tmp(n:n+(PixelDim-1));0107 n = n + PixelDim;0108 <span class="keyword">end</span>0109 <span class="keyword">end</span>0110 0111 avw.hdr.hist.orient = uint8(0);0112 0113 t=toc; fprintf(<span class="string">'\n...done (%5.2f sec).\n'</span>,t);0114 0115 <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 + -