annotate inst/analyze75write.m @ 892:a2140b980079

iptcheckconn: implement in C++ as static method for connectivity. * iptcheckconn.m: file removed; help text and tests reused for C++. * conndef.cc: implement two new connectivity::validate() methods and the iptcheckconn function for Octave as caller to those methods. * conndef.h: define the connectivity::validate() static methods. * COPYING
author Carnë Draug <carandraug@octave.org>
date Wed, 01 Oct 2014 20:22:37 +0100
parents df3accfcddb8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
641
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
1 %% Copyright (C) 2012 Adam H Aitkenhead <adamaitkenhead@hotmail.com>
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
2 %%
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
3 %% This program is free software; you can redistribute it and/or modify
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
4 %% it under the terms of the GNU General Public License as published by
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
5 %% the Free Software Foundation; either version 3 of the License, or
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
6 %% (at your option) any later version.
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
7 %%
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
8 %% This program is distributed in the hope that it will be useful,
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
9 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
10 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
11 %% GNU General Public License for more details.
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
12 %%
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
13 %% You should have received a copy of the GNU General Public License
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
14 %% along with this program; If not, see <http://www.gnu.org/licenses/>.
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
15
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
16 %% -*- texinfo -*-
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
17 %% @deftypefn {Function File} analyze75write (@var{filename}, @var{data}, @var{header})
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
18 %% @deftypefnx {Function File} analyze75write (@var{filename}, @var{data}, @var{x}, @var{y}, @var{z})
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
19 %% @deftypefnx {Function File} analyze75write (@var{filename}, @var{data}, @var{header}, @var{x}, @var{y}, @var{z})
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
20 %% Write image data to an Analyze 7.5 file.
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
21 %%
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
22 %% @var{filename} is the path to write the Analyze 7.5 file; @var{data} is
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
23 %% the 3D image data; @var{header} is a structure containing the file
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
24 %% information; @var{x}, @var{y}, @var{z} are lists of the x,y,z coordinates
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
25 %% (in cm) of the data grid.
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
26 %%
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
27 %% @seealso{analyze75info, analyze75read}
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
28 %% @end deftypefn
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
29
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
30 %% Author: Adam H. Aitkenhead <adamaitkenhead@hotmail.com>
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
31
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
32 function analyze75write (varargin);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
33
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
34 if (nargin ~= 3 && nargin ~= 5 && nargin ~= 6)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
35 print_usage;
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
36 else
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
37 filename = varargin{1};
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
38 data = varargin{2};
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
39 if (nargin ==3)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
40 header = varargin{3};
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
41 x = ( (0:header.Dimensions(2)-1) - (header.Dimensions(2)-1)/2 ) * header.PixelDimensions(2);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
42 y = ( (0:header.Dimensions(1)-1) - (header.Dimensions(1)-1)/2 ) * header.PixelDimensions(1);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
43 z = ( (0:header.Dimensions(3)-1) - (header.Dimensions(3)-1)/2 ) * header.PixelDimensions(3);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
44 % Convert mm to cm
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
45 if strncmpi(header.VoxelUnits,'mm',2)==1
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
46 x = x / 10;
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
47 y = y / 10;
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
48 z = z / 10;
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
49 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
50 elseif (nargin ==5)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
51 header = struct;
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
52 x = varargin{3};
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
53 y = varargin{4};
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
54 z = varargin{5};
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
55 elseif (nargin ==6)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
56 header = varargin{3};
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
57 x = varargin{4};
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
58 y = varargin{5};
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
59 z = varargin{6};
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
60 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
61 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
62
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
63 if (~ischar (filename))
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
64 error ('analyze75write: `filename'' must be a string.');
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
65 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
66
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
67 %% Strip the filename of the extension
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
68 fileextH = strfind (filename, '.hdr');
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
69 fileextI = strfind (filename, '.img');
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
70 if (~isempty (fileextH))
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
71 fileprefix = filename(1:fileextH(end)-1);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
72 elseif (~isempty (fileextI))
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
73 fileprefix = filename(1:fileextI(end)-1);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
74 else
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
75 fileprefix = filename;
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
76 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
77
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
78 % Check the byteorder
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
79 if (nargin == 6)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
80 if (isfield (header, 'ByteOrder')) && (any (strcmpi (header.ByteOrder, {'ieee-be', 'b'})))
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
81 warning ('analyze75write: No support for big-endian. Please consider submitting a patch. Attempting to write as little-endian');
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
82 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
83 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
84 header.ByteOrder = 'ieee-le';
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
85
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
86 %% Rearrange the data
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
87 data = permute(data,[2,1,3]);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
88
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
89 % Force uniform slice spacing
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
90 if (max(unique(diff(z))) - min(unique(diff(z))) > 1e-4)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
91 warning ('analyze75write: Data slices must be equally spaced. Attempting to interpolate the data onto equally spaced slices.')
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
92 [data,z] = interpslices(data,x,y,z);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
93 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
94
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
95 % Check certain header fields
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
96 header.PixelDimensions = single(10 * [x(2)-x(1),y(2)-y(1),z(2)-z(1)]);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
97 header.Dimensions = int16([size(data),1]);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
98 header.HdrFileSize = int32(348);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
99 header.VoxelUnits = 'mm ';
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
100 header.GlobalMin = int32(min(data(:)));
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
101 header.GlobalMax = int32(max(data(:)));
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
102 header.FileName = [fileprefix,'.hdr'];
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
103
739
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
104 % Descriptor: Generate a string containing the coordinates of the first voxel (stored in the header for information only)
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
105 origintext = ['Coordinates of first voxel: ',num2str( 10* [x(1),y(1),z(1)] ,' %07.2f' )];
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
106 header.Descriptor = sprintf('%-80s',origintext);
641
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
107
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
108 % Determine the type of data
645
cc81e4acc53c analyze75write: Now write int16 and int32 datasets correctly.
adam78a
parents: 643
diff changeset
109 if (isa(data,'int16'))
641
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
110 header.ImgDataType = 'DT_SIGNED_SHORT';
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
111 header.BitDepth = int16(16);
645
cc81e4acc53c analyze75write: Now write int16 and int32 datasets correctly.
adam78a
parents: 643
diff changeset
112 DataTypeLabel = int16(4);
cc81e4acc53c analyze75write: Now write int16 and int32 datasets correctly.
adam78a
parents: 643
diff changeset
113 DataTypeString = 'int16';
647
ad6b73ba5416 analyze75write: Typo correction.
adam78a
parents: 645
diff changeset
114 elseif (isa(data,'int32'))
645
cc81e4acc53c analyze75write: Now write int16 and int32 datasets correctly.
adam78a
parents: 643
diff changeset
115 header.ImgDataType = 'DT_SIGNED_INT';
cc81e4acc53c analyze75write: Now write int16 and int32 datasets correctly.
adam78a
parents: 643
diff changeset
116 header.BitDepth = int16(32);
cc81e4acc53c analyze75write: Now write int16 and int32 datasets correctly.
adam78a
parents: 643
diff changeset
117 DataTypeLabel = int16(8);
cc81e4acc53c analyze75write: Now write int16 and int32 datasets correctly.
adam78a
parents: 643
diff changeset
118 DataTypeString = 'int32';
641
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
119 elseif (isa(data,'single'))
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
120 header.ImgDataType = 'DT_FLOAT';
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
121 header.BitDepth = int16(32);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
122 DataTypeLabel = int16(16);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
123 DataTypeString = 'single';
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
124 elseif (isa(data,'double'))
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
125 header.ImgDataType = 'DT_DOUBLE';
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
126 header.BitDepth = int16(64);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
127 DataTypeLabel = int16(64);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
128 DataTypeString = 'double';
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
129 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
130
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
131 % Write the .hdr file
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
132 fidH = fopen([fileprefix,'.hdr'],'w');
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
133
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
134 fwrite(fidH,header.HdrFileSize,'int32',header.ByteOrder); % HdrFileSize
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
135 fwrite(fidH,repmat(' ',1,10),'char',header.ByteOrder); % HdrDataType
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
136 fwrite(fidH,repmat(' ',1,18),'char',header.ByteOrder); % DatabaseName
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
137 fwrite(fidH,zeros(1,1,'int32'),'int32',header.ByteOrder); % Extents
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
138 fwrite(fidH,zeros(1,1,'int16'),'int16',header.ByteOrder); % SessionError
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
139 fwrite(fidH,'r','char',header.ByteOrder); % Regular
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
140 fwrite(fidH,repmat(' ',1,1),'char',header.ByteOrder); % unused
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
141 fwrite(fidH,zeros(1,1,'int16'),'int16',header.ByteOrder); % unused
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
142 fwrite(fidH,header.Dimensions(1),'int16',header.ByteOrder); % Dimensions(1)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
143 fwrite(fidH,header.Dimensions(2),'int16',header.ByteOrder); % Dimensions(2)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
144 fwrite(fidH,header.Dimensions(3),'int16',header.ByteOrder); % Dimensions(3)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
145 fwrite(fidH,header.Dimensions(4),'int16',header.ByteOrder); % Dimensions(4)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
146 fwrite(fidH,zeros(1,3,'int16'),'int16',header.ByteOrder); % unused
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
147 fwrite(fidH,header.VoxelUnits,'char',header.ByteOrder); % VoxelUnits
739
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
148
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
149 if (isfield(header,'CalibrationUnits')) % CalibrationUnits
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
150 fwrite(fidH,sprintf('%-8s',header.CalibrationUnits(1:min([8,numel(header.CalibrationUnits)]))),'char',header.ByteOrder);
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
151 else
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
152 fwrite(fidH,repmat(' ',1,8),'char',header.ByteOrder);
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
153 end
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
154
641
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
155 fwrite(fidH,zeros(1,1,'int16'),'int16',header.ByteOrder); % unused
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
156 fwrite(fidH,DataTypeLabel,'int16',header.ByteOrder); % ImgDataType
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
157 fwrite(fidH,header.BitDepth,'int16',header.ByteOrder); % BitDepth
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
158 fwrite(fidH,zeros(1,1,'int16'),'int16',header.ByteOrder); % unused
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
159 fwrite(fidH,zeros(1,1,'single'),'float',header.ByteOrder); % unused
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
160 fwrite(fidH,header.PixelDimensions(1),'float',header.ByteOrder); % PixelDimensions(1)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
161 fwrite(fidH,header.PixelDimensions(2),'float',header.ByteOrder); % PixelDimensions(2)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
162 fwrite(fidH,header.PixelDimensions(3),'float',header.ByteOrder); % PixelDimensions(3)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
163 fwrite(fidH,zeros(1,4,'single'),'float',header.ByteOrder); % unused
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
164 fwrite(fidH,zeros(1,1,'single'),'float',header.ByteOrder); % VoxelOffset
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
165 fwrite(fidH,zeros(1,3,'single'),'float',header.ByteOrder); % unused
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
166 fwrite(fidH,zeros(1,1,'single'),'float',header.ByteOrder); % CalibrationMax
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
167 fwrite(fidH,zeros(1,1,'single'),'float',header.ByteOrder); % CalibrationMin
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
168 fwrite(fidH,zeros(1,1,'single'),'float',header.ByteOrder); % Compressed
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
169 fwrite(fidH,zeros(1,1,'single'),'float',header.ByteOrder); % Verified
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
170 fwrite(fidH,header.GlobalMax,'int32',header.ByteOrder); % GlobalMax
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
171 fwrite(fidH,header.GlobalMin,'int32',header.ByteOrder); % GlobalMin
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
172 fwrite(fidH,header.Descriptor,'char',header.ByteOrder); % Descriptor
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
173 fwrite(fidH,'none ','char',header.ByteOrder); % AuxFile
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
174 fwrite(fidH,repmat(' ',1,1),'char',header.ByteOrder); % Orientation
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
175 fwrite(fidH,repmat(' ',1,10),'char',header.ByteOrder); % Originator
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
176 fwrite(fidH,repmat(' ',1,10),'char',header.ByteOrder); % Generated
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
177 fwrite(fidH,repmat(' ',1,10),'char',header.ByteOrder); % Scannumber
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
178
643
753e9f54604f analyze75write: no check value of isxx
carandraug
parents: 641
diff changeset
179 if (isfield(header,'PatientID')) % PatientID
739
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
180 fwrite(fidH,sprintf('%-10s',header.PatientID(1:min([10,numel(header.PatientID)]))),'char',header.ByteOrder);
641
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
181 else
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
182 fwrite(fidH,repmat(' ',1,10),'char',header.ByteOrder);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
183 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
184
643
753e9f54604f analyze75write: no check value of isxx
carandraug
parents: 641
diff changeset
185 if (isfield(header,'ExposureDate')) % ExposureDate
739
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
186 fwrite(fidH,sprintf('%-10s',header.ExposureDate(1:min([10,numel(header.ExposureDate)]))),'char',header.ByteOrder);
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
187 elseif (isfield(header,'StudyDate'))
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
188 fwrite(fidH,sprintf('%-10s',header.StudyDate(1:min([10,numel(header.StudyDate)]))),'char',header.ByteOrder);
641
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
189 else
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
190 fwrite(fidH,repmat(' ',1,10),'char',header.ByteOrder);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
191 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
192
643
753e9f54604f analyze75write: no check value of isxx
carandraug
parents: 641
diff changeset
193 if (isfield(header,'ExposureTime')) % ExposureTime
739
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
194 fwrite(fidH,sprintf('%-10s',header.ExposureTime(1:min([10,numel(header.ExposureTime)]))),'char',header.ByteOrder);
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
195 elseif (isfield(header,'StudyTime'))
df3accfcddb8 analyze75write: Write CalibrationUnits to header if that information is provided in the input. Also, ensure all char entries in the header are left justified.
adam78a
parents: 647
diff changeset
196 fwrite(fidH,sprintf('%-10s',header.StudyTime(1:min([10,numel(header.StudyTime)]))),'char',header.ByteOrder);
641
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
197 else
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
198 fwrite(fidH,repmat(' ',1,10),'char',header.ByteOrder);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
199 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
200
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
201 fwrite(fidH,repmat(' ',1,3),'char',header.ByteOrder); % unused
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
202 fwrite(fidH,zeros(1,1,'int32'),'int32',header.ByteOrder); % Views
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
203 fwrite(fidH,zeros(1,1,'int32'),'int32',header.ByteOrder); % VolumesAdded
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
204 fwrite(fidH,zeros(1,1,'int32'),'int32',header.ByteOrder); % StartField
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
205 fwrite(fidH,zeros(1,1,'int32'),'int32',header.ByteOrder); % FieldSkip
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
206 fwrite(fidH,zeros(1,1,'int32'),'int32',header.ByteOrder); % OMax
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
207 fwrite(fidH,zeros(1,1,'int32'),'int32',header.ByteOrder); % OMin
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
208 fwrite(fidH,zeros(1,1,'int32'),'int32',header.ByteOrder); % SMax
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
209 fwrite(fidH,zeros(1,1,'int32'),'int32',header.ByteOrder); % SMin
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
210
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
211 fclose(fidH);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
212
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
213 % Write the .img file
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
214 fidI = fopen([fileprefix,'.img'],'w');
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
215 fwrite(fidI,data,DataTypeString,header.ByteOrder);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
216 fclose(fidI);
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
217
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
218 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
219
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
220
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
221 function [datanew,znew] = interpslices(data,x,y,z)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
222 znew = z(1):min(diff(z)):z(end);
645
cc81e4acc53c analyze75write: Now write int16 and int32 datasets correctly.
adam78a
parents: 643
diff changeset
223 datanew = zeros(numel(x),numel(y),numel(znew),class(data));
641
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
224 for loopN = 1:numel(znew)
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
225 datanew(:,:,loopN) = interpn(x,y,z,data,x,y,znew(loopN));
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
226 end
1eb2eff01e06 Initial commit into SVN.
adam78a
parents:
diff changeset
227 end