00001
00012 #ifndef _NIFTI_HEADER_
00013 #define _NIFTI_HEADER_
00014
00015 /*****************************************************************************
00016 ** This file defines the "NIFTI-1" header format. **
00017 ** It is derived from 2 meetings at the NIH (31 Mar 2003 and **
00018 ** 02 Sep 2003) of the Data Format Working Group (DFWG), **
00019 ** chartered by the NIfTI (Neuroimaging Informatics Technology **
00020 ** Initiative) at the National Institutes of Health (NIH). **
00021 **--------------------------------------------------------------**
00022 ** Neither the National Institutes of Health (NIH), the DFWG, **
00023 ** nor any of the members or employees of these institutions **
00024 ** imply any warranty of usefulness of this material for any **
00025 ** purpose, and do not assume any liability for damages, **
00026 ** incidental or otherwise, caused by any use of this document. **
00027 ** If these conditions are not acceptable, do not use this! **
00028 **--------------------------------------------------------------**
00029 ** Author: Robert W Cox (NIMH, Bethesda) **
00030 ** Advisors: John Ashburner (FIL, London), **
00031 ** Stephen Smith (FMRIB, Oxford), **
00032 ** Mark Jenkinson (FMRIB, Oxford) **
00033 ******************************************************************************/
00034
00035 /*---------------------------------------------------------------------------*/
00036 /* Note that the ANALYZE 7.5 file header (dbh.h) is
00037 (c) Copyright 1986-1995
00038 Biomedical Imaging Resource
00039 Mayo Foundation
00040 Incorporation of components of dbh.h are by permission of the
00041 Mayo Foundation.
00042
00043 Changes from the ANALYZE 7.5 file header in this file are released to the
00044 public domain, including the functional comments and any amusing asides.
00045 -----------------------------------------------------------------------------*/
00046
00047 /*---------------------------------------------------------------------------*/
00115 /*---------------------------------------------------------------------------*/
00116 /* HEADER STRUCT DECLARATION:
00117 -------------------------
00118 In the comments below for each field, only NIFTI-1 specific requirements
00119 or changes from the ANALYZE 7.5 format are described. For convenience,
00120 the 348 byte header is described as a single struct, rather than as the
00121 ANALYZE 7.5 group of 3 substructs.
00122
00123 Further comments about the interpretation of various elements of this
00124 header are after the data type definition itself. Fields that are
00125 marked as ++UNUSED++ have no particular interpretation in this standard.
00126 (Also see the UNUSED FIELDS comment section, far below.)
00127
00128 The presumption below is that the various C types have particular sizes:
00129 sizeof(int) = sizeof(float) = 4 ; sizeof(short) = 2
00130 -----------------------------------------------------------------------------*/
00131
00132 /*=================*/
00133 #ifdef __cplusplus
00134 extern "C" {
00135 #endif
00136 /*=================*/
00137
00143 /*************************/ /************************/
00144 struct nifti_1_header { /* NIFTI-1 usage */ /* ANALYZE 7.5 field(s) */
00145 /*************************/ /************************/
00146
00147 /*--- was header_key substruct ---*/
00148 int sizeof_hdr; /* int sizeof_hdr; */
00149 char data_type[10]; /* char data_type[10]; */
00150 char db_name[18]; /* char db_name[18]; */
00151 int extents; /* int extents; */
00152 short session_error; /* short session_error; */
00153 char regular; /* char regular; */
00154 char dim_info; /* char hkey_un0; */
00155
00156 /*--- was image_dimension substruct ---*/
00157 short dim[8]; /* short dim[8]; */
00158 float intent_p1 ; /* short unused8; */
00159 /* short unused9; */
00160 float intent_p2 ; /* short unused10; */
00161 /* short unused11; */
00162 float intent_p3 ; /* short unused12; */
00163 /* short unused13; */
00164 short intent_code ; /* short unused14; */
00165 short datatype; /* short datatype; */
00166 short bitpix; /* short bitpix; */
00167 short slice_start; /* short dim_un0; */
00168 float pixdim[8]; /* float pixdim[8]; */
00169 float vox_offset; /* float vox_offset; */
00170 float scl_slope ; /* float funused1; */
00171 float scl_inter ; /* float funused2; */
00172 short slice_end; /* float funused3; */
00173 char slice_code ;
00174 char xyzt_units ;
00175 float cal_max; /* float cal_max; */
00176 float cal_min; /* float cal_min; */
00177 float slice_duration; /* float compressed; */
00178 float toffset; /* float verified; */
00179 int glmax; /* int glmax; */
00180 int glmin; /* int glmin; */
00181
00182 /*--- was data_history substruct ---*/
00183 char descrip[80]; /* char descrip[80]; */
00184 char aux_file[24]; /* char aux_file[24]; */
00185
00186 short qform_code ; /*-- all ANALYZE 7.5 ---*/
00187 short sform_code ; /* fields below here */
00188 /* are replaced */
00189 float quatern_b ;
00190 float quatern_c ;
00191 float quatern_d ;
00192 float qoffset_x ;
00193 float qoffset_y ;
00194 float qoffset_z ;
00196 float srow_x[4] ;
00197 float srow_y[4] ;
00198 float srow_z[4] ;
00200 char intent_name[16];
00202 char magic[4] ;
00204 } ; /**** 348 bytes total ****/
00205
00206 typedef struct nifti_1_header nifti_1_header ;
00207
00208 /*---------------------------------------------------------------------------*/
00209 /* HEADER EXTENSIONS:
00210 -----------------
00211 After the end of the 348 byte header (e.g., after the magic field),
00212 the next 4 bytes are a char array field named "extension". By default,
00213 all 4 bytes of this array should be set to zero. In a .nii file, these
00214 4 bytes will always be present, since the earliest start point for
00215 the image data is byte #352. In a separate .hdr file, these bytes may
00216 or may not be present. If not present (i.e., if the length of the .hdr
00217 file is 348 bytes), then a NIfTI-1 compliant program should use the
00218 default value of extension={0,0,0,0}. The first byte (extension[0])
00219 is the only value of this array that is specified at present. The other
00220 3 bytes are reserved for future use.
00221
00222 If extension[0] is nonzero, it indicates that extended header information
00223 is present in the bytes following the extension array. In a .nii file,
00224 this extended header data is before the image data (and vox_offset
00225 must be set correctly to allow for this). In a .hdr file, this extended
00226 data follows extension and proceeds (potentially) to the end of the file.
00227
00228 The format of extended header data is weakly specified. Each extension
00229 must be an integer multiple of 16 bytes long. The first 8 bytes of each
00230 extension comprise 2 integers:
00231 int esize , ecode ;
00232 These values may need to be byte-swapped, as indicated by dim[0] for
00233 the rest of the header.
00234 * esize is the number of bytes that form the extended header data
00235 + esize must be a positive integral multiple of 16
00236 + this length includes the 8 bytes of esize and ecode themselves
00237 * ecode is a non-negative integer that indicates the format of the
00238 extended header data that follows
00239 + different ecode values are assigned to different developer groups
00240 + at present, the "registered" values for code are
00241 = 0 = unknown private format (not recommended!)
00242 = 2 = DICOM format (i.e., attribute tags and values)
00243 = 4 = AFNI group (i.e., ASCII XML-ish elements)
00244 In the interests of interoperability (a primary rationale for NIfTI),
00245 groups developing software that uses this extension mechanism are
00246 encouraged to document and publicize the format of their extensions.
00247 To this end, the NIfTI DFWG will assign even numbered codes upon request
00248 to groups submitting at least rudimentary documentation for the format
00249 of their extension; at present, the contact is mailto:rwcox@nih.gov.
00250 The assigned codes and documentation will be posted on the NIfTI
00251 website. All odd values of ecode (and 0) will remain unassigned;
00252 at least, until the even ones are used up, when we get to 2,147,483,646.
00253
00254 Note that the other contents of the extended header data section are
00255 totally unspecified by the NIfTI-1 standard. In particular, if binary
00256 data is stored in such a section, its byte order is not necessarily
00257 the same as that given by examining dim[0]; it is incumbent on the
00258 programs dealing with such data to determine the byte order of binary
00259 extended header data.
00260
00261 Multiple extended header sections are allowed, each starting with an
00262 esize,ecode value pair. The first esize value, as described above,
00263 is at bytes #352-355 in the .hdr or .nii file (files start at byte #0).
00264 If this value is positive, then the second (esize2) will be found
00265 starting at byte #352+esize1 , the third (esize3) at byte #352+esize1+esize2,
00266 et cetera. Of course, in a .nii file, the value of vox_offset must
00267 be compatible with these extensions. If a malformed file indicates
00268 that an extended header data section would run past vox_offset, then
00269 the entire extended header section should be ignored. In a .hdr file,
00270 if an extended header data section would run past the end-of-file,
00271 that extended header data should also be ignored.
00272
00273 With the above scheme, a program can successively examine the esize
00274 and ecode values, and skip over each extended header section if the
00275 program doesn't know how to interpret the data within. Of course, any
00276 program can simply ignore all extended header sections simply by jumping
00277 straight to the image data using vox_offset.
00278 -----------------------------------------------------------------------------*/
00279
00287 struct nifti1_extender { char extension[4] ; } ;
00288 typedef struct nifti1_extender nifti1_extender ;
00289
00293 struct nifti1_extension {
00294 int esize ;
00295 int ecode ;
00296 char * edata ;
00297 } ;
00298 typedef struct nifti1_extension nifti1_extension ;
00299
00300 /*---------------------------------------------------------------------------*/
00301 /* DATA DIMENSIONALITY (as in ANALYZE 7.5):
00302 ---------------------------------------
00303 dim[0] = number of dimensions;
00304 - if dim[0] is outside range 1..7, then the header information
00305 needs to be byte swapped appropriately
00306 - ANALYZE supports dim[0] up to 7, but NIFTI-1 reserves
00307 dimensions 1,2,3 for space (x,y,z), 4 for time (t), and
00308 5,6,7 for anything else needed.
00309
00310 dim[i] = length of dimension #i, for i=1..dim[0] (must be positive)
00311 - also see the discussion of intent_code, far below
00312
00313 pixdim[i] = voxel width along dimension #i, i=1..dim[0] (positive)
00314 - cf. ORIENTATION section below for use of pixdim[0]
00315 - the units of pixdim can be specified with the xyzt_units
00316 field (also described far below).
00317
00318 Number of bits per voxel value is in bitpix, which MUST correspond with
00319 the datatype field. The total number of bytes in the image data is
00320 dim[1] * ... * dim[dim[0]] * bitpix / 8
00321
00322 In NIFTI-1 files, dimensions 1,2,3 are for space, dimension 4 is for time,
00323 and dimension 5 is for storing multiple values at each spatiotemporal
00324 voxel. Some examples:
00325 - A typical whole-brain FMRI experiment's time series:
00326 - dim[0] = 4
00327 - dim[1] = 64 pixdim[1] = 3.75 xyzt_units = NIFTI_UNITS_MM
00328 - dim[2] = 64 pixdim[2] = 3.75 | NIFTI_UNITS_SEC
00329 - dim[3] = 20 pixdim[3] = 5.0
00330 - dim[4] = 120 pixdim[4] = 2.0
00331 - A typical T1-weighted anatomical volume:
00332 - dim[0] = 3
00333 - dim[1] = 256 pixdim[1] = 1.0 xyzt_units = NIFTI_UNITS_MM
00334 - dim[2] = 256 pixdim[2] = 1.0
00335 - dim[3] = 128 pixdim[3] = 1.1
00336 - A single slice EPI time series:
00337 - dim[0] = 4
00338 - dim[1] = 64 pixdim[1] = 3.75 xyzt_units = NIFTI_UNITS_MM
00339 - dim[2] = 64 pixdim[2] = 3.75 | NIFTI_UNITS_SEC
00340 - dim[3] = 1 pixdim[3] = 5.0
00341 - dim[4] = 1200 pixdim[4] = 0.2
00342 - A 3-vector stored at each point in a 3D volume:
00343 - dim[0] = 5
00344 - dim[1] = 256 pixdim[1] = 1.0 xyzt_units = NIFTI_UNITS_MM
00345 - dim[2] = 256 pixdim[2] = 1.0
00346 - dim[3] = 128 pixdim[3] = 1.1
00347 - dim[4] = 1 pixdim[4] = 0.0
00348 - dim[5] = 3 intent_code = NIFTI_INTENT_VECTOR
00349 - A single time series with a 3x3 matrix at each point:
00350 - dim[0] = 5
00351 - dim[1] = 1 xyzt_units = NIFTI_UNITS_SEC
00352 - dim[2] = 1
00353 - dim[3] = 1
00354 - dim[4] = 1200 pixdim[4] = 0.2
00355 - dim[5] = 9 intent_code = NIFTI_INTENT_GENMATRIX
00356 - intent_p1 = intent_p2 = 3.0 (indicates matrix dimensions)
00357 -----------------------------------------------------------------------------*/
00358
00359 /*---------------------------------------------------------------------------*/
00360 /* DATA STORAGE:
00361 ------------
00362 If the magic field is "n+1", then the voxel data is stored in the
00363 same file as the header. In this case, the voxel data starts at offset
00364 (int)vox_offset into the header file. Thus, vox_offset=352.0 means that
00365 the data starts immediately after the NIFTI-1 header. If vox_offset is
00366 greater than 352, the NIFTI-1 format does not say much about the
00367 contents of the dataset file between the end of the header and the
00368 start of the data.
00369
00370 FILES:
00371 -----
00372 If the magic field is "ni1", then the voxel data is stored in the
00373 associated ".img" file, starting at offset 0 (i.e., vox_offset is not
00374 used in this case, and should be set to 0.0).
00375
00376 When storing NIFTI-1 datasets in pairs of files, it is customary to name
00377 the files in the pattern "name.hdr" and "name.img", as in ANALYZE 7.5.
00378 When storing in a single file ("n+1"), the file name should be in
00379 the form "name.nii" (the ".nft" and ".nif" suffixes are already taken;
00380 cf. http://www.icdatamaster.com/n.html ).
00381
00382 BYTE ORDERING:
00383 -------------
00384 The byte order of the data arrays is presumed to be the same as the byte
00385 order of the header (which is determined by examining dim[0]).
00386
00387 Floating point types are presumed to be stored in IEEE-754 format.
00388 -----------------------------------------------------------------------------*/
00389
00390 /*---------------------------------------------------------------------------*/
00391 /* DETAILS ABOUT vox_offset:
00392 ------------------------
00393 In a .nii file, the vox_offset field value is interpreted as the start
00394 location of the image data bytes in that file. In a .hdr/.img file pair,
00395 the vox_offset field value is the start location of the image data
00396 bytes in the .img file.
00397 * If vox_offset is less than 352 in a .nii file, it is equivalent
00398 to 352 (i.e., image data never starts before byte #352 in a .nii file).
00399 * The default value for vox_offset in a .nii file is 352.
00400 * In a .hdr file, the default value for vox_offset is 0.
00401 * vox_offset should be an integer multiple of 16; otherwise, some
00402 programs may not work properly (e.g., SPM). This is to allow
00403 memory-mapped input to be properly byte-aligned.
00404 Note that since vox_offset is an IEEE-754 32 bit float (for compatibility
00405 with the ANALYZE-7.5 format), it effectively has a 24 bit mantissa. All
00406 integers from 0 to 2^24 can be represented exactly in this format, but not
00407 all larger integers are exactly storable as IEEE-754 32 bit floats. However,
00408 unless you plan to have vox_offset be potentially larger than 16 MB, this
00409 should not be an issue. (Actually, any integral multiple of 16 up to 2^27
00410 can be represented exactly in this format, which allows for up to 128 MB
00411 of random information before the image data. If that isn't enough, then
00412 perhaps this format isn't right for you.)
00413
00414 In a .img file (i.e., image data stored separately from the NIfTI-1
00415 header), data bytes between #0 and #vox_offset-1 (inclusive) are completely
00416 undefined and unregulated by the NIfTI-1 standard. One potential use of
00417 having vox_offset > 0 in the .hdr/.img file pair storage method is to make
00418 the .img file be a copy of (or link to) a pre-existing image file in some
00419 other format, such as DICOM; then vox_offset would be set to the offset of
00420 the image data in this file. (It may not be possible to follow the
00421 "multiple-of-16 rule" with an arbitrary external file; using the NIfTI-1
00422 format in such a case may lead to a file that is incompatible with software
00423 that relies on vox_offset being a multiple of 16.)
00424
00425 In a .nii file, data bytes between #348 and #vox_offset-1 (inclusive) may
00426 be used to store user-defined extra information; similarly, in a .hdr file,
00427 any data bytes after byte #347 are available for user-defined extra
00428 information. The (very weak) regulation of this extra header data is
00429 described elsewhere.
00430 -----------------------------------------------------------------------------*/
00431
00432 /*---------------------------------------------------------------------------*/
00433 /* DATA SCALING:
00434 ------------
00435 If the scl_slope field is nonzero, then each voxel value in the dataset
00436 should be scaled as
00437 y = scl_slope * x + scl_inter
00438 where x = voxel value stored
00439 y = "true" voxel value
00440 Normally, we would expect this scaling to be used to store "true" floating
00441 values in a smaller integer datatype, but that is not required. That is,
00442 it is legal to use scaling even if the datatype is a float type (crazy,
00443 perhaps, but legal).
00444 - However, the scaling is to be ignored if datatype is DT_RGB24.
00445 - If datatype is a complex type, then the scaling is to be
00446 applied to both the real and imaginary parts.
00447
00448 The cal_min and cal_max fields (if nonzero) are used for mapping (possibly
00449 scaled) dataset values to display colors:
00450 - Minimum display intensity (black) corresponds to dataset value cal_min.
00451 - Maximum display intensity (white) corresponds to dataset value cal_max.
00452 - Dataset values below cal_min should display as black also, and values
00453 above cal_max as white.
00454 - Colors "black" and "white", of course, may refer to any scalar display
00455 scheme (e.g., a color lookup table specified via aux_file).
00456 - cal_min and cal_max only make sense when applied to scalar-valued
00457 datasets (i.e., dim[0] < 5 or dim[5] = 1).
00458 -----------------------------------------------------------------------------*/
00459
00460 /*---------------------------------------------------------------------------*/
00461 /* TYPE OF DATA (acceptable values for datatype field):
00462 ---------------------------------------------------
00463 Values of datatype smaller than 256 are ANALYZE 7.5 compatible.
00464 Larger values are NIFTI-1 additions. These are all multiples of 256, so
00465 that no bits below position 8 are set in datatype. But there is no need
00466 to use only powers-of-2, as the original ANALYZE 7.5 datatype codes do.
00467
00468 The additional codes are intended to include a complete list of basic
00469 scalar types, including signed and unsigned integers from 8 to 64 bits,
00470 floats from 32 to 128 bits, and complex (float pairs) from 64 to 256 bits.
00471
00472 Note that most programs will support only a few of these datatypes!
00473 A NIFTI-1 program should fail gracefully (e.g., print a warning message)
00474 when it encounters a dataset with a type it doesn't like.
00475 -----------------------------------------------------------------------------*/
00476
00477 #undef DT_UNKNOWN /* defined in dirent.h on some Unix systems */
00478
00483 /*--- the original ANALYZE 7.5 type codes ---*/
00484 #define DT_NONE 0
00485 #define DT_UNKNOWN 0 /* what it says, dude */
00486 #define DT_BINARY 1 /* binary (1 bit/voxel) */
00487 #define DT_UNSIGNED_CHAR 2 /* unsigned char (8 bits/voxel) */
00488 #define DT_SIGNED_SHORT 4 /* signed short (16 bits/voxel) */
00489 #define DT_SIGNED_INT 8 /* signed int (32 bits/voxel) */
00490 #define DT_FLOAT 16 /* float (32 bits/voxel) */
00491 #define DT_COMPLEX 32 /* complex (64 bits/voxel) */
00492 #define DT_DOUBLE 64 /* double (64 bits/voxel) */
00493 #define DT_RGB 128 /* RGB triple (24 bits/voxel) */
00494 #define DT_ALL 255 /* not very useful (?) */
00495
00496 /*----- another set of names for the same ---*/
00497 #define DT_UINT8 2
00498 #define DT_INT16 4
00499 #define DT_INT32 8
00500 #define DT_FLOAT32 16
00501 #define DT_COMPLEX64 32
00502 #define DT_FLOAT64 64
00503 #define DT_RGB24 128
00504
00505 /*------------------- new codes for NIFTI ---*/
00506 #define DT_INT8 256 /* signed char (8 bits) */
00507 #define DT_UINT16 512 /* unsigned short (16 bits) */
00508 #define DT_UINT32 768 /* unsigned int (32 bits) */
00509 #define DT_INT64 1024 /* long long (64 bits) */
00510 #define DT_UINT64 1280 /* unsigned long long (64 bits) */
00511 #define DT_FLOAT128 1536 /* long double (128 bits) */
00512 #define DT_COMPLEX128 1792 /* double pair (128 bits) */
00513 #define DT_COMPLEX256 2048 /* long double pair (256 bits) */
00514 #define DT_RGBA32 2304 /* 4 byte RGBA (32 bits/voxel) */
00515 /* @} */
00516
00517
00518 /*------- aliases for all the above codes ---*/
00519
00525 #define NIFTI_TYPE_UINT8 2
00526
00527 #define NIFTI_TYPE_INT16 4
00528
00529 #define NIFTI_TYPE_INT32 8
00530
00531 #define NIFTI_TYPE_FLOAT32 16
00532
00533 #define NIFTI_TYPE_COMPLEX64 32
00534
00535 #define NIFTI_TYPE_FLOAT64 64
00536
00537 #define NIFTI_TYPE_RGB24 128
00538
00539 #define NIFTI_TYPE_INT8 256
00540
00541 #define NIFTI_TYPE_UINT16 512
00542
00543 #define NIFTI_TYPE_UINT32 768
00544
00545 #define NIFTI_TYPE_INT64 1024
00546
00547 #define NIFTI_TYPE_UINT64 1280
00548
00549 #define NIFTI_TYPE_FLOAT128 1536
00550
00551 #define NIFTI_TYPE_COMPLEX128 1792
00552
00553 #define NIFTI_TYPE_COMPLEX256 2048
00554
00555 #define NIFTI_TYPE_RGBA32 2304
00556 /* @} */
00557
00558 /*-------- sample typedefs for complicated types ---*/
00559 #if 0
00560 typedef struct { float r,i; } complex_float ;
00561 typedef struct { double r,i; } complex_double ;
00562 typedef struct { long double r,i; } complex_longdouble ;
00563 typedef struct { unsigned char r,g,b; } rgb_byte ;
00564 #endif
00565
00566 /*---------------------------------------------------------------------------*/
00567 /* INTERPRETATION OF VOXEL DATA:
00568 ----------------------------
00569 The intent_code field can be used to indicate that the voxel data has
00570 some particular meaning. In particular, a large number of codes is
00571 given to indicate that the the voxel data should be interpreted as
00572 being drawn from a given probability distribution.
00573
00574 VECTOR-VALUED DATASETS:
00575 ----------------------
00576 The 5th dimension of the dataset, if present (i.e., dim[0]=5 and
00577 dim[5] > 1), contains multiple values (e.g., a vector) to be stored
00578 at each spatiotemporal location. For example, the header values
00579 - dim[0] = 5
00580 - dim[1] = 64
00581 - dim[2] = 64
00582 - dim[3] = 20
00583 - dim[4] = 1 (indicates no time axis)
00584 - dim[5] = 3
00585 - datatype = DT_FLOAT
00586 - intent_code = NIFTI_INTENT_VECTOR
00587 mean that this dataset should be interpreted as a 3D volume (64x64x20),
00588 with a 3-vector of floats defined at each point in the 3D grid.
00589
00590 A program reading a dataset with a 5th dimension may want to reformat
00591 the image data to store each voxels' set of values together in a struct
00592 or array. This programming detail, however, is beyond the scope of the
00593 NIFTI-1 file specification! Uses of dimensions 6 and 7 are also not
00594 specified here.
00595
00596 STATISTICAL PARAMETRIC DATASETS (i.e., SPMs):
00597 --------------------------------------------
00598 Values of intent_code from NIFTI_FIRST_STATCODE to NIFTI_LAST_STATCODE
00599 (inclusive) indicate that the numbers in the dataset should be interpreted
00600 as being drawn from a given distribution. Most such distributions have
00601 auxiliary parameters (e.g., NIFTI_INTENT_TTEST has 1 DOF parameter).
00602
00603 If the dataset DOES NOT have a 5th dimension, then the auxiliary parameters
00604 are the same for each voxel, and are given in header fields intent_p1,
00605 intent_p2, and intent_p3.
00606
00607 If the dataset DOES have a 5th dimension, then the auxiliary parameters
00608 are different for each voxel. For example, the header values
00609 - dim[0] = 5
00610 - dim[1] = 128
00611 - dim[2] = 128
00612 - dim[3] = 1 (indicates a single slice)
00613 - dim[4] = 1 (indicates no time axis)
00614 - dim[5] = 2
00615 - datatype = DT_FLOAT
00616 - intent_code = NIFTI_INTENT_TTEST
00617 mean that this is a 2D dataset (128x128) of t-statistics, with the
00618 t-statistic being in the first "plane" of data and the degrees-of-freedom
00619 parameter being in the second "plane" of data.
00620
00621 If the dataset 5th dimension is used to store the voxel-wise statistical
00622 parameters, then dim[5] must be 1 plus the number of parameters required
00623 by that distribution (e.g., intent_code=NIFTI_INTENT_TTEST implies dim[5]
00624 must be 2, as in the example just above).
00625
00626 Note: intent_code values 2..10 are compatible with AFNI 1.5x (which is
00627 why there is no code with value=1, which is obsolescent in AFNI).
00628
00629 OTHER INTENTIONS:
00630 ----------------
00631 The purpose of the intent_* fields is to help interpret the values
00632 stored in the dataset. Some non-statistical values for intent_code
00633 and conventions are provided for storing other complex data types.
00634
00635 The intent_name field provides space for a 15 character (plus 0 byte)
00636 'name' string for the type of data stored. Examples:
00637 - intent_code = NIFTI_INTENT_ESTIMATE; intent_name = "T1";
00638 could be used to signify that the voxel values are estimates of the
00639 NMR parameter T1.
00640 - intent_code = NIFTI_INTENT_TTEST; intent_name = "House";
00641 could be used to signify that the voxel values are t-statistics
00642 for the significance of 'activation' response to a House stimulus.
00643 - intent_code = NIFTI_INTENT_DISPVECT; intent_name = "ToMNI152";
00644 could be used to signify that the voxel values are a displacement
00645 vector that transforms each voxel (x,y,z) location to the
00646 corresponding location in the MNI152 standard brain.
00647 - intent_code = NIFTI_INTENT_SYMMATRIX; intent_name = "DTI";
00648 could be used to signify that the voxel values comprise a diffusion
00649 tensor image.
00650
00651 If no data name is implied or needed, intent_name[0] should be set to 0.
00652 -----------------------------------------------------------------------------*/
00653
00656 #define NIFTI_INTENT_NONE 0
00657
00658 /*-------- These codes are for probability distributions ---------------*/
00659 /* Most distributions have a number of parameters,
00660 below denoted by p1, p2, and p3, and stored in
00661 - intent_p1, intent_p2, intent_p3 if dataset doesn't have 5th dimension
00662 - image data array if dataset does have 5th dimension
00663
00664 Functions to compute with many of the distributions below can be found
00665 in the CDF library from U Texas.
00666
00667 Formulas for and discussions of these distributions can be found in the
00668 following books:
00669
00670 [U] Univariate Discrete Distributions,
00671 NL Johnson, S Kotz, AW Kemp.
00672
00673 [C1] Continuous Univariate Distributions, vol. 1,
00674 NL Johnson, S Kotz, N Balakrishnan.
00675
00676 [C2] Continuous Univariate Distributions, vol. 2,
00677 NL Johnson, S Kotz, N Balakrishnan. */
00678 /*----------------------------------------------------------------------*/
00679
00688 #define NIFTI_INTENT_CORREL 2
00689
00692 #define NIFTI_INTENT_TTEST 3
00693
00697 #define NIFTI_INTENT_FTEST 4
00698
00701 #define NIFTI_INTENT_ZSCORE 5
00702
00706 #define NIFTI_INTENT_CHISQ 6
00707
00711 #define NIFTI_INTENT_BETA 7
00712
00717 #define NIFTI_INTENT_BINOM 8
00718
00723 #define NIFTI_INTENT_GAMMA 9
00724
00728 #define NIFTI_INTENT_POISSON 10
00729
00733 #define NIFTI_INTENT_NORMAL 11
00734
00739 #define NIFTI_INTENT_FTEST_NONC 12
00740
00744 #define NIFTI_INTENT_CHISQ_NONC 13
00745
00750 #define NIFTI_INTENT_LOGISTIC 14
00751
00756 #define NIFTI_INTENT_LAPLACE 15
00757
00760 #define NIFTI_INTENT_UNIFORM 16
00761
00765 #define NIFTI_INTENT_TTEST_NONC 17
00766
00772 #define NIFTI_INTENT_WEIBULL 18
00773
00780 #define NIFTI_INTENT_CHI 19
00781
00787 #define NIFTI_INTENT_INVGAUSS 20
00788
00793 #define NIFTI_INTENT_EXTVAL 21
00794
00797 #define NIFTI_INTENT_PVAL 22
00798
00805 #define NIFTI_INTENT_LOGPVAL 23
00806
00812 #define NIFTI_INTENT_LOG10PVAL 24
00813
00816 #define NIFTI_FIRST_STATCODE 2
00817
00820 #define NIFTI_LAST_STATCODE 24
00821
00822 /*---------- these values for intent_code aren't for statistics ----------*/
00823
00828 #define NIFTI_INTENT_ESTIMATE 1001
00829
00834 #define NIFTI_INTENT_LABEL 1002
00835
00839 #define NIFTI_INTENT_NEURONAME 1003
00840
00853 #define NIFTI_INTENT_GENMATRIX 1004
00854
00866 #define NIFTI_INTENT_SYMMATRIX 1005
00867
00875 #define NIFTI_INTENT_DISPVECT 1006 /* specifically for displacements */
00876 #define NIFTI_INTENT_VECTOR 1007 /* for any other type of vector */
00877
00889 #define NIFTI_INTENT_POINTSET 1008
00890
00902 #define NIFTI_INTENT_TRIANGLE 1009
00903
00911 #define NIFTI_INTENT_QUATERNION 1010
00912
00916 #define NIFTI_INTENT_DIMLESS 1011
00917
00918 /*---------- these values apply to GIFTI datasets ----------*/
00919
00922 #define NIFTI_INTENT_TIME_SERIES 2001
00923
00927 #define NIFTI_INTENT_NODE_INDEX 2002
00928
00938 #define NIFTI_INTENT_RGB_VECTOR 2003
00939
00949 #define NIFTI_INTENT_RGBA_VECTOR 2004
00950
00954 #define NIFTI_INTENT_SHAPE 2005
00955
00956 /* @} */
00957
00958 /*---------------------------------------------------------------------------*/
00959 /* 3D IMAGE (VOLUME) ORIENTATION AND LOCATION IN SPACE:
00960 ---------------------------------------------------
00961 There are 3 different methods by which continuous coordinates can
00962 attached to voxels. The discussion below emphasizes 3D volumes, and
00963 the continuous coordinates are referred to as (x,y,z). The voxel
00964 index coordinates (i.e., the array indexes) are referred to as (i,j,k),
00965 with valid ranges:
00966 i = 0 .. dim[1]-1
00967 j = 0 .. dim[2]-1 (if dim[0] >= 2)
00968 k = 0 .. dim[3]-1 (if dim[0] >= 3)
00969 The (x,y,z) coordinates refer to the CENTER of a voxel. In methods
00970 2 and 3, the (x,y,z) axes refer to a subject-based coordinate system,
00971 with
00972 +x = Right +y = Anterior +z = Superior.
00973 This is a right-handed coordinate system. However, the exact direction
00974 these axes point with respect to the subject depends on qform_code
00975 (Method 2) and sform_code (Method 3).
00976
00977 N.B.: The i index varies most rapidly, j index next, k index slowest.
00978 Thus, voxel (i,j,k) is stored starting at location
00979 (i + j*dim[1] + k*dim[1]*dim[2]) * (bitpix/8)
00980 into the dataset array.
00981
00982 N.B.: The ANALYZE 7.5 coordinate system is
00983 +x = Left +y = Anterior +z = Superior
00984 which is a left-handed coordinate system. This backwardness is
00985 too difficult to tolerate, so this NIFTI-1 standard specifies the
00986 coordinate order which is most common in functional neuroimaging.
00987
00988 N.B.: The 3 methods below all give the locations of the voxel centers
00989 in the (x,y,z) coordinate system. In many cases, programs will wish
00990 to display image data on some other grid. In such a case, the program
00991 will need to convert its desired (x,y,z) values into (i,j,k) values
00992 in order to extract (or interpolate) the image data. This operation
00993 would be done with the inverse transformation to those described below.
00994
00995 N.B.: Method 2 uses a factor 'qfac' which is either -1 or 1; qfac is
00996 stored in the otherwise unused pixdim[0]. If pixdim[0]=0.0 (which
00997 should not occur), we take qfac=1. Of course, pixdim[0] is only used
00998 when reading a NIFTI-1 header, not when reading an ANALYZE 7.5 header.
00999
01000 N.B.: The units of (x,y,z) can be specified using the xyzt_units field.
01001
01002 METHOD 1 (the "old" way, used only when qform_code = 0):
01003 -------------------------------------------------------
01004 The coordinate mapping from (i,j,k) to (x,y,z) is the ANALYZE
01005 7.5 way. This is a simple scaling relationship:
01006
01007 x = pixdim[1] * i
01008 y = pixdim[2] * j
01009 z = pixdim[3] * k
01010
01011 No particular spatial orientation is attached to these (x,y,z)
01012 coordinates. (NIFTI-1 does not have the ANALYZE 7.5 orient field,
01013 which is not general and is often not set properly.) This method
01014 is not recommended, and is present mainly for compatibility with
01015 ANALYZE 7.5 files.
01016
01017 METHOD 2 (used when qform_code > 0, which should be the "normal" case):
01018 ---------------------------------------------------------------------
01019 The (x,y,z) coordinates are given by the pixdim[] scales, a rotation
01020 matrix, and a shift. This method is intended to represent
01021 "scanner-anatomical" coordinates, which are often embedded in the
01022 image header (e.g., DICOM fields (0020,0032), (0020,0037), (0028,0030),
01023 and (0018,0050)), and represent the nominal orientation and location of
01024 the data. This method can also be used to represent "aligned"
01025 coordinates, which would typically result from some post-acquisition
01026 alignment of the volume to a standard orientation (e.g., the same
01027 subject on another day, or a rigid rotation to true anatomical
01028 orientation from the tilted position of the subject in the scanner).
01029 The formula for (x,y,z) in terms of header parameters and (i,j,k) is:
01030
01031 [ x ] [ R11 R12 R13 ] [ pixdim[1] * i ] [ qoffset_x ]
01032 [ y ] = [ R21 R22 R23 ] [ pixdim[2] * j ] + [ qoffset_y ]
01033 [ z ] [ R31 R32 R33 ] [ qfac * pixdim[3] * k ] [ qoffset_z ]
01034
01035 The qoffset_* shifts are in the NIFTI-1 header. Note that the center
01036 of the (i,j,k)=(0,0,0) voxel (first value in the dataset array) is
01037 just (x,y,z)=(qoffset_x,qoffset_y,qoffset_z).
01038
01039 The rotation matrix R is calculated from the quatern_* parameters.
01040 This calculation is described below.
01041
01042 The scaling factor qfac is either 1 or -1. The rotation matrix R
01043 defined by the quaternion parameters is "proper" (has determinant 1).
01044 This may not fit the needs of the data; for example, if the image
01045 grid is
01046 i increases from Left-to-Right
01047 j increases from Anterior-to-Posterior
01048 k increases from Inferior-to-Superior
01049 Then (i,j,k) is a left-handed triple. In this example, if qfac=1,
01050 the R matrix would have to be
01051
01052 [ 1 0 0 ]
01053 [ 0 -1 0 ] which is "improper" (determinant = -1).
01054 [ 0 0 1 ]
01055
01056 If we set qfac=-1, then the R matrix would be
01057
01058 [ 1 0 0 ]
01059 [ 0 -1 0 ] which is proper.
01060 [ 0 0 -1 ]
01061
01062 This R matrix is represented by quaternion [a,b,c,d] = [0,1,0,0]
01063 (which encodes a 180 degree rotation about the x-axis).
01064
01065 METHOD 3 (used when sform_code > 0):
01066 -----------------------------------
01067 The (x,y,z) coordinates are given by a general affine transformation
01068 of the (i,j,k) indexes:
01069
01070 x = srow_x[0] * i + srow_x[1] * j + srow_x[2] * k + srow_x[3]
01071 y = srow_y[0] * i + srow_y[1] * j + srow_y[2] * k + srow_y[3]
01072 z = srow_z[0] * i + srow_z[1] * j + srow_z[2] * k + srow_z[3]
01073
01074 The srow_* vectors are in the NIFTI_1 header. Note that no use is
01075 made of pixdim[] in this method.
01076
01077 WHY 3 METHODS?
01078 --------------
01079 Method 1 is provided only for backwards compatibility. The intention
01080 is that Method 2 (qform_code > 0) represents the nominal voxel locations
01081 as reported by the scanner, or as rotated to some fiducial orientation and
01082 location. Method 3, if present (sform_code > 0), is to be used to give
01083 the location of the voxels in some standard space. The sform_code
01084 indicates which standard space is present. Both methods 2 and 3 can be
01085 present, and be useful in different contexts (method 2 for displaying the
01086 data on its original grid; method 3 for displaying it on a standard grid).
01087
01088 In this scheme, a dataset would originally be set up so that the
01089 Method 2 coordinates represent what the scanner reported. Later,
01090 a registration to some standard space can be computed and inserted
01091 in the header. Image display software can use either transform,
01092 depending on its purposes and needs.
01093
01094 In Method 2, the origin of coordinates would generally be whatever
01095 the scanner origin is; for example, in MRI, (0,0,0) is the center
01096 of the gradient coil.
01097
01098 In Method 3, the origin of coordinates would depend on the value
01099 of sform_code; for example, for the Talairach coordinate system,
01100 (0,0,0) corresponds to the Anterior Commissure.
01101
01102 QUATERNION REPRESENTATION OF ROTATION MATRIX (METHOD 2)
01103 -------------------------------------------------------
01104 The orientation of the (x,y,z) axes relative to the (i,j,k) axes
01105 in 3D space is specified using a unit quaternion [a,b,c,d], where
01106 a*a+b*b+c*c+d*d=1. The (b,c,d) values are all that is needed, since
01107 we require that a = sqrt(1.0-(b*b+c*c+d*d)) be nonnegative. The (b,c,d)
01108 values are stored in the (quatern_b,quatern_c,quatern_d) fields.
01109
01110 The quaternion representation is chosen for its compactness in
01111 representing rotations. The (proper) 3x3 rotation matrix that
01112 corresponds to [a,b,c,d] is
01113
01114 [ a*a+b*b-c*c-d*d 2*b*c-2*a*d 2*b*d+2*a*c ]
01115 R = [ 2*b*c+2*a*d a*a+c*c-b*b-d*d 2*c*d-2*a*b ]
01116 [ 2*b*d-2*a*c 2*c*d+2*a*b a*a+d*d-c*c-b*b ]
01117
01118 [ R11 R12 R13 ]
01119 = [ R21 R22 R23 ]
01120 [ R31 R32 R33 ]
01121
01122 If (p,q,r) is a unit 3-vector, then rotation of angle h about that
01123 direction is represented by the quaternion
01124
01125 [a,b,c,d] = [cos(h/2), p*sin(h/2), q*sin(h/2), r*sin(h/2)].
01126
01127 Requiring a >= 0 is equivalent to requiring -Pi <= h <= Pi. (Note that
01128 [-a,-b,-c,-d] represents the same rotation as [a,b,c,d]; there are 2
01129 quaternions that can be used to represent a given rotation matrix R.)
01130 To rotate a 3-vector (x,y,z) using quaternions, we compute the
01131 quaternion product
01132
01133 [0,x',y',z'] = [a,b,c,d] * [0,x,y,z] * [a,-b,-c,-d]
01134
01135 which is equivalent to the matrix-vector multiply
01136
01137 [ x' ] [ x ]
01138 [ y' ] = R [ y ] (equivalence depends on a*a+b*b+c*c+d*d=1)
01139 [ z' ] [ z ]
01140
01141 Multiplication of 2 quaternions is defined by the following:
01142
01143 [a,b,c,d] = a*1 + b*I + c*J + d*K
01144 where
01145 I*I = J*J = K*K = -1 (I,J,K are square roots of -1)
01146 I*J = K J*K = I K*I = J
01147 J*I = -K K*J = -I I*K = -J (not commutative!)
01148 For example
01149 [a,b,0,0] * [0,0,0,1] = [0,0,-b,a]
01150 since this expands to
01151 (a+b*I)*(K) = (a*K+b*I*K) = (a*K-b*J).
01152
01153 The above formula shows how to go from quaternion (b,c,d) to
01154 rotation matrix and direction cosines. Conversely, given R,
01155 we can compute the fields for the NIFTI-1 header by
01156
01157 a = 0.5 * sqrt(1+R11+R22+R33) (not stored)
01158 b = 0.25 * (R32-R23) / a => quatern_b
01159 c = 0.25 * (R13-R31) / a => quatern_c
01160 d = 0.25 * (R21-R12) / a => quatern_d
01161
01162 If a=0 (a 180 degree rotation), alternative formulas are needed.
01163 See the nifti1_io.c function mat44_to_quatern() for an implementation
01164 of the various cases in converting R to [a,b,c,d].
01165
01166 Note that R-transpose (= R-inverse) would lead to the quaternion
01167 [a,-b,-c,-d].
01168
01169 The choice to specify the qoffset_x (etc.) values in the final
01170 coordinate system is partly to make it easy to convert DICOM images to
01171 this format. The DICOM attribute "Image Position (Patient)" (0020,0032)
01172 stores the (Xd,Yd,Zd) coordinates of the center of the first voxel.
01173 Here, (Xd,Yd,Zd) refer to DICOM coordinates, and Xd=-x, Yd=-y, Zd=z,
01174 where (x,y,z) refers to the NIFTI coordinate system discussed above.
01175 (i.e., DICOM +Xd is Left, +Yd is Posterior, +Zd is Superior,
01176 whereas +x is Right, +y is Anterior , +z is Superior. )
01177 Thus, if the (0020,0032) DICOM attribute is extracted into (px,py,pz), then
01178 qoffset_x = -px qoffset_y = -py qoffset_z = pz
01179 is a reasonable setting when qform_code=NIFTI_XFORM_SCANNER_ANAT.
01180
01181 That is, DICOM's coordinate system is 180 degrees rotated about the z-axis
01182 from the neuroscience/NIFTI coordinate system. To transform between DICOM
01183 and NIFTI, you just have to negate the x- and y-coordinates.
01184
01185 The DICOM attribute (0020,0037) "Image Orientation (Patient)" gives the
01186 orientation of the x- and y-axes of the image data in terms of 2 3-vectors.
01187 The first vector is a unit vector along the x-axis, and the second is
01188 along the y-axis. If the (0020,0037) attribute is extracted into the
01189 value (xa,xb,xc,ya,yb,yc), then the first two columns of the R matrix
01190 would be
01191 [ -xa -ya ]
01192 [ -xb -yb ]
01193 [ xc yc ]
01194 The negations are because DICOM's x- and y-axes are reversed relative
01195 to NIFTI's. The third column of the R matrix gives the direction of
01196 displacement (relative to the subject) along the slice-wise direction.
01197 This orientation is not encoded in the DICOM standard in a simple way;
01198 DICOM is mostly concerned with 2D images. The third column of R will be
01199 either the cross-product of the first 2 columns or its negative. It is
01200 possible to infer the sign of the 3rd column by examining the coordinates
01201 in DICOM attribute (0020,0032) "Image Position (Patient)" for successive
01202 slices. However, this method occasionally fails for reasons that I
01203 (RW Cox) do not understand.
01204 -----------------------------------------------------------------------------*/
01205
01206 /* [qs]form_code value: */ /* x,y,z coordinate system refers to: */
01207 /*-----------------------*/ /*---------------------------------------*/
01208
01215 #define NIFTI_XFORM_UNKNOWN 0
01216
01219 #define NIFTI_XFORM_SCANNER_ANAT 1
01220
01224 #define NIFTI_XFORM_ALIGNED_ANAT 2
01225
01229 #define NIFTI_XFORM_TALAIRACH 3
01230
01233 #define NIFTI_XFORM_MNI_152 4
01234 /* @} */
01235
01236 /*---------------------------------------------------------------------------*/
01237 /* UNITS OF SPATIAL AND TEMPORAL DIMENSIONS:
01238 ----------------------------------------
01239 The codes below can be used in xyzt_units to indicate the units of pixdim.
01240 As noted earlier, dimensions 1,2,3 are for x,y,z; dimension 4 is for
01241 time (t).
01242 - If dim[4]=1 or dim[0] < 4, there is no time axis.
01243 - A single time series (no space) would be specified with
01244 - dim[0] = 4 (for scalar data) or dim[0] = 5 (for vector data)
01245 - dim[1] = dim[2] = dim[3] = 1
01246 - dim[4] = number of time points
01247 - pixdim[4] = time step
01248 - xyzt_units indicates units of pixdim[4]
01249 - dim[5] = number of values stored at each time point
01250
01251 Bits 0..2 of xyzt_units specify the units of pixdim[1..3]
01252 (e.g., spatial units are values 1..7).
01253 Bits 3..5 of xyzt_units specify the units of pixdim[4]
01254 (e.g., temporal units are multiples of 8).
01255
01256 This compression of 2 distinct concepts into 1 byte is due to the
01257 limited space available in the 348 byte ANALYZE 7.5 header. The
01258 macros XYZT_TO_SPACE and XYZT_TO_TIME can be used to mask off the
01259 undesired bits from the xyzt_units fields, leaving "pure" space
01260 and time codes. Inversely, the macro SPACE_TIME_TO_XYZT can be
01261 used to assemble a space code (0,1,2,...,7) with a time code
01262 (0,8,16,32,...,56) into the combined value for xyzt_units.
01263
01264 Note that codes are provided to indicate the "time" axis units are
01265 actually frequency in Hertz (_HZ), in part-per-million (_PPM)
01266 or in radians-per-second (_RADS).
01267
01268 The toffset field can be used to indicate a nonzero start point for
01269 the time axis. That is, time point #m is at t=toffset+m*pixdim[4]
01270 for m=0..dim[4]-1.
01271 -----------------------------------------------------------------------------*/
01272
01279 #define NIFTI_UNITS_UNKNOWN 0
01280
01283 #define NIFTI_UNITS_METER 1
01284
01285 #define NIFTI_UNITS_MM 2
01286
01287 #define NIFTI_UNITS_MICRON 3
01288
01291 #define NIFTI_UNITS_SEC 8
01292
01293 #define NIFTI_UNITS_MSEC 16
01294
01295 #define NIFTI_UNITS_USEC 24
01296
01297 /*** These units are for spectral data: ***/
01299 #define NIFTI_UNITS_HZ 32
01300
01301 #define NIFTI_UNITS_PPM 40
01302
01303 #define NIFTI_UNITS_RADS 48
01304 /* @} */
01305
01306 #undef XYZT_TO_SPACE
01307 #undef XYZT_TO_TIME
01308 #define XYZT_TO_SPACE(xyzt) ( (xyzt) & 0x07 )
01309 #define XYZT_TO_TIME(xyzt) ( (xyzt) & 0x38 )
01310
01311 #undef SPACE_TIME_TO_XYZT
01312 #define SPACE_TIME_TO_XYZT(ss,tt) ( (((char)(ss)) & 0x07) \
01313 | (((char)(tt)) & 0x38) )
01314
01315 /*---------------------------------------------------------------------------*/
01316 /* MRI-SPECIFIC SPATIAL AND TEMPORAL INFORMATION:
01317 ---------------------------------------------
01318 A few fields are provided to store some extra information
01319 that is sometimes important when storing the image data
01320 from an FMRI time series experiment. (After processing such
01321 data into statistical images, these fields are not likely
01322 to be useful.)
01323
01324 { freq_dim } = These fields encode which spatial dimension (1,2, or 3)
01325 { phase_dim } = corresponds to which acquisition dimension for MRI data.
01326 { slice_dim } =
01327 Examples:
01328 Rectangular scan multi-slice EPI:
01329 freq_dim = 1 phase_dim = 2 slice_dim = 3 (or some permutation)
01330 Spiral scan multi-slice EPI:
01331 freq_dim = phase_dim = 0 slice_dim = 3
01332 since the concepts of frequency- and phase-encoding directions
01333 don't apply to spiral scan
01334
01335 slice_duration = If this is positive, AND if slice_dim is nonzero,
01336 indicates the amount of time used to acquire 1 slice.
01337 slice_duration*dim[slice_dim] can be less than pixdim[4]
01338 with a clustered acquisition method, for example.
01339
01340 slice_code = If this is nonzero, AND if slice_dim is nonzero, AND
01341 if slice_duration is positive, indicates the timing
01342 pattern of the slice acquisition. The following codes
01343 are defined:
01344 NIFTI_SLICE_SEQ_INC == sequential increasing
01345 NIFTI_SLICE_SEQ_DEC == sequential decreasing
01346 NIFTI_SLICE_ALT_INC == alternating increasing
01347 NIFTI_SLICE_ALT_DEC == alternating decreasing
01348 NIFTI_SLICE_ALT_INC2 == alternating increasing #2
01349 NIFTI_SLICE_ALT_DEC2 == alternating decreasing #2
01350 { slice_start } = Indicates the start and end of the slice acquisition
01351 { slice_end } = pattern, when slice_code is nonzero. These values
01352 are present to allow for the possible addition of
01353 "padded" slices at either end of the volume, which
01354 don't fit into the slice timing pattern. If there
01355 are no padding slices, then slice_start=0 and
01356 slice_end=dim[slice_dim]-1 are the correct values.
01357 For these values to be meaningful, slice_start must
01358 be non-negative and slice_end must be greater than
01359 slice_start. Otherwise, they should be ignored.
01360
01361 The following table indicates the slice timing pattern, relative to
01362 time=0 for the first slice acquired, for some sample cases. Here,
01363 dim[slice_dim]=7 (there are 7 slices, labeled 0..6), slice_duration=0.1,
01364 and slice_start=1, slice_end=5 (1 padded slice on each end).
01365
01366 slice
01367 index SEQ_INC SEQ_DEC ALT_INC ALT_DEC ALT_INC2 ALT_DEC2
01368 6 : n/a n/a n/a n/a n/a n/a n/a = not applicable
01369 5 : 0.4 0.0 0.2 0.0 0.4 0.2 (slice time offset
01370 4 : 0.3 0.1 0.4 0.3 0.1 0.0 doesn't apply to
01371 3 : 0.2 0.2 0.1 0.1 0.3 0.3 slices outside
01372 2 : 0.1 0.3 0.3 0.4 0.0 0.1 the range
01373 1 : 0.0 0.4 0.0 0.2 0.2 0.4 slice_start ..
01374 0 : n/a n/a n/a n/a n/a n/a slice_end)
01375
01376 The SEQ slice_codes are sequential ordering (uncommon but not unknown),
01377 either increasing in slice number or decreasing (INC or DEC), as
01378 illustrated above.
01379
01380 The ALT slice codes are alternating ordering. The 'standard' way for
01381 these to operate (without the '2' on the end) is for the slice timing
01382 to start at the edge of the slice_start .. slice_end group (at slice_start
01383 for INC and at slice_end for DEC). For the 'ALT_*2' slice_codes, the
01384 slice timing instead starts at the first slice in from the edge (at
01385 slice_start+1 for INC2 and at slice_end-1 for DEC2). This latter
01386 acquisition scheme is found on some Siemens scanners.
01387
01388 The fields freq_dim, phase_dim, slice_dim are all squished into the single
01389 byte field dim_info (2 bits each, since the values for each field are
01390 limited to the range 0..3). This unpleasantness is due to lack of space
01391 in the 348 byte allowance.
01392
01393 The macros DIM_INFO_TO_FREQ_DIM, DIM_INFO_TO_PHASE_DIM, and
01394 DIM_INFO_TO_SLICE_DIM can be used to extract these values from the
01395 dim_info byte.
01396
01397 The macro FPS_INTO_DIM_INFO can be used to put these 3 values
01398 into the dim_info byte.
01399 -----------------------------------------------------------------------------*/
01400
01401 #undef DIM_INFO_TO_FREQ_DIM
01402 #undef DIM_INFO_TO_PHASE_DIM
01403 #undef DIM_INFO_TO_SLICE_DIM
01404
01405 #define DIM_INFO_TO_FREQ_DIM(di) ( ((di) ) & 0x03 )
01406 #define DIM_INFO_TO_PHASE_DIM(di) ( ((di) >> 2) & 0x03 )
01407 #define DIM_INFO_TO_SLICE_DIM(di) ( ((di) >> 4) & 0x03 )
01408
01409 #undef FPS_INTO_DIM_INFO
01410 #define FPS_INTO_DIM_INFO(fd,pd,sd) ( ( ( ((char)(fd)) & 0x03) ) | \
01411 ( ( ((char)(pd)) & 0x03) << 2 ) | \
01412 ( ( ((char)(sd)) & 0x03) << 4 ) )
01413
01419 #define NIFTI_SLICE_UNKNOWN 0
01420 #define NIFTI_SLICE_SEQ_INC 1
01421 #define NIFTI_SLICE_SEQ_DEC 2
01422 #define NIFTI_SLICE_ALT_INC 3
01423 #define NIFTI_SLICE_ALT_DEC 4
01424 #define NIFTI_SLICE_ALT_INC2 5 /* 05 May 2005: RWCox */
01425 #define NIFTI_SLICE_ALT_DEC2 6 /* 05 May 2005: RWCox */
01426 /* @} */
01427
01428 /*---------------------------------------------------------------------------*/
01429 /* UNUSED FIELDS:
01430 -------------
01431 Some of the ANALYZE 7.5 fields marked as ++UNUSED++ may need to be set
01432 to particular values for compatibility with other programs. The issue
01433 of interoperability of ANALYZE 7.5 files is a murky one -- not all
01434 programs require exactly the same set of fields. (Unobscuring this
01435 murkiness is a principal motivation behind NIFTI-1.)
01436
01437 Some of the fields that may need to be set for other (non-NIFTI aware)
01438 software to be happy are:
01439
01440 extents dbh.h says this should be 16384
01441 regular dbh.h says this should be the character 'r'
01442 glmin, } dbh.h says these values should be the min and max voxel
01443 glmax } values for the entire dataset
01444
01445 It is best to initialize ALL fields in the NIFTI-1 header to 0
01446 (e.g., with calloc()), then fill in what is needed.
01447 -----------------------------------------------------------------------------*/
01448
01449 /*---------------------------------------------------------------------------*/
01450 /* MISCELLANEOUS C MACROS
01451 -----------------------------------------------------------------------------*/
01452
01453 /*.................*/
01457 #define NIFTI_VERSION(h) \
01458 ( ( (h).magic[0]=='n' && (h).magic[3]=='\0' && \
01459 ( (h).magic[1]=='i' || (h).magic[1]=='+' ) && \
01460 ( (h).magic[2]>='1' && (h).magic[2]<='9' ) ) \
01461 ? (h).magic[2]-'0' : 0 )
01462
01463 /*.................*/
01468 #define NIFTI_ONEFILE(h) ( (h).magic[1] == '+' )
01469
01470 /*.................*/
01474 #define NIFTI_NEEDS_SWAP(h) ( (h).dim[0] < 0 || (h).dim[0] > 7 )
01475
01476 /*.................*/
01480 #define NIFTI_5TH_DIM(h) ( ((h).dim[0]>4 && (h).dim[5]>1) ? (h).dim[5] : 0 )
01481
01482 /*****************************************************************************/
01483
01484 /*=================*/
01485 #ifdef __cplusplus
01486 }
01487 #endif
01488 /*=================*/
01489
01490 #endif /* _NIFTI_HEADER_ */
1.2.4 written by Dimitri van Heesch,
© 1997-2000