Debian Codegraph @

conversion/ana2mnc/doc/html/AnalyzeFileInfo.html

raw
1 <!DOCTYPE HTML PUBLIC "-//Netscape Comm. Corp.//DTD HTML//EN">
2 <HTML>
3 <HEAD>
4 <!-- SGI_COMMENT COSMOCREATE -->
5 <!-- SGI_COMMENT VERSION NUMBER="1.0" -->
6 <TITLE>ANALYZE (TM) Coordinate system / File Format</TITLE>
7 </HEAD>
8 <BODY BGCOLOR="white">
9 <H1>
10 ANALYZE<sup><KBD>TM</KBD></sup> 7.5 <A NAME="CoordinateSystem">Coordinate
11 System</A></H1>
12 <P>
13 The coordinate system employed by the ANALYZE<sup><KBD>TM</KBD></sup>
14 programs is left-handed, with the coordinate origin in the lower left
15 corner. Thus, with the subject lying supine, the coordinate origin is
16 on the right side of the body (x), at the back (y), and at the feet (z).</P>
17 <P>
18 A major advantage of this convention is that the coordinate origin of
19 each orthogonal orientation (transverse, coronal, and sagittal) lies in
20 the lower left corner of the slice as it is displayed.</P>
21 <P>
22 Orthogonal slices are numbered from one to the number of slices in that
23 orientation. For example, a volume (x, y, z) dimensioned 128, 256, 48
24 has: </P>
25 <UL>
26 <LI>
27 48 transverse slices numbered 1 through 48
28 <LI>
29 128 sagittal slices numbered 1 through 128
30 <LI>
31 256 coronal slices numbered 1 through 256
32 </UL>
33 <P>
34 Pixel coordinates are made with reference to the slice numbers from
35 which the pixels come. Thus, the first pixel in the volume is
36 referenced p(1,1,1) and not at p(0,0,0).</P>
37 <P>
38 The names of the orthogonal planes can be changed in the Configure
39 program.</P>
40 <P>
41 This system is illustrated in the following diagrams.</P>
42 <H4>
43 <B>Volume</B></H4>
44 <UL>
45 <LI>
46 Transverse slices are in the XY plane.
47 <LI>
48 Sagittal slices are in the ZY plane.
49 <LI>
50 Coronal slices are in the ZX plane.
51 </UL>
52 <CENTER><P ALIGN="CENTER">
53 <IMG SRC="images/Orthodiagramsg.gif"
54 SGI_SRC="/images/bir/STAFF/mar/web/analyze/images/Orthodiagramsg.gif"></P>
55 </CENTER><H4>
56 Origin/Order Consistency</H4>
57 <P>
58 We refer to the ANALYZE<sup><KBD>TM</KBD></sup> coordinate system as an
59 origin/order system because it is based on an unambiguous single 3-D
60 origin in the image data, and on the idea that the order of pixels in
61 one line of a section, the order of lines in a section, and the order
62 of sections in a volume all proceed from the origin. As shown in Figure
63 2, the projection of the origin is always displayed at the lower left
64 of the screen, and the order of slices is always from the origin
65 outward. Image data in any of these three orientations (if properly
66 identified) will be correctly rendered as a 3D image (i.e. left-sided
67 defects will appear on the left side of the 3-D rendering). Flipping
68 data in any of the three orientations about two axes will also result
69 in a correctly rendered 3-D image, but the two axis flip will move the
70 effective location of the origin, and the orthogonal sections may
71 appear upside down or left/right reversed when displayed. Flipping the
72 data about one or three axes will ruin the integrity of the data and
73 cause 3-D renderings to appear mirror-reversed (i.e. right-sided
74 lesions will appear to be on the left). Mislabeling transverse data
75 sets as sagittal or vice-versa will not destroy the coherence of the
76 data, and renderings will be correct although the labelling of axes
77 will be in error. However, mislabeling transverse or sagittal images as
78 coronal (or vice-versa) will cause renderings to be mirror reversed.</P>
79 <CENTER><P ALIGN="CENTER">
80 <IMG SRC="images/Figure2.gif"
81 SGI_SRC="/images/bir/STAFF/mar/web/analyze/images/Figure2.gif"> </P>
82 </CENTER><P>
83 It should be noted that the choice of a particular origin/order system
84 is largely arbitrary, and that there are 16 possible origin/order
85 systems based on the transverse orientation, and another 16 possible
86 systems based on each of the other two orientations. </P>
87 <H4>
88 Other Consistent Systems</H4>
89 <P>
90 Origin/order systems provide many conveniences to the programmer,
91 because the complete 3-D orientation of a volume image is coded into
92 the order of pixels in the image file. Origin/order is not, however,
93 the only logically consistent way of thinking about 3-D images made up
94 of 2-D sections. Those who work with sectional images which are not
95 inherently registered by the imaging modality (such as serial
96 microscopic sections or photographs of gross tissue specimens) may
97 naturally think of the sections in a view/order system.</P>
98 <P>
99 View/order consistency is not concerned with the maintenance of a
100 single unambiguous 3-D origin, it simply posits a relationship which
101 should hold between the orientation of the sectional images and their
102 order in the data file. A view/order based system would accept
103 sectional images in any of six orientations, and would assign the x, y,
104 and z axis to the row, column, and slice directions of the image data
105 regardless of the physical section orientation. The main advantage of
106 the view/order concept is that it is highly intuitive and is completely
107 insensitive to orientation. Its major drawback is that the location of
108 the origin and orientations of the axes will vary depending upon the
109 section orientation. Figure 3 illustrates the view order system which
110 most closely matches the origin/order system of ANALYZE<sup><KBD>TM</KBD></sup>,
111 i.e., it is a left-handed coordinate system based on the transverse
112 ANALYZE<sup><KBD>TM</KBD></sup> specification. Note carefully the
113 nconsistencies between this system and the one used in ANALYZE<sup><KBD>TM</KBD></sup>.
114 For example, the first possible transverse orientation of Figure 3 is
115 completely compatible with the ANALYZE<sup><KBD>TM</KBD></sup> format,
116 while the second transverse format is not. If images in this second
117 transverse format are loaded into ANALYZE<sup><KBD>TM</KBD></sup>, the
118 3-D coherence of the image will remain intact, but the initial 3-D
119 rendering will be upside down. On the other hand, neither of the
120 Coronal orientations of Figure 3 are compatible with ANALYZE<sup><KBD>TM</KBD></sup>,and
121 loading images in this order will cause a mirror-reversed 3-D
122 rendering. </P>
123 <CENTER><P ALIGN="CENTER">
124 <IMG SRC="images/Figure3.gif"
125 SGI_SRC="/images/bir/STAFF/mar/web/analyze/images/Figure3.gif"></P>
126 </CENTER><H4>
127 Other Systems</H4>
128 <P>
129 Finally, other systems of data order may be completely arbitrary.
130 Figure 4 illustrates the conventions currently in use at the Mayo
131 Foundation for 3-D MR images. The transverse standard is also the
132 current convention for CT. Note that the conventions describe a
133 consistently right-handed system, but it is not an origin/order system
134 because that the location of the 3-D origin is ambiguous. The order of
135 coronal images implies that the origin is at the back of the head,
136 while the orientation of the transverse and sagittal images clearly
137 indicates it is at the front. Note also that it is not a consistent
138 view/order system, and to add further confusion, the sagittal
139 orientation is standard only for GE and Siemens and is not followed by
140 other manufacturers. </P>
141 <CENTER><P ALIGN="CENTER">
142 <IMG SRC="images/Figure4.gif"
143 SGI_SRC="/images/bir/STAFF/mar/web/analyze/images/Figure4.gif"></P>
144 </CENTER><P>
145 The ANALYZE<sup><KBD>TM</KBD></sup> functions for reading GE and
146 Siemens MR tapes correctly convert the above orientations into the
147 ANALYZE<sup><KBD>TM</KBD></sup> system, but this means the orientation
148 and order of sections in ANALYZE<sup> <KBD>TM</KBD></sup> differs from
149 that seen on the MR console.</P>
150 <P>
151 We strongly suggest a carefully review of data order conventions
152 whenever integrating a new source of images into the ANALYZE<sup><KBD>TM</KBD></sup>
153 system. Only properly labelled images in the correct orientation can
154 be accurately rendered by ANALYZE<sup><KBD>TM</KBD></sup>, and
155 mirror-reversed images are often almost impossible to detect.</P>
156 <HR>
157 <H1>
158 ANALYZE<sup><KBD>TM</KBD></sup> 7.5 <A NAME="FileFormat">File Format</A></H1>
159 <P>
160 The image database is the system of files that the ANALYZE<sup><KBD>TM</KBD></sup>
161 package uses to organize and access image data on the disk. Facilities
162 are provided for converting data from a number of sources for use with
163 the package. A description of the database format is provided to aid
164 developers in porting images from other sources for use with the ANALYZE<sup>
165 <KBD>TM</KBD></sup> system. An ANALYZE<sup><KBD>TM</KBD></sup> image
166 database consists of at least two files: </P>
167 <UL>
168 <LI>
169 an image file
170 <LI>
171 a header file
172 </UL>
173 <P>
174 The files have the same name being distinguished by the extensions .img
175 for the image file and .hdr for the header file. Thus, for the image
176 database heart, there are the UNIX files heart.img and heart.hdr. The
177 ANALYZE<sup><KBD>TM</KBD></sup> programs all refer to this pair of
178 files as a single entity named heart.</P>
179 <H4>
180 Image File </H4>
181 <P>
182 The format of the image file is very simple containing usually
183 uncompressed pixel data for the images in one of several possible pixel
184 formats: </P>
185 <UL>
186 <LI>
187 <B>1 bit</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;packed
188 binary (slices must begin on byte boundaries)
189 <LI>
190 <B>8 bit</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8
191 bits per pixel (unsigned char)
192 <LI>
193 <B>16 bit</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16
194 bits per pixel (signed short)
195 <LI>
196 <B>32 bit</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;32
197 bits per pixel signed integers, or floating point
198 <LI>
199 <B>64 bit </B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;64
200 bits per pixel; double precision, floating point, or complex.
201 <LI>
202 <B>24 bit</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RGB
203 , 8-bits per channel Red, Green, Blue.
204 </UL>
205 <H4>
206 Header File </H4>
207 <P>
208 The header file is represented here as a `C' structure which describes
209 the dimensions and history of the pixel data. The header structure
210 consists of three substructures: </P>
211 <DD>
212 <B>header_key</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;describes
213 the header
214 <DD>
215 <B>image_dimension</B> &nbsp;&nbsp;&nbsp;describes image sizes
216 <DD>
217 <B>data_history</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;optional
218 <HR>
219 <CENTER><H4 ALIGN="CENTER">
220 ANALYZE<sup><KBD>TM</KBD></sup> Header File Format (analyze_db.h)</H4>
221 </CENTER><PRE>
222 <B>struct header_key</B> /* header key */
223 <B>{ </B>/* off + size */
224 int sizeof_hdr /* 0 + 4 */
225 char data_type[10]; /* 4 + 10 */
226 char db_name[18]; /* 14 + 18 */
227 int extents; /* 32 + 4 */
228 short int session_error; /* 36 + 2 */
229 char regular; /* 38 + 1 */
230 char hkey_un0; /* 39 + 1 */
231 <B>}</B>; /* total=40 bytes */
232 <B>struct image_dimension</B>
233 <B> { </B>/* off + size */
234 short int dim[8]; /* 0 + 16 */
235 short int unused8; /* 16 + 2 */
236 short int unused9; /* 18 + 2 */
237 short int unused10; /* 20 + 2 */
238 short int unused11; /* 22 + 2 */
239 short int unused12; /* 24 + 2 */
240 short int unused13; /* 26 + 2 */
241 short int unused14; /* 28 + 2 */
242 short int datatype; /* 30 + 2 */
243 short int bitpix; /* 32 + 2 */
244 short int dim_un0; /* 34 + 2 */
245 float pixdim[8]; /* 36 + 32 */
246 float funused8; /* 68 + 4 */
247 float funused9; /* 72 + 4 */
248 float funused10; /* 76 + 4 */
249 float funused11; /* 80 + 4 */
250 float funused12; /* 84 + 4 */
251 float funused13; /* 88 + 4 */
252 float compressed; /* 92 + 4 */
253 float verified; /* 96 + 4 */
254 int glmax,glmin; /* 100 + 8 */
255 <B>}</B>; /* total=108 bytes */
256 <B>struct data_history</B>
257 <B>{ </B>/* off + size */
258 char descrip[80]; /* 0 + 80 */
259 char aux_file[24]; /* 80 + 24 */
260 char orient; /* 104 + 1 */
261 char originator[10]; /* 105 + 10 */
262 char generated[10]; /* 115 + 10 */
263 char scannum[10]; /* 125 + 10 */
264 char patient_id[10]; /* 135 + 10 */
265 char exp_date[10]; /* 145 + 10 */
266 char exp_time[10]; /* 155 + 10 */
267 char hist_un0[3]; /* 165 + 3 */
268 int views /* 168 + 4 */
269 int vols_added; /* 172 + 4 */
270 int start_field; /* 176 + 4 */
271 int field_skip; /* 180 + 4 */
272 int omax, omin; /* 184 + 8 */
273 int smax, smin; /* 192 + 8 */
274 <B> }</B>;
275 <B>struct dsr</B>
276 <B> {</B>
277 struct header_key hk; /* 0 + 40 */
278 struct image_dimension dime; /* 40 + 108 */
279 struct data_history hist; /* 148 + 200 */
280 <B>}</B>; /* total= 348 bytes*/
281
282 </PRE>
283 <HR>
284 <H4>
285 Comments</H4>
286 <P>
287 The header format is flexible and can be extended for new user-defined
288 data types. The essential structures of the header are the header_key
289 and the image_dimension.</P>
290 <P>
291 The required elements in the <B>header_key</B> substructure are: </P>
292 <DD>
293 <B>int sizeof_header</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Must indicate
294 the byte size of the header file.
295 <DD>
296 <B>int extents&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</B>Should
297 be 16384, the image file is created as contiguous with a minimum extent
298 size.
299 <DD>
300 <B>char regular</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Must
301 be `r' to indicate that all images and volumes are the same size.
302 <P>
303 The <B>image_dimension</B> substructure describes the organization and
304 size of the images. These elements enable the database to reference
305 images by volume and slice number. Explanation of each element follows: </P>
306 <DL>
307 <DT>
308
309 <DD>
310
311 <DL>
312 <DT>
313 <B>short int dim[]</B>; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* array
314 of the image dimensions */
315 <DD>
316 <B>dim[0] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</B>Number of
317 dimensions in database; usually 4
318 <DD>
319 <B>dim[1]</B> <B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</B>Image X
320 dimension; number of pixels in an image row
321 <DD>
322 <B>dim[2]</B> <B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</B>Image Y
323 dimension; number of pixel rows in slice
324 <DD>
325 <B>dim[3]</B> <B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</B>Volume Z
326 dimension; number of slices in a volume
327 <DD>
328 <B>cdim[4] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</B>Time points,
329 number of volumes in database.<BR>
330 <B>char vox_units[4]</B> &nbsp;&nbsp;&nbsp;&nbsp;specifies the
331 spatial units of measure for a voxel
332 <DD>
333 <B>char cal_units[4]</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;specifies
334 the name of the calibration unit
335 <DT>
336 <B>short int datatype</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*
337 datatype for this image set */
338 <DD>
339 /*Acceptable values for datatype are*/
340 <DD>
341 <B>#define DT_NONE &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0</B>
342
343 <DD>
344 <B>#define DT_UNKNOWN &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0</B>
345 <B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*</B>Unknown data type*/
346 <DD>
347 <B>#define DT_BINARY &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1</B>
348 <B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*</B>Binary (1 bit per
349 voxel)*/
350 <DD>
351 <B>#define DT_UNSIGNED_CHAR &nbsp;&nbsp;&nbsp;&nbsp;2</B> <B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*</B>Unsigned
352 character (8 bits per voxel)*/
353 <DD>
354 <B>#define DT_SIGNED_SHORT &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4</B>
355 <B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*</B>Signed short (16 bits
356 per voxel)*/
357 <DD>
358 <B>#define DT_SIGNED_INT &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8</B>
359 <B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*</B>Signed integer (32 bits
360 per voxel)*/
361 <DD>
362 <B>#define DT_FLOAT &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*</B>Floating
363 point (32 bits per voxel)*/
364 <DD>
365 <B>#define DT_COMPLEX &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;32&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*</B>Complex
366 (64 bits per voxel; 2 floating point numbers)
367 <DD>
368 <B>#define DT_DOUBLE &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;64&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*</B>Double
369 precision (64 bits per voxel)*/
370 <DD>
371 <B>#define DT_RGB &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;128&nbsp;&nbsp;&nbsp;&nbsp;/* </B>*/<BR>
372 <B>#define DT_ALL &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255&nbsp;&nbsp;&nbsp;&nbsp;/* </B>*/<BR>
373
374 <DT>
375 <B>short int bitpix;</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*
376 number of bits per pixel; 1, 8, 16, 32, or 64. */
377 <DT>
378 <B>short int dim_un0;</B> &nbsp;&nbsp;/* unused */
379 <DT>
380 <B>float pixdim[];</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parallel
381 array to dim[], giving real world measurements in <I>mm</I>.
382 and <I>ms.</I>
383 <DD>
384 <B>pixdim[1];</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;voxel width in
385 mm.
386 <DD>
387 <B>pixdim[2];</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;voxel height in
388 mm.
389 <DD>
390 <B>pixdim[3];</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;slice thickness
391 in mm.
392 <DT>
393 <B>float vox_offset;</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte
394 offset in the .img file at which voxels start. This value can be <BR>
395 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;negative
396 to specify that the absolute value is applied for every image<BR>
397 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in
398 the file.
399 <DT>
400 <B>float calibrated Max, Min&nbsp;&nbsp;&nbsp;</B> specify the
401 range of calibration values
402 <DT>
403 <B>int glmax, glmin;</B> &nbsp;&nbsp;&nbsp;The maximum and
404 minimum pixel values for the entire database.
405 </DL>
406 </DL>
407 <P>
408 The <B>data_history</B> substructure is not required, but the orient
409 field is used to indicate individual slice orientation and determines
410 whether the Movie program will attempt to flip the images before
411 displaying a movie sequence.</P>
412 <DD>
413 <B>orient:</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;slice orientation
414 for this dataset.
415 <DD>
416 0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transverse unflipped
417 <DD>
418 1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;coronal unflipped
419 <DD>
420 2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sagittal unflipped
421 <DD>
422 3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transverse flipped
423 <DD>
424 4 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;coronal flipped
425 <DD>
426 5 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sagittal flipped
427 <HR>
428 <H4>
429 Sample Program</H4>
430 <P>
431 Any image data can be ported to the ANALYZE<sup><KBD>TM</KBD></sup>
432 system by creating the appropriate image and header files. Although
433 header files can be created with the <B>Header Edit</B> program, the
434 following <B>C</B> program is provided to illustrate how to make an
435 ANALYZE<sup><KBD>TM</KBD></sup> image database header file given the
436 critical image dimensions as parameters. For example; </P>
437 <DD>
438 make_header heart.hdr 128 128 97 3 CHAR 255 0
439 <P>
440 Makes the header file heart.hdr with the following dimensions: </P>
441 <UL>
442 <LI>
443 x dimension = 128
444 <LI>
445 y dimension = 128
446 <LI>
447 slices/volume = 97
448 <LI>
449 volumes in file = 3
450 <LI>
451 bits/pixel = 8
452 <LI>
453 global max = 255
454 <LI>
455 global min = 0
456 </UL>
457 <HR>
458 <PRE>
459 /* <B>This program creates an ANALYZE</B><sup><KBD>TM</KBD></sup><B> database header</B> */
460 /*
461 * (c) Copyright, 1986-1995
462 * Biomedical Imaging Resource
463 * Mayo Foundation
464 *
465 * to compile:
466 *
467 * cc -o make_hdr make_hdr.c
468 *
469 */
470 #include &lt;stdio.h&gt;
471 #include &quot;dbh.h&quot;
472
473 main(argc,argv) /* file x y z t datatype max min */
474 int argc;
475 char **argv;
476 {
477 int i;
478 struct dsr hdr;
479 FILE *fp;
480 static char DataTypes[9][12] = {&quot;UNKNOWN&quot;, &quot;BINARY&quot;,
481 &quot;CHAR&quot;, &quot;SHORT&quot;, &quot;INT&quot;,&quot;FLOAT&quot;, &quot;COMPLEX&quot;,
482 &quot;DOUBLE&quot;, &quot;RGB&quot;};
483
484 static int DataTypeSizes[9] = {0,1,8,16,32,32,64,64,24};
485
486 if(argc != 9)
487 {
488 usage();
489 exit(0);
490 }
491 memset(&amp;hdr,0, sizeof(struct dsr));
492 for(i=0;i&lt;8;i++)
493 hdr.dime.pixdim[i] = 0.0;
494
495 hdr.dime.vox_offset = 0.0;
496 hdr.dime.funused1 = 0.0;
497 hdr.dime.funused2 = 0.0;
498 hdr.dime.funused3 = 0.0;
499 hdr.dime.cal_max = 0.0;
500 hdr.dime.cal_min = 0.0;
501
502
503 hdr.dime.datatype = -1;
504
505 for(i=1;i&lt;=8;i++)
506 if(!strcmp(argv[6],DataTypes[i]))
507 {
508 hdr.dime.datatype = (1&lt;&lt;(i-1));
509 hdr.dime.bitpix = DataTypeSizes[i];
510 break;
511 }
512
513 if(hdr.dime.datatype &lt;= 0)
514 {
515 printf(&quot;&lt;%s&gt; is an unacceptable datatype \n\n&quot;, argv[6]);
516 usage();
517 exit(0);
518 }
519
520 if((fp=fopen(argv[1],&quot;w&quot;))==0)
521 {
522 printf(&quot;unable to create: %s\n&quot;,argv[1]);
523 exit(0);
524 }
525
526 hdr.dime.dim[0] = 4; /* all Analyze images are taken as 4 dimensional */
527 hdr.hk.regular = 'r';
528 hdr.hk.sizeof_hdr = sizeof(struct dsr);
529
530 hdr.dime.dim[1] = atoi(argv[2]); /* slice width in pixels */
531 hdr.dime.dim[2] = atoi(argv[3]); /* slice height in pixels */
532 hdr.dime.dim[3] = atoi(argv[4]); /* volume depth in slices */
533 hdr.dime.dim[4] = atoi(argv[5]); /* number of volumes per file */
534
535 hdr.dime.glmax = atoi(argv[7]); /* maximum voxel value */
536 hdr.dime.glmin = atoi(argv[8]); /* minimum voxel value */
537
538
539
540
541 /* Set the voxel dimension fields:
542 A value of 0.0 for these fields implies that the value is unknown.
543 Change these values to what is appropriate for your data
544 or pass additional command line arguments */
545
546 hdr.dime.pixdim[1] = 0.0; /* voxel x dimension */
547 hdr.dime.pixdim[2] = 0.0; /* voxel y dimension */
548 hdr.dime.pixdim[3] = 0.0; /* pixel z dimension, slice thickness */
549
550 /* Assume zero offset in .img file, byte at which pixel
551 data starts in the image file */
552
553 hdr.dime.vox_offset = 0.0;
554
555 /* Planar Orientation; */
556 /* Movie flag OFF: 0 = transverse, 1 = coronal, 2 = sagittal
557 Movie flag ON: 3 = transverse, 4 = coronal, 5 = sagittal */
558
559 hdr.hist.orient = 0;
560
561 /* up to 3 characters for the voxels units label; i.e. mm., um., cm. */ */
562
563 strcpy(hdr.dime.vox_units,&quot; &quot;);
564
565 /* up to 7 characters for the calibration units label; i.e. HU */
566
567 strcpy(hdr.dime.cal_units,&quot; &quot;);
568
569 /* Calibration maximum and minimum values;
570 values of 0.0 for both fields imply that no
571 calibration max and min values are used */
572
573 hdr.dime.cal_max = 0.0;
574 hdr.dime.cal_min = 0.0;
575
576 fwrite(&amp;hdr,sizeof(struct dsr),1,fp);
577 fclose(fp);
578 }
579
580 usage()
581 {
582 printf(&quot;usage: make_hdr name.hdr x y z t datatype max min \n\n&quot;);
583 printf(&quot; name.hdr = the name of the header file\n&quot;);
584 printf(&quot; x = width, y = height, z = depth, t = number of volumes\n&quot;);
585 printf(&quot; acceptable datatype values are: BINARY, CHAR, SHORT,\n&quot;);
586 printf(&quot; INT, FLOAT, COMPLEX, DOUBLE, and RGB\n&quot;);
587 printf(&quot; max = maximum voxel value, min = minimum voxel value\n&quot;);
588 }
589 </PRE>
590 <HR>
591 <PRE>
592 The following program displays information in an Analyze header file.
593
594 #include &lt;stdio.h&gt;
595 #include &quot;dbh.h&quot;
596
597 void ShowHdr(char *, struct dsr *);
598 void swap_long(unsigned char *);
599 void swap_short(unsigned char *);
600
601 main(argc,argv)
602 int argc;
603 char **argv;
604 {
605 struct dsr hdr;
606 int size;
607 double cmax, cmin;
608 FILE *fp;
609
610 if((fp=fopen(argv[1],&quot;r&quot;))==NULL)
611 {
612 fprintf(stderr,&quot;Can't open:&lt;%s&gt;\n&quot;, argv[1]);
613 exit(0);
614 }
615 fread(&amp;hdr,1,sizeof(struct dsr),fp);
616
617 if(hdr.dime.dim[0] &lt; 0 || hdr.dime.dim[0] &gt; 15)
618 swap_hdr(&amp;hdr);
619
620 ShowHdr(argv[1], &amp;hdr);
621
622
623 }
624
625
626
627
628 void ShowHdr(fileName,hdr)
629 struct dsr *hdr;
630 char *fileName;
631 {
632 int i;
633 char string[128];
634 printf(&quot;Analyze Header Dump of: &lt;%s&gt; \n&quot;, fileName);
635 /* Header Key */
636 printf(&quot;sizeof_hdr: &lt;%d&gt; \n&quot;, hdr-&gt;hk.sizeof_hdr);
637 printf(&quot;data_type: &lt;%s&gt; \n&quot;, hdr-&gt;hk.data_type);
638 printf(&quot;db_name: &lt;%s&gt; \n&quot;, hdr-&gt;hk.db_name);
639 printf(&quot;extents: &lt;%d&gt; \n&quot;, hdr-&gt;hk.extents);
640 printf(&quot;session_error: &lt;%d&gt; \n&quot;, hdr-&gt;hk.session_error);
641 printf(&quot;regular: &lt;%c&gt; \n&quot;, hdr-&gt;hk.regular);
642 printf(&quot;hkey_un0: &lt;%c&gt; \n&quot;, hdr-&gt;hk.hkey_un0);
643
644 /* Image Dimension */
645 for(i=0;i&lt;8;i++)
646 printf(&quot;dim[%d]: &lt;%d&gt; \n&quot;, i, hdr-&gt;dime.dim[i]);
647
648 strncpy(string,hdr-&gt;dime.vox_units,4);
649 printf(&quot;vox_units: &lt;%s&gt; \n&quot;, string);
650
651 strncpy(string,hdr-&gt;dime.cal_units,8);
652 printf(&quot;cal_units: &lt;%s&gt; \n&quot;, string);
653 printf(&quot;unused1: &lt;%d&gt; \n&quot;, hdr-&gt;dime.unused1);
654 printf(&quot;datatype: &lt;%d&gt; \n&quot;, hdr-&gt;dime.datatype);
655 printf(&quot;bitpix: &lt;%d&gt; \n&quot;, hdr-&gt;dime.bitpix);
656
657 for(i=0;i&lt;8;i++)
658 printf(&quot;pixdim[%d]: &lt;%6.4f&gt; \n&quot;,i, hdr-&gt;dime.pixdim[i]);
659
660 printf(&quot;vox_offset: &lt;%6.4&gt; \n&quot;, hdr-&gt;dime.vox_offset);
661 printf(&quot;funused1: &lt;%6.4f&gt; \n&quot;, hdr-&gt;dime.funused1);
662 printf(&quot;funused2: &lt;%6.4f&gt; \n&quot;, hdr-&gt;dime.funused2);
663 printf(&quot;funused3: &lt;%6.4f&gt; \n&quot;, hdr-&gt;dime.funused3);
664 printf(&quot;cal_max: &lt;%6.4f&gt; \n&quot;, hdr-&gt;dime.cal_max);
665 printf(&quot;cal_min: &lt;%6.4f&gt; \n&quot;, hdr-&gt;dime.cal_min);
666 printf(&quot;compressed: &lt;%d&gt; \n&quot;, hdr-&gt;dime.compressed);
667 printf(&quot;verified: &lt;%d&gt; \n&quot;, hdr-&gt;dime.verified);
668 printf(&quot;glmax: &lt;%d&gt; \n&quot;, hdr-&gt;dime.glmax);
669 printf(&quot;glmin: &lt;%d&gt; \n&quot;, hdr-&gt;dime.glmin);
670
671 /* Data History */
672 strncpy(string,hdr-&gt;hist.descrip,80);
673 printf(&quot;descrip: &lt;%s&gt; \n&quot;, string);
674 strncpy(string,hdr-&gt;hist.aux_file,24);
675 printf(&quot;aux_file: &lt;%s&gt; \n&quot;, string);
676 printf(&quot;orient: &lt;%d&gt; \n&quot;, hdr-&gt;hist.orient);
677
678 strncpy(string,hdr-&gt;hist.originator,10);
679 printf(&quot;originator: &lt;%s&gt; \n&quot;, string);
680
681 strncpy(string,hdr-&gt;hist.generated,10);
682 printf(&quot;generated: &lt;%s&gt; \n&quot;, string);
683
684
685 strncpy(string,hdr-&gt;hist.scannum,10);
686 printf(&quot;scannum: &lt;%s&gt; \n&quot;, string);
687
688 strncpy(string,hdr-&gt;hist.patient_id,10);
689 printf(&quot;patient_id: &lt;%s&gt; \n&quot;, string);
690
691 strncpy(string,hdr-&gt;hist.exp_date,10);
692 printf(&quot;exp_date: &lt;%s&gt; \n&quot;, string);
693
694 strncpy(string,hdr-&gt;hist.exp_time,10);
695 printf(&quot;exp_time: &lt;%s&gt; \n&quot;, string);
696
697 strncpy(string,hdr-&gt;hist.hist_un0,10);
698 printf(&quot;hist_un0: &lt;%s&gt; \n&quot;, string);
699
700 printf(&quot;views: &lt;%d&gt; \n&quot;, hdr-&gt;hist.views);
701 printf(&quot;vols_added: &lt;%d&gt; \n&quot;, hdr-&gt;hist.vols_added);
702 printf(&quot;start_field:&lt;%d&gt; \n&quot;, hdr-&gt;hist.start_field);
703 printf(&quot;field_skip: &lt;%d&gt; \n&quot;, hdr-&gt;hist.field_skip);
704 printf(&quot;omax: &lt;%d&gt; \n&quot;, hdr-&gt;hist.omax);
705 printf(&quot;omin: &lt;%d&gt; \n&quot;, hdr-&gt;hist.omin);
706 printf(&quot;smin: &lt;%d&gt; \n&quot;, hdr-&gt;hist.smax);
707 printf(&quot;smin: &lt;%d&gt; \n&quot;, hdr-&gt;hist.smin);
708
709 }
710
711
712 swap_hdr(pntr)
713 struct dsr *pntr;
714 {
715 swap_long(&amp;pntr-&gt;hk.sizeof_hdr) ;
716 swap_long(&amp;pntr-&gt;hk.extents) ;
717 swap_short(&amp;pntr-&gt;hk.session_error) ;
718 swap_short(&amp;pntr-&gt;dime.dim[0]) ;
719 swap_short(&amp;pntr-&gt;dime.dim[1]) ;
720 swap_short(&amp;pntr-&gt;dime.dim[2]) ;
721 swap_short(&amp;pntr-&gt;dime.dim[3]) ;
722 swap_short(&amp;pntr-&gt;dime.dim[4]) ;
723 swap_short(&amp;pntr-&gt;dime.dim[5]) ;
724 swap_short(&amp;pntr-&gt;dime.dim[6]) ;
725 swap_short(&amp;pntr-&gt;dime.dim[7]) ;
726 swap_short(&amp;pntr-&gt;dime.unused1) ;
727 swap_short(&amp;pntr-&gt;dime.datatype) ;
728 swap_short(&amp;pntr-&gt;dime.bitpix) ;
729 swap_long(&amp;pntr-&gt;dime.pixdim[0]) ;
730 swap_long(&amp;pntr-&gt;dime.pixdim[1]) ;
731 swap_long(&amp;pntr-&gt;dime.pixdim[2]) ;
732 swap_long(&amp;pntr-&gt;dime.pixdim[3]) ;
733 swap_long(&amp;pntr-&gt;dime.pixdim[4]) ;
734 swap_long(&amp;pntr-&gt;dime.pixdim[5]) ;
735 swap_long(&amp;pntr-&gt;dime.pixdim[6]) ;
736 swap_long(&amp;pntr-&gt;dime.pixdim[7]) ;
737 swap_long(&amp;pntr-&gt;dime.vox_offset) ;
738 swap_long(&amp;pntr-&gt;dime.funused1) ;
739 swap_long(&amp;pntr-&gt;dime.funused2) ;
740 swap_long(&amp;pntr-&gt;dime.cal_max) ;
741 swap_long(&amp;pntr-&gt;dime.cal_min) ;
742 swap_long(&amp;pntr-&gt;dime.compressed) ;
743 swap_long(&amp;pntr-&gt;dime.verified) ;
744 swap_short(&amp;pntr-&gt;dime.dim_un0) ;
745 swap_long(&amp;pntr-&gt;dime.glmax) ;
746 swap_long(&amp;pntr-&gt;dime.glmin) ;
747 }
748
749 swap_long(pntr)
750 unsigned char *pntr;
751 {
752 unsigned char b0, b1, b2, b3;
753
754 b0 = *pntr;
755 b1 = *(pntr+1);
756 b2 = *(pntr+2);
757 b3 = *(pntr+3);
758
759 *pntr = b3;
760 *(pntr+1) = b2;
761 *(pntr+2) = b1;
762 *(pntr+3) = b0;
763 }
764
765 swap_short(pntr)
766 unsigned char *pntr;
767 {
768 unsigned char b0, b1;
769
770 b0 = *pntr;
771 b1 = *(pntr+1);
772
773 *pntr = b1;
774 *(pntr+1) = b0;
775 }
776 </PRE>
777 <HR>
778 </BODY>
779 </HTML>