1 #ifndef _RWC_ANALYZE_HEADER_ 2 /*************************************************************************** 3 From http://www.mayo.edu/bir/Analyze_Pages/AnalyzeFileInfo.html 4 Describes the ANALYZE 7.5 file format (.img/.hdr pairs). 5 ---------------------------------------------------------------- 6 The image database is the system of files that the ANALYZE package uses to 7 organize and access image data on the disk. Facilities are provided for 8 converting data from a number of sources for use with the package. A 9 description of the database format is provided to aid developers in porting 10 images from other sources for use with the ANALYZE TM system. An ANALYZE 11 image database consists of at least two files: 12 13 * an image file 14 * a header file 15 16 The files have the same name being distinguished by the extensions .img for 17 the image file and .hdr for the header file. Thus, for the image database 18 heart, there are the UNIX files heart.img and heart.hdr. The ANALYZE 19 programs all refer to this pair of files as a single entity named heart. 20 21 Image File 22 23 The format of the image file is very simple containing usually uncompressed 24 pixel data for the images in one of several possible pixel formats: 25 26 * 1 bit packed binary (slices must begin on byte boundaries) 27 * 8 bit 8 bits per pixel (unsigned char) 28 * 16 bit 16 bits per pixel (signed short) 29 * 32 bit 32 bits per pixel signed integers, or floating point 30 * 64 bit 64 bits per pixel; double precision, floating point, 31 or complex. 32 * 24 bit RGB , 8-bits per channel Red, Green, Blue. 33 34 Header File 35 36 The header file is represented here as a `C' structure which describes the 37 dimensions and history of the pixel data. The header structure consists of 38 three substructures: 39 40 header_key describes the header 41 image_dimension describes image sizes 42 data_history optional 43 ****************************************************************************/ 44 45 struct header_key /* header key */ 46 { /* off + size */ 47 int sizeof_hdr; /* 0 + 4 */ 48 char data_type[10]; /* 4 + 10 */ 49 char db_name[18]; /* 14 + 18 */ 50 int extents; /* 32 + 4 */ 51 short int session_error; /* 36 + 2 */ 52 char regular; /* 38 + 1 */ 53 char hkey_un0; /* 39 + 1 */ 54 }; /* total=40 bytes */ 55 struct image_dimension 56 { /* off + size */ 57 short int dim[8]; /* 0 + 16 */ 58 short int unused8; /* 16 + 2 */ 59 short int unused9; /* 18 + 2 */ 60 short int unused10; /* 20 + 2 */ 61 short int unused11; /* 22 + 2 */ 62 short int unused12; /* 24 + 2 */ 63 short int unused13; /* 26 + 2 */ 64 short int unused14; /* 28 + 2 */ 65 short int datatype; /* 30 + 2 */ 66 short int bitpix; /* 32 + 2 */ 67 short int dim_un0; /* 34 + 2 */ 68 float pixdim[8]; /* 36 + 32 */ 69 /* 70 pixdim[] specifies the voxel dimensitons: 71 pixdim[1] - voxel width 72 pixdim[2] - voxel height 73 pixdim[3] - interslice distance 74 ...etc 75 */ 76 float vox_offset; /* 68 + 4 */ 77 float funused1; /* 72 + 4 */ 78 float funused2; /* 76 + 4 */ 79 float funused3; /* 80 + 4 */ 80 float cal_max; /* 84 + 4 */ 81 float cal_min; /* 88 + 4 */ 82 float compressed; /* 92 + 4 */ 83 float verified; /* 96 + 4 */ 84 int glmax,glmin; /* 100 + 8 */ 85 }; /* total=108 bytes */ 86 struct data_history 87 { /* off + size */ 88 char descrip[80]; /* 0 + 80 */ 89 char aux_file[24]; /* 80 + 24 */ 90 char orient; /* 104 + 1 */ 91 char originator[10]; /* 105 + 10 */ 92 char generated[10]; /* 115 + 10 */ 93 char scannum[10]; /* 125 + 10 */ 94 char patient_id[10]; /* 135 + 10 */ 95 char exp_date[10]; /* 145 + 10 */ 96 char exp_time[10]; /* 155 + 10 */ 97 char hist_un0[3]; /* 165 + 3 */ 98 int views; /* 168 + 4 */ 99 int vols_added; /* 172 + 4 */ 100 int start_field; /* 176 + 4 */ 101 int field_skip; /* 180 + 4 */ 102 int omax, omin; /* 184 + 8 */ 103 int smax, smin; /* 192 + 8 */ 104 }; 105 struct dsr 106 { 107 struct header_key hk; /* 0 + 40 */ 108 struct image_dimension dime; /* 40 + 108 */ 109 struct data_history hist; /* 148 + 200 */ 110 }; /* total= 348 bytes*/ 111 112 /* Acceptable values for datatype */ 113 114 #define ANDT_NONE 0 115 #define ANDT_UNKNOWN 0 /* what it says, dude */ 116 #define ANDT_BINARY 1 /* binary (1 bit/voxel) */ 117 #define ANDT_UNSIGNED_CHAR 2 /* unsigned char (8 bits/voxel) */ 118 #define ANDT_SIGNED_SHORT 4 /* signed short (16 bits/voxel) */ 119 #define ANDT_SIGNED_INT 8 /* signed int (32 bits/voxel) */ 120 #define ANDT_FLOAT 16 /* float (32 bits/voxel) */ 121 #define ANDT_COMPLEX 32 /* complex (64 bits/voxel) */ 122 #define ANDT_DOUBLE 64 /* double (64 bits/voxel) */ 123 #define ANDT_RGB 128 /* RGB triple (24 bits/voxel) */ 124 #define ANDT_ALL 255 125 126 #define ANDT_string(aa) \ 127 ((aa)==ANDT_BINARY ? "binary" \ 128 :(aa)==ANDT_UNSIGNED_CHAR ? "byte" \ 129 :(aa)==ANDT_SIGNED_SHORT ? "short" \ 130 :(aa)==ANDT_SIGNED_INT ? "int" \ 131 :(aa)==ANDT_FLOAT ? "float" \ 132 :(aa)==ANDT_COMPLEX ? "complex" \ 133 :(aa)==ANDT_DOUBLE ? "double" \ 134 :(aa)==ANDT_RGB ? "RGB" \ 135 : "unknown" ) 136 137 /*************************************************************************** 138 The header format is flexible and can be extended for new user-defined data 139 types. The essential structures of the header are the header_key and the 140 image_dimension. 141 142 The required elements in the header_key substructure are: 143 144 int sizeof_header Must indicate the byte size of the header file. 145 int extents Should be 16384, the image file is created as 146 contiguous with a minimum extent size. 147 char regular Must be `r' to indicate that all images and 148 volumes are the same size. 149 150 The image_dimension substructure describes the organization and size of the 151 images. These elements enable the database to reference images by volume and 152 slice number. Explanation of each element follows: 153 154 short int dim[]; = array of the image dimensions 155 dim[0] = Number of dimensions in database; usually 4 156 dim[1] = Image X dimension; number of pixels in an image row 157 dim[2] = Image Y dimension; number of pixel rows in slice 158 dim[3] = Volume Z dimension; number of slices in a volume 159 dim[4] = Time points, number of volumes in database. 160 161 char vox_units[4] = specifies the spatial units of measure for a 162 voxel 163 char cal_units[4] = specifies the name of the calibration unit 164 165 short int datatype = datatype for this image set 166 Acceptable values for datatype are one of 167 the ANDT_* defines above 168 169 short int bitpix = number of bits per pixel; 1, 8, 16, 32, 64 170 short int dim_un0 = unused 171 172 float pixdim[] = Parallel array to dim[], giving real world 173 measurements in mm and ms. 174 pixdim[1] = voxel width in mm 175 pixdim[2] = voxel height in mm 176 pixdim[3] = slice thickness in mm 177 float vox_offset = byte offset in the .img file at which voxels 178 start. This value can be negative to specify 179 that the absolute value is applied for every image 180 in the file 181 float cal_max, = specify the range of calibration values 182 cal_min 183 int glmax, glmin = The maximum and minimum pixel values for the 184 entire database 185 186 The data_history substructure is not required, but the orient field is used 187 to indicate individual slice orientation and determines whether the Movie 188 program will attempt to flip the images before displaying a movie sequence. 189 190 orient = slice orientation for this dataset. 191 0 = transverse unflipped 192 1 = coronal unflipped 193 2 = sagittal unflipped 194 3 = transverse flipped 195 4 = coronal flipped 196 5 = sagittal flipped 197 ****************************************************************************/ 198 #endif /* _RWC_ANALYZE_HEADER_ */ 199