00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: dbh.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/02/20 16:02:11 $ 00007 Version: $Revision: 1.5 $ 00008 00009 Copyright (c) 2002 Insight Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #ifndef __dbh_h__ 00018 #define __dbh_h__ 00019 00020 #ifdef __cplusplus 00021 extern "C" 00022 { 00023 #endif 00024 /************************************************************************* 00025 * Programmer: Hans J. Johnson The following are notes gathered from several sources 00026 * e-mail: hans-johnson@uiowa.edu 00027 * Organization: The University of Iowa 00028 * Function: This file contains the structure definition for Analyze files 00029 **************************************************************************/ 00030 /* Analyze 7.5 From Mayo --Comments From Medical image formats web page in 1999: 00031 * ----------------------------------------------------------------------------------------- 00032 * This very popular software package is produced by the Biomedical Imaging Resource 00033 * group at the Mayo Clinic/Foundation. I have always thought they should give it away 00034 * but they don't, it is moderately expensive, though less so than some other alternatives. 00035 * If you want to test or buy it try contacting 00036 * Denny Hanson <A HREF="mailto:dph@mayo.edu">dph@mayo.edu</A> who is extremely helpful. 00037 * See also the web site at <A HREF="part7.html#AnalyzeFromMayoWebSite">Analyze from Mayo</A>. 00038 * Anyway, importing images into Analyze is a drag and you have to convert your files to their 00039 * format, but it isn't very difficult. I hear that some other programs also use their format 00040 * but haven't encountered them myself. Anyway, the package is sufficiently commonly used that 00041 * it seems appropriate to include the format here. 00042 * This information is included verbatim from what was sent to me by 00043 * Ellis Workman <A HREF="mailto:elw@mayo.edu">elw@mayo.edu</A> and if you have problems I 00044 * am sure he will be able to help. 00045 * ------------------------------------------------------------------------------------------- 00046 */ 00047 /* 00048 * Analyze IMAGE FILE FORMAT -- As much information as I can determine from the Medical image 00049 * formats web site, and the Analyze75.pdf file provided from the Mayo clinic. 00050 * 00051 * Analyze image file sets consist of at least 2 files: 00052 * REQUIRED: 00053 * - an image file ([basename].img or [basename].img.gz or [basename].img.Z) 00054 * This contains the binary represenation of the raw voxel values. If the file 00055 * is compressed, 00056 * it should be of of size (sizeof(storagetype)*NX*NY*NZ(*NT). 00057 * The format of the image file is very simple; containing usually 00058 * uncompressed voxel data for the images in one of the several 00059 * possible voxel formats: 00060 * - 1 bit packed binary (slices begin on byte boundaries) 00061 * - 8 bit (unsigned char) gray scale unless .lkup file present 00062 * - 16 bit signed short 00063 * - 32 bit signed integers or float 00064 * - 24 bit RGB, 8 bits per channel 00065 * - a header file ([basename].hdr) 00066 * This a 348byte file that contains a binary represenation of the C-struct 00067 * defined in this file 00068 * OPTIONAL: 00069 * - a color lookup file ([basename].lkup) 00070 * This is only relevant for unsigned char images. The .lkup file conatins 00071 * 255*3 floating point numbers between the value of (0.0F-1.0F) that can be 00072 * read directly into an array float [255][3]. Each element of the array represents 00073 * the Red Green and Blue components to be associated with the unsigned char value 00074 * at that point. 00075 * - a vol file ([basename].vol) 00076 * - an object file ([basename].obj) 00077 * A specially formated file with a mapping between object name and image code used to associate 00078 * image voxel locations with a label. This file is run length encoded to save disk storage. 00079 */ 00080 /* 00081 * Analyze 7.5 header structure 00082 * The header file is a 'C' structure which describes the dimensions 00083 * and properties of the voxel data. This structure follows: 00084 * NOTE: many programs claim to write analyze 7.5 file format, but fail 00085 * to fill in much of this information. 00086 * 00087 * struct header_key 00088 * int sizeof_header // must indicate the byte size of header file, Always 348 bytes ????? 00089 * char data_type[10] //??????A character string that has a 1 to 1 correspondence 00090 * //with the short int datatype field of the image_dimension. 00091 * //Acceptable values are: DataTypes[10][12]= { "UNKNOWN", 00092 * //"BINARY","CHAR","SHORT", "INT","FLOAT","COMPLEX", 00093 * //"DOUBLE","RGB", "USHORT" }; 00094 * //NOTE: Some programs that claim to use the analyze format 00095 * // do not fill this field in. i.e. AIR 00096 * //NOTE: Some documentation claims that this field should contain 00097 * //information about the type of data stored i.e. MRI-T1, MRI-T2, MRI-PD, CT, etc... 00098 * char db_name[18] //??????????Don't know what this is 00099 * int extents; //Should be 16384, the image file is created as contiguous with a 00100 * //minium extent size. 00101 * //This is the key for determining byte endedness of the file. 00102 * short int session_error; // ????????????Don't know what this is. 00103 * char regular; // This must be 'r' to indicate that all images and volumes are the same size. 00104 * char hkey_un0; // Unused field for future expansion. 00105 * 00106 * struct image_dimension struct decribes the organization and 00107 * size of images. These elements enable IO routines to reference 00108 * images by volume and slice number. 00109 * 00110 * short int dim[] // array of image dimensions 00111 * dim[0] // number of dimensions; usually 4 00112 * dim[1] // image X dimension, i.e. number of voxels per row (adjacent memory locations) 00113 * dim[2] // image Y dimension, i.e. number of rows per slice 00114 * dim[3] // Volume Z dimension, i.e. number of slices per volume 00115 * dim[4] // Number of time points, i.e. number of volumes per series 00116 * . . . 00117 * dim[7] // volumes in file, i.e. number of volumes per series 00118 * 00119 * char vox_units[4] // specifies the spatial units of measure for a voxel, valid values are "mm","cm" and "in" 00120 * // NOTE: if no match is found, "mm" is assumed 00121 * char cal_units[4] // specifies the name of hte calibration unit, valid values are "mm","cm" and "in" 00122 * //??????????How do cal_unit differ from vox_units? 00123 * short int unused; //Unused field for future expansion 00124 * // NOTE: if no match is found, "mm" is assumed 00125 * short int datatype //A short int that has a 1 to 1 correspondence 00126 * //with the string datatype field of the image_dimension. 00127 * //Acceptable values are: 00128 * // enum DataTypeKeyValues { 00129 * // ANALYZE_DT_UNKNOWN =0, 00130 * // ANALYZE_DT_BINARY =1, 00131 * // ANALYZE_DT_UNSIGNED_CHAR =2, 00132 * // ANALYZE_DT_SIGNED_SHORT =4, 00133 * // ANALYZE_DT_SIGNED_INT =8, 00134 * // ANALYZE_DT_FLOAT =16, 00135 * // ANALYZE_DT_COMPLEX =32, 00136 * // ANALYZE_DT_DOUBLE =64, 00137 * // ANALYZE_DT_RGB =128, 00138 * // ANALYZE_DT_ALL =255 00139 * // ANALYZE_DT_UNSIGNED_SHORT =6, ##NOTE: This is not officially supported by the ANALYZE 7.5 file format!! 00140 * // }; 00141 * //NOTE: THIS MUST BE FILLED IN. This is the field that most 00142 * //applications use to determine the type. 00143 * short int bitpix // bits per pixel. This field must agree with the datatype and 00144 * // data_type feilds. 00145 * //DataTypeSizes[11]={0,1,8,16,32,32,64,64,24,0,16}; 00146 * short int dim_un0; // Unused value for future expansion. 00147 * float pixdim[] // parallel array to dim giving voxel dimensions 00148 * NOTE: pixdim[0] is ignored, and the number of dims are taken from dims[0], 00149 * and pixdim[1..7] are the actual pixdims. 00150 * pixdim[1] // voxel width 00151 * pixdim[2] // voxel height 00152 * pixdim[3] // voxel depth or slice thickness 00153 * pixdim[4] // 00154 * . . . 00155 * pixdim[7] // 00156 * 00157 * float vox_offset; // byte offset in the .img file at which 00158 * // voxels start. If value is negative 00159 * // specifies that the absolute value 00160 * // is applied for every image in the file. 00161 * float roi_scale // ???????????Don't know what this does. 00162 * float funused1 // Unused, for future expansion 00163 * float funused2 // Unused, for future expansion 00164 * float cal_max //Specify the minimum of the range of the calibration values. 00165 * float cal_min //Specify the minimum of the range of the calibration values. 00166 * float compressed //?????Have not figured out what the valid values are. 00167 * // Most applications ignore this field. 00168 * int verified //??????????? Don't know what this field is for. 00169 * int glmax, glmin //the max and min values for entire data set. ??What entire data set? 00170 * //??How does this relate to the cal_min,cal_max,omax,omin,smax,smin? 00171 * //??????? What if the datatype is unsigned int or float or RGB or complex? 00172 */ 00173 /* 00174 *The data_history substructure is not required, but the 'orient' element 00175 *is used to indicate individual slice orientation and determines whether 00176 *the Analyze 'Movie' program will attempt to flip the images before 00177 *displaying a movie sequence. 00178 *???????many of the fields in the data_history section are no longer 00179 *???????meaningful. It is perfectly acceptable to put any values you want 00180 *???????into those fields because they do not(should not) affect image 00181 *???????processing. 00182 * char descrip[80] //A place to put a short description of the data. 00183 * char aux_file[24] //A place to put the name of an auxillary file to 00184 * //use instead of the default .img file???????????? 00185 * ???????????????????????????????????????????????? 00186 * A "Radiologic" view of the data and places the spatial 00187 * origin at the subjects Inferior-Right-Posterior. Presumably this is because 00188 * it is the view a radiologist would have of a patient in an MR/PET/CT scanner. 00189 * orient: 00190 * 0 - transverse unflipped (Radiolgic) 00191 * 1 - coronal unflipped (Radiolgic) 00192 * 2 - sagittal unflipped (Radiolgic) 00193 * 3 - transverse flipped 00194 * 4 - coronal flipped 00195 * 5 - sagittal flipped 00196 * Where the Origin disignators are are with respect to the patient 00197 * [(I)nferior|(S)uperior] [(L}eft|(R)ight] [(A)nterior|(P)osterior] 00198 * hdr->orient "MayoClinic/Analyze" Origin dims[1] dims[2] dims[3] 00199 * ====================================================================== 00200 * 0 transverse-unflipped IRP R->L P->A I->S 00201 * 1 coronal-unflipped IRP R->L I->S P->A 00202 * 2 sagittal-unflipped IRP P->A I->S R->L 00203 * 3 transverse-flipped ??? R->L A->P I->S 00204 * 4 coronal-flipped ??? R->L S->I P->A 00205 * 5 sagittal-flipped ??? P->A I->S L->R 00206 * char originator[10] //The person or group that generated this image 00207 * char generated[10] //The data the image was generated???????????? 00208 * char scannum[10] //An instituion independent identifier for the image 00209 * char patient_id[10] //An instituion independant identifier for the subject of the scan 00210 * exp_date[10] //?????????????????????? 00211 * exp_time[10] //?????????????????????? 00212 * char hist_un0[3] //Unused padding of the structure 00213 * int views //?????????????????????? 00214 * int vols_added; //?????????????????????? 00215 * int start_field //?????????????????????? 00216 * int field_skip //?????????????????????? 00217 * int omax //?????????????????????? 00218 * int omin //?????????????????????? 00219 * int smax //?????????????????????? 00220 * int smin //?????????????????????? 00221 */ 00222 00223 enum { 00224 ITKA_TRANSVERSE=0, 00225 ITKA_CORONAL =1, 00226 ITKA_SAGITTAL =2, 00227 ITKA_TRANSVERSE_FLIPPED=3, 00228 ITKA_CORONAL_FLIPPED=4, 00229 ITKA_SAGITTAL_FLIPPED=5 00230 }; 00231 00232 /* 00233 * 00234 * (c) Copyright, 1986-1995 00235 * Biomedical Imaging Resource 00236 * Mayo Foundation 00237 * 00238 * dbh.h 00239 * database sub-definitions 00240 */ 00241 00242 struct header_key /* header_key */ 00243 { /* off + size*/ 00244 int sizeof_hdr; /* 0 + 4 */ 00245 char data_type[10]; /* 4 + 10 */ 00246 char db_name[18]; /* 14 + 18 */ 00247 int extents; /* 32 + 4 */ 00248 short int session_error; /* 36 + 2 */ 00249 char regular; /* 38 + 1 */ 00250 char hkey_un0; /* 39 + 1 */ 00251 }; /* total=40 */ 00252 00253 struct image_dimension /* image_dimension */ 00254 { /* off + size*/ 00255 short int dim[8]; /* 0 + 16 */ 00256 char vox_units[4]; /* 16 + 4 */ 00257 char cal_units[8]; /* 20 + 4 */ 00258 short int unused1; /* 24 + 2 */ 00259 short int datatype; /* 30 + 2 */ 00260 short int bitpix; /* 32 + 2 */ 00261 short int dim_un0; /* 34 + 2 */ 00262 float pixdim[8]; /* 36 + 32 */ 00263 float vox_offset; /* 68 + 4 */ 00264 float roi_scale; /* 72 + 4 */ 00265 float funused1; /* 76 + 4 */ 00266 float funused2; /* 80 + 4 */ 00267 float cal_max; /* 84 + 4 */ 00268 float cal_min; /* 88 + 4 */ 00269 int compressed; /* 92 + 4 */ 00270 int verified; /* 96 + 4 */ 00271 int glmax, glmin; /* 100 + 8 */ 00272 }; /* total=108 */ 00273 00274 struct data_history /* data_history */ 00275 { /* off + size*/ 00276 char descrip[80]; /* 0 + 80 */ 00277 char aux_file[24]; /* 80 + 24 */ 00278 char orient; /* 104 + 1 */ 00279 char originator[10]; /* 105 + 10 */ 00280 char generated[10]; /* 115 + 10 */ 00281 char scannum[10]; /* 125 + 10 */ 00282 char patient_id[10]; /* 135 + 10 */ 00283 char exp_date[10]; /* 145 + 10 */ 00284 char exp_time[10]; /* 155 + 10 */ 00285 char hist_un0[3]; /* 165 + 3 */ 00286 int views; /* 168 + 4 */ 00287 int vols_added; /* 172 + 4 */ 00288 int start_field; /* 176 + 4 */ 00289 int field_skip; /* 180 + 4 */ 00290 int omax,omin; /* 184 + 8 */ 00291 int smax,smin; /* 192 + 8 */ 00292 }; /* total=200 */ 00293 00294 struct dsr /* dsr */ 00295 { /* off + size*/ 00296 struct header_key hk; /* 0 + 40 */ 00297 struct image_dimension dime; /* 40 + 108 */ 00298 struct data_history hist; /* 148 + 200 */ 00299 }; /* total=348 */ 00300 00301 #ifdef __cplusplus 00302 } 00303 #endif /*#ifdef __cplusplus*/ 00304 #endif /* __dbh_h__ */