nifti1.h 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528
  1. /** \file nifti1.h
  2. \brief Official definition of the nifti1 header. Written by Bob Cox, SSCC, NIMH.
  3. HISTORY:
  4. 29 Nov 2007 [rickr]
  5. - added DT_RGBA32 and NIFTI_TYPE_RGBA32
  6. - added NIFTI_INTENT codes:
  7. TIME_SERIES, NODE_INDEX, RGB_VECTOR, RGBA_VECTOR, SHAPE
  8. 08 Mar 2019 [PT,DRG]
  9. - Updated to include [qs]form_code = 5
  10. */
  11. #ifndef _NIFTI_HEADER_
  12. #define _NIFTI_HEADER_
  13. /*****************************************************************************
  14. ** This file defines the "NIFTI-1" header format. **
  15. ** It is derived from 2 meetings at the NIH (31 Mar 2003 and **
  16. ** 02 Sep 2003) of the Data Format Working Group (DFWG), **
  17. ** chartered by the NIfTI (Neuroimaging Informatics Technology **
  18. ** Initiative) at the National Institutes of Health (NIH). **
  19. **--------------------------------------------------------------**
  20. ** Neither the National Institutes of Health (NIH), the DFWG, **
  21. ** nor any of the members or employees of these institutions **
  22. ** imply any warranty of usefulness of this material for any **
  23. ** purpose, and do not assume any liability for damages, **
  24. ** incidental or otherwise, caused by any use of this document. **
  25. ** If these conditions are not acceptable, do not use this! **
  26. **--------------------------------------------------------------**
  27. ** Author: Robert W Cox (NIMH, Bethesda) **
  28. ** Advisors: John Ashburner (FIL, London), **
  29. ** Stephen Smith (FMRIB, Oxford), **
  30. ** Mark Jenkinson (FMRIB, Oxford) **
  31. ******************************************************************************/
  32. /*---------------------------------------------------------------------------*/
  33. /* Note that the ANALYZE 7.5 file header (dbh.h) is
  34. (c) Copyright 1986-1995
  35. Biomedical Imaging Resource
  36. Mayo Foundation
  37. Incorporation of components of dbh.h are by permission of the
  38. Mayo Foundation.
  39. Changes from the ANALYZE 7.5 file header in this file are released to the
  40. public domain, including the functional comments and any amusing asides.
  41. -----------------------------------------------------------------------------*/
  42. /*---------------------------------------------------------------------------*/
  43. /*! INTRODUCTION TO NIFTI-1:
  44. ------------------------
  45. The twin (and somewhat conflicting) goals of this modified ANALYZE 7.5
  46. format are:
  47. (a) To add information to the header that will be useful for functional
  48. neuroimaging data analysis and display. These additions include:
  49. - More basic data types.
  50. - Two affine transformations to specify voxel coordinates.
  51. - "Intent" codes and parameters to describe the meaning of the data.
  52. - Affine scaling of the stored data values to their "true" values.
  53. - Optional storage of the header and image data in one file (.nii).
  54. (b) To maintain compatibility with non-NIFTI-aware ANALYZE 7.5 compatible
  55. software (i.e., such a program should be able to do something useful
  56. with a NIFTI-1 dataset -- at least, with one stored in a traditional
  57. .img/.hdr file pair).
  58. Most of the unused fields in the ANALYZE 7.5 header have been taken,
  59. and some of the lesser-used fields have been co-opted for other purposes.
  60. Notably, most of the data_history substructure has been co-opted for
  61. other purposes, since the ANALYZE 7.5 format describes this substructure
  62. as "not required".
  63. NIFTI-1 FLAG (MAGIC STRINGS):
  64. ----------------------------
  65. To flag such a struct as being conformant to the NIFTI-1 spec, the last 4
  66. bytes of the header must be either the C String "ni1" or "n+1";
  67. in hexadecimal, the 4 bytes
  68. 6E 69 31 00 or 6E 2B 31 00
  69. (in any future version of this format, the '1' will be upgraded to '2',
  70. etc.). Normally, such a "magic number" or flag goes at the start of the
  71. file, but trying to avoid clobbering widely-used ANALYZE 7.5 fields led to
  72. putting this marker last. However, recall that "the last shall be first"
  73. (Matthew 20:16).
  74. If a NIFTI-aware program reads a header file that is NOT marked with a
  75. NIFTI magic string, then it should treat the header as an ANALYZE 7.5
  76. structure.
  77. NIFTI-1 FILE STORAGE:
  78. --------------------
  79. "ni1" means that the image data is stored in the ".img" file corresponding
  80. to the header file (starting at file offset 0).
  81. "n+1" means that the image data is stored in the same file as the header
  82. information. We recommend that the combined header+data filename suffix
  83. be ".nii". When the dataset is stored in one file, the first byte of image
  84. data is stored at byte location (int)vox_offset in this combined file.
  85. The minimum allowed value of vox_offset is 352; for compatibility with
  86. some software, vox_offset should be an integral multiple of 16.
  87. GRACE UNDER FIRE:
  88. ----------------
  89. Most NIFTI-aware programs will only be able to handle a subset of the full
  90. range of datasets possible with this format. All NIFTI-aware programs
  91. should take care to check if an input dataset conforms to the program's
  92. needs and expectations (e.g., check datatype, intent_code, etc.). If the
  93. input dataset can't be handled by the program, the program should fail
  94. gracefully (e.g., print a useful warning; not crash).
  95. SAMPLE CODES:
  96. ------------
  97. The associated files nifti1_io.h and nifti1_io.c provide a sample
  98. implementation in C of a set of functions to read, write, and manipulate
  99. NIFTI-1 files. The file nifti1_test.c is a sample program that uses
  100. the nifti1_io.c functions.
  101. -----------------------------------------------------------------------------*/
  102. /*---------------------------------------------------------------------------*/
  103. /* HEADER STRUCT DECLARATION:
  104. -------------------------
  105. In the comments below for each field, only NIFTI-1 specific requirements
  106. or changes from the ANALYZE 7.5 format are described. For convenience,
  107. the 348 byte header is described as a single struct, rather than as the
  108. ANALYZE 7.5 group of 3 substructs.
  109. Further comments about the interpretation of various elements of this
  110. header are after the data type definition itself. Fields that are
  111. marked as ++UNUSED++ have no particular interpretation in this standard.
  112. (Also see the UNUSED FIELDS comment section, far below.)
  113. The presumption below is that the various C types have particular sizes:
  114. sizeof(int) = sizeof(float) = 4 ; sizeof(short) = 2
  115. -----------------------------------------------------------------------------*/
  116. /*=================*/
  117. #ifdef __cplusplus
  118. extern "C" {
  119. #endif
  120. /*=================*/
  121. /*! \struct nifti_1_header
  122. \brief Data structure defining the fields in the nifti1 header.
  123. This binary header should be found at the beginning of a valid
  124. NIFTI-1 header file.
  125. */
  126. /*************************/ /************************/
  127. struct nifti_1_header { /* NIFTI-1 usage */ /* ANALYZE 7.5 field(s) */
  128. /*************************/ /************************/
  129. /*--- was header_key substruct ---*/
  130. int sizeof_hdr; /*!< MUST be 348 */ /* int sizeof_hdr; */
  131. char data_type[10]; /*!< ++UNUSED++ */ /* char data_type[10]; */
  132. char db_name[18]; /*!< ++UNUSED++ */ /* char db_name[18]; */
  133. int extents; /*!< ++UNUSED++ */ /* int extents; */
  134. short session_error; /*!< ++UNUSED++ */ /* short session_error; */
  135. char regular; /*!< ++UNUSED++ */ /* char regular; */
  136. char dim_info; /*!< MRI slice ordering. */ /* char hkey_un0; */
  137. /*--- was image_dimension substruct ---*/
  138. short dim[8]; /*!< Data array dimensions.*/ /* short dim[8]; */
  139. float intent_p1 ; /*!< 1st intent parameter. */ /* short unused8; */
  140. /* short unused9; */
  141. float intent_p2 ; /*!< 2nd intent parameter. */ /* short unused10; */
  142. /* short unused11; */
  143. float intent_p3 ; /*!< 3rd intent parameter. */ /* short unused12; */
  144. /* short unused13; */
  145. short intent_code ; /*!< NIFTI_INTENT_* code. */ /* short unused14; */
  146. short datatype; /*!< Defines data type! */ /* short datatype; */
  147. short bitpix; /*!< Number bits/voxel. */ /* short bitpix; */
  148. short slice_start; /*!< First slice index. */ /* short dim_un0; */
  149. float pixdim[8]; /*!< Grid spacings. */ /* float pixdim[8]; */
  150. float vox_offset; /*!< Offset into .nii file */ /* float vox_offset; */
  151. float scl_slope ; /*!< Data scaling: slope. */ /* float funused1; */
  152. float scl_inter ; /*!< Data scaling: offset. */ /* float funused2; */
  153. short slice_end; /*!< Last slice index. */ /* float funused3; */
  154. char slice_code ; /*!< Slice timing order. */
  155. char xyzt_units ; /*!< Units of pixdim[1..4] */
  156. float cal_max; /*!< Max display intensity */ /* float cal_max; */
  157. float cal_min; /*!< Min display intensity */ /* float cal_min; */
  158. float slice_duration;/*!< Time for 1 slice. */ /* float compressed; */
  159. float toffset; /*!< Time axis shift. */ /* float verified; */
  160. int glmax; /*!< ++UNUSED++ */ /* int glmax; */
  161. int glmin; /*!< ++UNUSED++ */ /* int glmin; */
  162. /*--- was data_history substruct ---*/
  163. char descrip[80]; /*!< any text you like. */ /* char descrip[80]; */
  164. char aux_file[24]; /*!< auxiliary filename. */ /* char aux_file[24]; */
  165. short qform_code ; /*!< NIFTI_XFORM_* code. */ /*-- all ANALYZE 7.5 ---*/
  166. short sform_code ; /*!< NIFTI_XFORM_* code. */ /* fields below here */
  167. /* are replaced */
  168. float quatern_b ; /*!< Quaternion b param. */
  169. float quatern_c ; /*!< Quaternion c param. */
  170. float quatern_d ; /*!< Quaternion d param. */
  171. float qoffset_x ; /*!< Quaternion x shift. */
  172. float qoffset_y ; /*!< Quaternion y shift. */
  173. float qoffset_z ; /*!< Quaternion z shift. */
  174. float srow_x[4] ; /*!< 1st row affine transform. */
  175. float srow_y[4] ; /*!< 2nd row affine transform. */
  176. float srow_z[4] ; /*!< 3rd row affine transform. */
  177. char intent_name[16];/*!< 'name' or meaning of data. */
  178. char magic[4] ; /*!< MUST be "ni1\0" or "n+1\0". */
  179. } ; /**** 348 bytes total ****/
  180. typedef struct nifti_1_header nifti_1_header ;
  181. /*---------------------------------------------------------------------------*/
  182. /* HEADER EXTENSIONS:
  183. -----------------
  184. After the end of the 348 byte header (e.g., after the magic field),
  185. the next 4 bytes are a char array field named "extension". By default,
  186. all 4 bytes of this array should be set to zero. In a .nii file, these
  187. 4 bytes will always be present, since the earliest start point for
  188. the image data is byte #352. In a separate .hdr file, these bytes may
  189. or may not be present. If not present (i.e., if the length of the .hdr
  190. file is 348 bytes), then a NIfTI-1 compliant program should use the
  191. default value of extension={0,0,0,0}. The first byte (extension[0])
  192. is the only value of this array that is specified at present. The other
  193. 3 bytes are reserved for future use.
  194. If extension[0] is nonzero, it indicates that extended header information
  195. is present in the bytes following the extension array. In a .nii file,
  196. this extended header data is before the image data (and vox_offset
  197. must be set correctly to allow for this). In a .hdr file, this extended
  198. data follows extension and proceeds (potentially) to the end of the file.
  199. The format of extended header data is weakly specified. Each extension
  200. must be an integer multiple of 16 bytes long. The first 8 bytes of each
  201. extension comprise 2 integers:
  202. int esize , ecode ;
  203. These values may need to be byte-swapped, as indicated by dim[0] for
  204. the rest of the header.
  205. * esize is the number of bytes that form the extended header data
  206. + esize must be a positive integral multiple of 16
  207. + this length includes the 8 bytes of esize and ecode themselves
  208. * ecode is a non-negative integer that indicates the format of the
  209. extended header data that follows
  210. + different ecode values are assigned to different developer groups
  211. + at present, the "registered" values for code are
  212. = 0 = unknown private format (not recommended!)
  213. = 2 = DICOM format (i.e., attribute tags and values)
  214. = 4 = AFNI group (i.e., ASCII XML-ish elements)
  215. In the interests of interoperability (a primary rationale for NIfTI),
  216. groups developing software that uses this extension mechanism are
  217. encouraged to document and publicize the format of their extensions.
  218. To this end, the NIfTI DFWG will assign even numbered codes upon request
  219. to groups submitting at least rudimentary documentation for the format
  220. of their extension; at present, the contact is mailto:rwcox@nih.gov.
  221. The assigned codes and documentation will be posted on the NIfTI
  222. website. All odd values of ecode (and 0) will remain unassigned;
  223. at least, until the even ones are used up, when we get to 2,147,483,646.
  224. Note that the other contents of the extended header data section are
  225. totally unspecified by the NIfTI-1 standard. In particular, if binary
  226. data is stored in such a section, its byte order is not necessarily
  227. the same as that given by examining dim[0]; it is incumbent on the
  228. programs dealing with such data to determine the byte order of binary
  229. extended header data.
  230. Multiple extended header sections are allowed, each starting with an
  231. esize,ecode value pair. The first esize value, as described above,
  232. is at bytes #352-355 in the .hdr or .nii file (files start at byte #0).
  233. If this value is positive, then the second (esize2) will be found
  234. starting at byte #352+esize1 , the third (esize3) at byte #352+esize1+esize2,
  235. et cetera. Of course, in a .nii file, the value of vox_offset must
  236. be compatible with these extensions. If a malformed file indicates
  237. that an extended header data section would run past vox_offset, then
  238. the entire extended header section should be ignored. In a .hdr file,
  239. if an extended header data section would run past the end-of-file,
  240. that extended header data should also be ignored.
  241. With the above scheme, a program can successively examine the esize
  242. and ecode values, and skip over each extended header section if the
  243. program doesn't know how to interpret the data within. Of course, any
  244. program can simply ignore all extended header sections simply by jumping
  245. straight to the image data using vox_offset.
  246. -----------------------------------------------------------------------------*/
  247. /*! \struct nifti1_extender
  248. \brief This structure represents a 4-byte string that should follow the
  249. binary nifti_1_header data in a NIFTI-1 header file. If the char
  250. values are {1,0,0,0}, the file is expected to contain extensions,
  251. values of {0,0,0,0} imply the file does not contain extensions.
  252. Other sequences of values are not currently defined.
  253. */
  254. struct nifti1_extender { char extension[4] ; } ;
  255. typedef struct nifti1_extender nifti1_extender ;
  256. /*! \struct nifti1_extension
  257. \brief Data structure defining the fields of a header extension.
  258. */
  259. struct nifti1_extension {
  260. int esize ; /*!< size of extension, in bytes (must be multiple of 16) */
  261. int ecode ; /*!< extension code, one of the NIFTI_ECODE_ values */
  262. char * edata ; /*!< raw data, with no byte swapping (length is esize-8) */
  263. } ;
  264. typedef struct nifti1_extension nifti1_extension ;
  265. /*---------------------------------------------------------------------------*/
  266. /* DATA DIMENSIONALITY (as in ANALYZE 7.5):
  267. ---------------------------------------
  268. dim[0] = number of dimensions;
  269. - if dim[0] is outside range 1..7, then the header information
  270. needs to be byte swapped appropriately
  271. - ANALYZE supports dim[0] up to 7, but NIFTI-1 reserves
  272. dimensions 1,2,3 for space (x,y,z), 4 for time (t), and
  273. 5,6,7 for anything else needed.
  274. dim[i] = length of dimension #i, for i=1..dim[0] (must be positive)
  275. - also see the discussion of intent_code, far below
  276. pixdim[i] = voxel width along dimension #i, i=1..dim[0] (positive)
  277. - cf. ORIENTATION section below for use of pixdim[0]
  278. - the units of pixdim can be specified with the xyzt_units
  279. field (also described far below).
  280. Number of bits per voxel value is in bitpix, which MUST correspond with
  281. the datatype field. The total number of bytes in the image data is
  282. dim[1] * ... * dim[dim[0]] * bitpix / 8
  283. In NIFTI-1 files, dimensions 1,2,3 are for space, dimension 4 is for time,
  284. and dimension 5 is for storing multiple values at each spatiotemporal
  285. voxel. Some examples:
  286. - A typical whole-brain FMRI experiment's time series:
  287. - dim[0] = 4
  288. - dim[1] = 64 pixdim[1] = 3.75 xyzt_units = NIFTI_UNITS_MM
  289. - dim[2] = 64 pixdim[2] = 3.75 | NIFTI_UNITS_SEC
  290. - dim[3] = 20 pixdim[3] = 5.0
  291. - dim[4] = 120 pixdim[4] = 2.0
  292. - A typical T1-weighted anatomical volume:
  293. - dim[0] = 3
  294. - dim[1] = 256 pixdim[1] = 1.0 xyzt_units = NIFTI_UNITS_MM
  295. - dim[2] = 256 pixdim[2] = 1.0
  296. - dim[3] = 128 pixdim[3] = 1.1
  297. - A single slice EPI time series:
  298. - dim[0] = 4
  299. - dim[1] = 64 pixdim[1] = 3.75 xyzt_units = NIFTI_UNITS_MM
  300. - dim[2] = 64 pixdim[2] = 3.75 | NIFTI_UNITS_SEC
  301. - dim[3] = 1 pixdim[3] = 5.0
  302. - dim[4] = 1200 pixdim[4] = 0.2
  303. - A 3-vector stored at each point in a 3D volume:
  304. - dim[0] = 5
  305. - dim[1] = 256 pixdim[1] = 1.0 xyzt_units = NIFTI_UNITS_MM
  306. - dim[2] = 256 pixdim[2] = 1.0
  307. - dim[3] = 128 pixdim[3] = 1.1
  308. - dim[4] = 1 pixdim[4] = 0.0
  309. - dim[5] = 3 intent_code = NIFTI_INTENT_VECTOR
  310. - A single time series with a 3x3 matrix at each point:
  311. - dim[0] = 5
  312. - dim[1] = 1 xyzt_units = NIFTI_UNITS_SEC
  313. - dim[2] = 1
  314. - dim[3] = 1
  315. - dim[4] = 1200 pixdim[4] = 0.2
  316. - dim[5] = 9 intent_code = NIFTI_INTENT_GENMATRIX
  317. - intent_p1 = intent_p2 = 3.0 (indicates matrix dimensions)
  318. -----------------------------------------------------------------------------*/
  319. /*---------------------------------------------------------------------------*/
  320. /* DATA STORAGE:
  321. ------------
  322. If the magic field is "n+1", then the voxel data is stored in the
  323. same file as the header. In this case, the voxel data starts at offset
  324. (int)vox_offset into the header file. Thus, vox_offset=352.0 means that
  325. the data starts immediately after the NIFTI-1 header. If vox_offset is
  326. greater than 352, the NIFTI-1 format does not say much about the
  327. contents of the dataset file between the end of the header and the
  328. start of the data.
  329. FILES:
  330. -----
  331. If the magic field is "ni1", then the voxel data is stored in the
  332. associated ".img" file, starting at offset 0 (i.e., vox_offset is not
  333. used in this case, and should be set to 0.0).
  334. When storing NIFTI-1 datasets in pairs of files, it is customary to name
  335. the files in the pattern "name.hdr" and "name.img", as in ANALYZE 7.5.
  336. When storing in a single file ("n+1"), the file name should be in
  337. the form "name.nii" (the ".nft" and ".nif" suffixes are already taken;
  338. cf. http://www.icdatamaster.com/n.html ).
  339. BYTE ORDERING:
  340. -------------
  341. The byte order of the data arrays is presumed to be the same as the byte
  342. order of the header (which is determined by examining dim[0]).
  343. Floating point types are presumed to be stored in IEEE-754 format.
  344. -----------------------------------------------------------------------------*/
  345. /*---------------------------------------------------------------------------*/
  346. /* DETAILS ABOUT vox_offset:
  347. ------------------------
  348. In a .nii file, the vox_offset field value is interpreted as the start
  349. location of the image data bytes in that file. In a .hdr/.img file pair,
  350. the vox_offset field value is the start location of the image data
  351. bytes in the .img file.
  352. * If vox_offset is less than 352 in a .nii file, it is equivalent
  353. to 352 (i.e., image data never starts before byte #352 in a .nii file).
  354. * The default value for vox_offset in a .nii file is 352.
  355. * In a .hdr file, the default value for vox_offset is 0.
  356. * vox_offset should be an integer multiple of 16; otherwise, some
  357. programs may not work properly (e.g., SPM). This is to allow
  358. memory-mapped input to be properly byte-aligned.
  359. Note that since vox_offset is an IEEE-754 32 bit float (for compatibility
  360. with the ANALYZE-7.5 format), it effectively has a 24 bit mantissa. All
  361. integers from 0 to 2^24 can be represented exactly in this format, but not
  362. all larger integers are exactly storable as IEEE-754 32 bit floats. However,
  363. unless you plan to have vox_offset be potentially larger than 16 MB, this
  364. should not be an issue. (Actually, any integral multiple of 16 up to 2^27
  365. can be represented exactly in this format, which allows for up to 128 MB
  366. of random information before the image data. If that isn't enough, then
  367. perhaps this format isn't right for you.)
  368. In a .img file (i.e., image data stored separately from the NIfTI-1
  369. header), data bytes between #0 and #vox_offset-1 (inclusive) are completely
  370. undefined and unregulated by the NIfTI-1 standard. One potential use of
  371. having vox_offset > 0 in the .hdr/.img file pair storage method is to make
  372. the .img file be a copy of (or link to) a pre-existing image file in some
  373. other format, such as DICOM; then vox_offset would be set to the offset of
  374. the image data in this file. (It may not be possible to follow the
  375. "multiple-of-16 rule" with an arbitrary external file; using the NIfTI-1
  376. format in such a case may lead to a file that is incompatible with software
  377. that relies on vox_offset being a multiple of 16.)
  378. In a .nii file, data bytes between #348 and #vox_offset-1 (inclusive) may
  379. be used to store user-defined extra information; similarly, in a .hdr file,
  380. any data bytes after byte #347 are available for user-defined extra
  381. information. The (very weak) regulation of this extra header data is
  382. described elsewhere.
  383. -----------------------------------------------------------------------------*/
  384. /*---------------------------------------------------------------------------*/
  385. /* DATA SCALING:
  386. ------------
  387. If the scl_slope field is nonzero, then each voxel value in the dataset
  388. should be scaled as
  389. y = scl_slope * x + scl_inter
  390. where x = voxel value stored
  391. y = "true" voxel value
  392. Normally, we would expect this scaling to be used to store "true" floating
  393. values in a smaller integer datatype, but that is not required. That is,
  394. it is legal to use scaling even if the datatype is a float type (crazy,
  395. perhaps, but legal).
  396. - However, the scaling is to be ignored if datatype is DT_RGB24.
  397. - If datatype is a complex type, then the scaling is to be
  398. applied to both the real and imaginary parts.
  399. The cal_min and cal_max fields (if nonzero) are used for mapping (possibly
  400. scaled) dataset values to display colors:
  401. - Minimum display intensity (black) corresponds to dataset value cal_min.
  402. - Maximum display intensity (white) corresponds to dataset value cal_max.
  403. - Dataset values below cal_min should display as black also, and values
  404. above cal_max as white.
  405. - Colors "black" and "white", of course, may refer to any scalar display
  406. scheme (e.g., a color lookup table specified via aux_file).
  407. - cal_min and cal_max only make sense when applied to scalar-valued
  408. datasets (i.e., dim[0] < 5 or dim[5] = 1).
  409. -----------------------------------------------------------------------------*/
  410. /*---------------------------------------------------------------------------*/
  411. /* TYPE OF DATA (acceptable values for datatype field):
  412. ---------------------------------------------------
  413. Values of datatype smaller than 256 are ANALYZE 7.5 compatible.
  414. Larger values are NIFTI-1 additions. These are all multiples of 256, so
  415. that no bits below position 8 are set in datatype. But there is no need
  416. to use only powers-of-2, as the original ANALYZE 7.5 datatype codes do.
  417. The additional codes are intended to include a complete list of basic
  418. scalar types, including signed and unsigned integers from 8 to 64 bits,
  419. floats from 32 to 128 bits, and complex (float pairs) from 64 to 256 bits.
  420. Note that most programs will support only a few of these datatypes!
  421. A NIFTI-1 program should fail gracefully (e.g., print a warning message)
  422. when it encounters a dataset with a type it doesn't like.
  423. -----------------------------------------------------------------------------*/
  424. #undef DT_UNKNOWN /* defined in dirent.h on some Unix systems */
  425. /*! \defgroup NIFTI1_DATATYPES
  426. \brief nifti1 datatype codes
  427. @{
  428. */
  429. /*--- the original ANALYZE 7.5 type codes ---*/
  430. #define DT_NONE 0
  431. #define DT_UNKNOWN 0 /* what it says, dude */
  432. #define DT_BINARY 1 /* binary (1 bit/voxel) */
  433. #define DT_UNSIGNED_CHAR 2 /* unsigned char (8 bits/voxel) */
  434. #define DT_SIGNED_SHORT 4 /* signed short (16 bits/voxel) */
  435. #define DT_SIGNED_INT 8 /* signed int (32 bits/voxel) */
  436. #define DT_FLOAT 16 /* float (32 bits/voxel) */
  437. #define DT_COMPLEX 32 /* complex (64 bits/voxel) */
  438. #define DT_DOUBLE 64 /* double (64 bits/voxel) */
  439. #define DT_RGB 128 /* RGB triple (24 bits/voxel) */
  440. #define DT_ALL 255 /* not very useful (?) */
  441. /*----- another set of names for the same ---*/
  442. #define DT_UINT8 2
  443. #define DT_INT16 4
  444. #define DT_INT32 8
  445. #define DT_FLOAT32 16
  446. #define DT_COMPLEX64 32
  447. #define DT_FLOAT64 64
  448. #define DT_RGB24 128
  449. /*------------------- new codes for NIFTI ---*/
  450. #define DT_INT8 256 /* signed char (8 bits) */
  451. #define DT_UINT16 512 /* unsigned short (16 bits) */
  452. #define DT_UINT32 768 /* unsigned int (32 bits) */
  453. #define DT_INT64 1024 /* long long (64 bits) */
  454. #define DT_UINT64 1280 /* unsigned long long (64 bits) */
  455. #define DT_FLOAT128 1536 /* long double (128 bits) */
  456. #define DT_COMPLEX128 1792 /* double pair (128 bits) */
  457. #define DT_COMPLEX256 2048 /* long double pair (256 bits) */
  458. #define DT_RGBA32 2304 /* 4 byte RGBA (32 bits/voxel) */
  459. /* @} */
  460. /*------- aliases for all the above codes ---*/
  461. /*! \defgroup NIFTI1_DATATYPE_ALIASES
  462. \brief aliases for the nifti1 datatype codes
  463. @{
  464. */
  465. /*! unsigned char. */
  466. #define NIFTI_TYPE_UINT8 2
  467. /*! signed short. */
  468. #define NIFTI_TYPE_INT16 4
  469. /*! signed int. */
  470. #define NIFTI_TYPE_INT32 8
  471. /*! 32 bit float. */
  472. #define NIFTI_TYPE_FLOAT32 16
  473. /*! 64 bit complex = 2 32 bit floats. */
  474. #define NIFTI_TYPE_COMPLEX64 32
  475. /*! 64 bit float = double. */
  476. #define NIFTI_TYPE_FLOAT64 64
  477. /*! 3 8 bit bytes. */
  478. #define NIFTI_TYPE_RGB24 128
  479. /*! signed char. */
  480. #define NIFTI_TYPE_INT8 256
  481. /*! unsigned short. */
  482. #define NIFTI_TYPE_UINT16 512
  483. /*! unsigned int. */
  484. #define NIFTI_TYPE_UINT32 768
  485. /*! signed long long. */
  486. #define NIFTI_TYPE_INT64 1024
  487. /*! unsigned long long. */
  488. #define NIFTI_TYPE_UINT64 1280
  489. /*! 128 bit float = long double. */
  490. #define NIFTI_TYPE_FLOAT128 1536
  491. /*! 128 bit complex = 2 64 bit floats. */
  492. #define NIFTI_TYPE_COMPLEX128 1792
  493. /*! 256 bit complex = 2 128 bit floats */
  494. #define NIFTI_TYPE_COMPLEX256 2048
  495. /*! 4 8 bit bytes. */
  496. #define NIFTI_TYPE_RGBA32 2304
  497. /* @} */
  498. /*-------- sample typedefs for complicated types ---*/
  499. #if 0
  500. typedef struct { float r,i; } complex_float ;
  501. typedef struct { double r,i; } complex_double ;
  502. typedef struct { long double r,i; } complex_longdouble ;
  503. typedef struct { unsigned char r,g,b; } rgb_byte ;
  504. #endif
  505. /*---------------------------------------------------------------------------*/
  506. /* INTERPRETATION OF VOXEL DATA:
  507. ----------------------------
  508. The intent_code field can be used to indicate that the voxel data has
  509. some particular meaning. In particular, a large number of codes is
  510. given to indicate that the the voxel data should be interpreted as
  511. being drawn from a given probability distribution.
  512. VECTOR-VALUED DATASETS:
  513. ----------------------
  514. The 5th dimension of the dataset, if present (i.e., dim[0]=5 and
  515. dim[5] > 1), contains multiple values (e.g., a vector) to be stored
  516. at each spatiotemporal location. For example, the header values
  517. - dim[0] = 5
  518. - dim[1] = 64
  519. - dim[2] = 64
  520. - dim[3] = 20
  521. - dim[4] = 1 (indicates no time axis)
  522. - dim[5] = 3
  523. - datatype = DT_FLOAT
  524. - intent_code = NIFTI_INTENT_VECTOR
  525. mean that this dataset should be interpreted as a 3D volume (64x64x20),
  526. with a 3-vector of floats defined at each point in the 3D grid.
  527. A program reading a dataset with a 5th dimension may want to reformat
  528. the image data to store each voxels' set of values together in a struct
  529. or array. This programming detail, however, is beyond the scope of the
  530. NIFTI-1 file specification! Uses of dimensions 6 and 7 are also not
  531. specified here.
  532. STATISTICAL PARAMETRIC DATASETS (i.e., SPMs):
  533. --------------------------------------------
  534. Values of intent_code from NIFTI_FIRST_STATCODE to NIFTI_LAST_STATCODE
  535. (inclusive) indicate that the numbers in the dataset should be interpreted
  536. as being drawn from a given distribution. Most such distributions have
  537. auxiliary parameters (e.g., NIFTI_INTENT_TTEST has 1 DOF parameter).
  538. If the dataset DOES NOT have a 5th dimension, then the auxiliary parameters
  539. are the same for each voxel, and are given in header fields intent_p1,
  540. intent_p2, and intent_p3.
  541. If the dataset DOES have a 5th dimension, then the auxiliary parameters
  542. are different for each voxel. For example, the header values
  543. - dim[0] = 5
  544. - dim[1] = 128
  545. - dim[2] = 128
  546. - dim[3] = 1 (indicates a single slice)
  547. - dim[4] = 1 (indicates no time axis)
  548. - dim[5] = 2
  549. - datatype = DT_FLOAT
  550. - intent_code = NIFTI_INTENT_TTEST
  551. mean that this is a 2D dataset (128x128) of t-statistics, with the
  552. t-statistic being in the first "plane" of data and the degrees-of-freedom
  553. parameter being in the second "plane" of data.
  554. If the dataset 5th dimension is used to store the voxel-wise statistical
  555. parameters, then dim[5] must be 1 plus the number of parameters required
  556. by that distribution (e.g., intent_code=NIFTI_INTENT_TTEST implies dim[5]
  557. must be 2, as in the example just above).
  558. Note: intent_code values 2..10 are compatible with AFNI 1.5x (which is
  559. why there is no code with value=1, which is obsolescent in AFNI).
  560. OTHER INTENTIONS:
  561. ----------------
  562. The purpose of the intent_* fields is to help interpret the values
  563. stored in the dataset. Some non-statistical values for intent_code
  564. and conventions are provided for storing other complex data types.
  565. The intent_name field provides space for a 15 character (plus 0 byte)
  566. 'name' string for the type of data stored. Examples:
  567. - intent_code = NIFTI_INTENT_ESTIMATE; intent_name = "T1";
  568. could be used to signify that the voxel values are estimates of the
  569. NMR parameter T1.
  570. - intent_code = NIFTI_INTENT_TTEST; intent_name = "House";
  571. could be used to signify that the voxel values are t-statistics
  572. for the significance of 'activation' response to a House stimulus.
  573. - intent_code = NIFTI_INTENT_DISPVECT; intent_name = "ToMNI152";
  574. could be used to signify that the voxel values are a displacement
  575. vector that transforms each voxel (x,y,z) location to the
  576. corresponding location in the MNI152 standard brain.
  577. - intent_code = NIFTI_INTENT_SYMMATRIX; intent_name = "DTI";
  578. could be used to signify that the voxel values comprise a diffusion
  579. tensor image.
  580. If no data name is implied or needed, intent_name[0] should be set to 0.
  581. -----------------------------------------------------------------------------*/
  582. /*! default: no intention is indicated in the header. */
  583. #define NIFTI_INTENT_NONE 0
  584. /*-------- These codes are for probability distributions ---------------*/
  585. /* Most distributions have a number of parameters,
  586. below denoted by p1, p2, and p3, and stored in
  587. - intent_p1, intent_p2, intent_p3 if dataset doesn't have 5th dimension
  588. - image data array if dataset does have 5th dimension
  589. Functions to compute with many of the distributions below can be found
  590. in the CDF library from U Texas.
  591. Formulas for and discussions of these distributions can be found in the
  592. following books:
  593. [U] Univariate Discrete Distributions,
  594. NL Johnson, S Kotz, AW Kemp.
  595. [C1] Continuous Univariate Distributions, vol. 1,
  596. NL Johnson, S Kotz, N Balakrishnan.
  597. [C2] Continuous Univariate Distributions, vol. 2,
  598. NL Johnson, S Kotz, N Balakrishnan. */
  599. /*----------------------------------------------------------------------*/
  600. /*! [C2, chap 32] Correlation coefficient R (1 param):
  601. p1 = degrees of freedom
  602. R/sqrt(1-R*R) is t-distributed with p1 DOF. */
  603. /*! \defgroup NIFTI1_INTENT_CODES
  604. \brief nifti1 intent codes, to describe intended meaning of dataset contents
  605. @{
  606. */
  607. #define NIFTI_INTENT_CORREL 2
  608. /*! [C2, chap 28] Student t statistic (1 param): p1 = DOF. */
  609. #define NIFTI_INTENT_TTEST 3
  610. /*! [C2, chap 27] Fisher F statistic (2 params):
  611. p1 = numerator DOF, p2 = denominator DOF. */
  612. #define NIFTI_INTENT_FTEST 4
  613. /*! [C1, chap 13] Standard normal (0 params): Density = N(0,1). */
  614. #define NIFTI_INTENT_ZSCORE 5
  615. /*! [C1, chap 18] Chi-squared (1 param): p1 = DOF.
  616. Density(x) proportional to exp(-x/2) * x^(p1/2-1). */
  617. #define NIFTI_INTENT_CHISQ 6
  618. /*! [C2, chap 25] Beta distribution (2 params): p1=a, p2=b.
  619. Density(x) proportional to x^(a-1) * (1-x)^(b-1). */
  620. #define NIFTI_INTENT_BETA 7
  621. /*! [U, chap 3] Binomial distribution (2 params):
  622. p1 = number of trials, p2 = probability per trial.
  623. Prob(x) = (p1 choose x) * p2^x * (1-p2)^(p1-x), for x=0,1,...,p1. */
  624. #define NIFTI_INTENT_BINOM 8
  625. /*! [C1, chap 17] Gamma distribution (2 params):
  626. p1 = shape, p2 = scale.
  627. Density(x) proportional to x^(p1-1) * exp(-p2*x). */
  628. #define NIFTI_INTENT_GAMMA 9
  629. /*! [U, chap 4] Poisson distribution (1 param): p1 = mean.
  630. Prob(x) = exp(-p1) * p1^x / x! , for x=0,1,2,.... */
  631. #define NIFTI_INTENT_POISSON 10
  632. /*! [C1, chap 13] Normal distribution (2 params):
  633. p1 = mean, p2 = standard deviation. */
  634. #define NIFTI_INTENT_NORMAL 11
  635. /*! [C2, chap 30] Noncentral F statistic (3 params):
  636. p1 = numerator DOF, p2 = denominator DOF,
  637. p3 = numerator noncentrality parameter. */
  638. #define NIFTI_INTENT_FTEST_NONC 12
  639. /*! [C2, chap 29] Noncentral chi-squared statistic (2 params):
  640. p1 = DOF, p2 = noncentrality parameter. */
  641. #define NIFTI_INTENT_CHISQ_NONC 13
  642. /*! [C2, chap 23] Logistic distribution (2 params):
  643. p1 = location, p2 = scale.
  644. Density(x) proportional to sech^2((x-p1)/(2*p2)). */
  645. #define NIFTI_INTENT_LOGISTIC 14
  646. /*! [C2, chap 24] Laplace distribution (2 params):
  647. p1 = location, p2 = scale.
  648. Density(x) proportional to exp(-abs(x-p1)/p2). */
  649. #define NIFTI_INTENT_LAPLACE 15
  650. /*! [C2, chap 26] Uniform distribution: p1 = lower end, p2 = upper end. */
  651. #define NIFTI_INTENT_UNIFORM 16
  652. /*! [C2, chap 31] Noncentral t statistic (2 params):
  653. p1 = DOF, p2 = noncentrality parameter. */
  654. #define NIFTI_INTENT_TTEST_NONC 17
  655. /*! [C1, chap 21] Weibull distribution (3 params):
  656. p1 = location, p2 = scale, p3 = power.
  657. Density(x) proportional to
  658. ((x-p1)/p2)^(p3-1) * exp(-((x-p1)/p2)^p3) for x > p1. */
  659. #define NIFTI_INTENT_WEIBULL 18
  660. /*! [C1, chap 18] Chi distribution (1 param): p1 = DOF.
  661. Density(x) proportional to x^(p1-1) * exp(-x^2/2) for x > 0.
  662. p1 = 1 = 'half normal' distribution
  663. p1 = 2 = Rayleigh distribution
  664. p1 = 3 = Maxwell-Boltzmann distribution. */
  665. #define NIFTI_INTENT_CHI 19
  666. /*! [C1, chap 15] Inverse Gaussian (2 params):
  667. p1 = mu, p2 = lambda
  668. Density(x) proportional to
  669. exp(-p2*(x-p1)^2/(2*p1^2*x)) / x^3 for x > 0. */
  670. #define NIFTI_INTENT_INVGAUSS 20
  671. /*! [C2, chap 22] Extreme value type I (2 params):
  672. p1 = location, p2 = scale
  673. cdf(x) = exp(-exp(-(x-p1)/p2)). */
  674. #define NIFTI_INTENT_EXTVAL 21
  675. /*! Data is a 'p-value' (no params). */
  676. #define NIFTI_INTENT_PVAL 22
  677. /*! Data is ln(p-value) (no params).
  678. To be safe, a program should compute p = exp(-abs(this_value)).
  679. The nifti_stats.c library returns this_value
  680. as positive, so that this_value = -log(p). */
  681. #define NIFTI_INTENT_LOGPVAL 23
  682. /*! Data is log10(p-value) (no params).
  683. To be safe, a program should compute p = pow(10.,-abs(this_value)).
  684. The nifti_stats.c library returns this_value
  685. as positive, so that this_value = -log10(p). */
  686. #define NIFTI_INTENT_LOG10PVAL 24
  687. /*! Smallest intent_code that indicates a statistic. */
  688. #define NIFTI_FIRST_STATCODE 2
  689. /*! Largest intent_code that indicates a statistic. */
  690. #define NIFTI_LAST_STATCODE 24
  691. /*---------- these values for intent_code aren't for statistics ----------*/
  692. /*! To signify that the value at each voxel is an estimate
  693. of some parameter, set intent_code = NIFTI_INTENT_ESTIMATE.
  694. The name of the parameter may be stored in intent_name. */
  695. #define NIFTI_INTENT_ESTIMATE 1001
  696. /*! To signify that the value at each voxel is an index into
  697. some set of labels, set intent_code = NIFTI_INTENT_LABEL.
  698. The filename with the labels may stored in aux_file. */
  699. #define NIFTI_INTENT_LABEL 1002
  700. /*! To signify that the value at each voxel is an index into the
  701. NeuroNames labels set, set intent_code = NIFTI_INTENT_NEURONAME. */
  702. #define NIFTI_INTENT_NEURONAME 1003
  703. /*! To store an M x N matrix at each voxel:
  704. - dataset must have a 5th dimension (dim[0]=5 and dim[5]>1)
  705. - intent_code must be NIFTI_INTENT_GENMATRIX
  706. - dim[5] must be M*N
  707. - intent_p1 must be M (in float format)
  708. - intent_p2 must be N (ditto)
  709. - the matrix values A[i][[j] are stored in row-order:
  710. - A[0][0] A[0][1] ... A[0][N-1]
  711. - A[1][0] A[1][1] ... A[1][N-1]
  712. - etc., until
  713. - A[M-1][0] A[M-1][1] ... A[M-1][N-1] */
  714. #define NIFTI_INTENT_GENMATRIX 1004
  715. /*! To store an NxN symmetric matrix at each voxel:
  716. - dataset must have a 5th dimension
  717. - intent_code must be NIFTI_INTENT_SYMMATRIX
  718. - dim[5] must be N*(N+1)/2
  719. - intent_p1 must be N (in float format)
  720. - the matrix values A[i][[j] are stored in row-order:
  721. - A[0][0]
  722. - A[1][0] A[1][1]
  723. - A[2][0] A[2][1] A[2][2]
  724. - etc.: row-by-row */
  725. #define NIFTI_INTENT_SYMMATRIX 1005
  726. /*! To signify that the vector value at each voxel is to be taken
  727. as a displacement field or vector:
  728. - dataset must have a 5th dimension
  729. - intent_code must be NIFTI_INTENT_DISPVECT
  730. - dim[5] must be the dimensionality of the displacment
  731. vector (e.g., 3 for spatial displacement, 2 for in-plane) */
  732. #define NIFTI_INTENT_DISPVECT 1006 /* specifically for displacements */
  733. #define NIFTI_INTENT_VECTOR 1007 /* for any other type of vector */
  734. /*! To signify that the vector value at each voxel is really a
  735. spatial coordinate (e.g., the vertices or nodes of a surface mesh):
  736. - dataset must have a 5th dimension
  737. - intent_code must be NIFTI_INTENT_POINTSET
  738. - dim[0] = 5
  739. - dim[1] = number of points
  740. - dim[2] = dim[3] = dim[4] = 1
  741. - dim[5] must be the dimensionality of space (e.g., 3 => 3D space).
  742. - intent_name may describe the object these points come from
  743. (e.g., "pial", "gray/white" , "EEG", "MEG"). */
  744. #define NIFTI_INTENT_POINTSET 1008
  745. /*! To signify that the vector value at each voxel is really a triple
  746. of indexes (e.g., forming a triangle) from a pointset dataset:
  747. - dataset must have a 5th dimension
  748. - intent_code must be NIFTI_INTENT_TRIANGLE
  749. - dim[0] = 5
  750. - dim[1] = number of triangles
  751. - dim[2] = dim[3] = dim[4] = 1
  752. - dim[5] = 3
  753. - datatype should be an integer type (preferably DT_INT32)
  754. - the data values are indexes (0,1,...) into a pointset dataset. */
  755. #define NIFTI_INTENT_TRIANGLE 1009
  756. /*! To signify that the vector value at each voxel is a quaternion:
  757. - dataset must have a 5th dimension
  758. - intent_code must be NIFTI_INTENT_QUATERNION
  759. - dim[0] = 5
  760. - dim[5] = 4
  761. - datatype should be a floating point type */
  762. #define NIFTI_INTENT_QUATERNION 1010
  763. /*! Dimensionless value - no params - although, as in _ESTIMATE
  764. the name of the parameter may be stored in intent_name. */
  765. #define NIFTI_INTENT_DIMLESS 1011
  766. /*---------- these values apply to GIFTI datasets ----------*/
  767. /*! To signify that the value at each location is from a time series. */
  768. #define NIFTI_INTENT_TIME_SERIES 2001
  769. /*! To signify that the value at each location is a node index, from
  770. a complete surface dataset. */
  771. #define NIFTI_INTENT_NODE_INDEX 2002
  772. /*! To signify that the vector value at each location is an RGB triplet,
  773. of whatever type.
  774. - dataset must have a 5th dimension
  775. - dim[0] = 5
  776. - dim[1] = number of nodes
  777. - dim[2] = dim[3] = dim[4] = 1
  778. - dim[5] = 3
  779. */
  780. #define NIFTI_INTENT_RGB_VECTOR 2003
  781. /*! To signify that the vector value at each location is a 4 valued RGBA
  782. vector, of whatever type.
  783. - dataset must have a 5th dimension
  784. - dim[0] = 5
  785. - dim[1] = number of nodes
  786. - dim[2] = dim[3] = dim[4] = 1
  787. - dim[5] = 4
  788. */
  789. #define NIFTI_INTENT_RGBA_VECTOR 2004
  790. /*! To signify that the value at each location is a shape value, such
  791. as the curvature. */
  792. #define NIFTI_INTENT_SHAPE 2005
  793. /*! The following intent codes have been used by FSL FNIRT for
  794. displacement/coefficient files.
  795. These codes are included to prevent clashes in community-created
  796. extensions to NIfTI. Encoding and decoding behavior for these
  797. intents is not specified by the standard, and support is OPTIONAL
  798. for conforming implementations.
  799. */
  800. #define NIFTI_INTENT_FSL_FNIRT_DISPLACEMENT_FIELD 2006
  801. #define NIFTI_INTENT_FSL_CUBIC_SPLINE_COEFFICIENTS 2007
  802. #define NIFTI_INTENT_FSL_DCT_COEFFICIENTS 2008
  803. #define NIFTI_INTENT_FSL_QUADRATIC_SPLINE_COEFFICIENTS 2009
  804. /*! The following intent codes have been used by FSL TOPUP for
  805. displacement/coefficient files.
  806. These codes are included to prevent clashes in community-created
  807. extensions to NIfTI. Encoding and decoding behavior for these
  808. intents is not specified by the standard, and support is OPTIONAL
  809. for conforming implementations.
  810. */
  811. #define NIFTI_INTENT_FSL_TOPUP_CUBIC_SPLINE_COEFFICIENTS 2016
  812. #define NIFTI_INTENT_FSL_TOPUP_QUADRATIC_SPLINE_COEFFICIENTS 2017
  813. #define NIFTI_INTENT_FSL_TOPUP_FIELD 2018
  814. /* @} */
  815. /*---------------------------------------------------------------------------*/
  816. /* 3D IMAGE (VOLUME) ORIENTATION AND LOCATION IN SPACE:
  817. ---------------------------------------------------
  818. There are 3 different methods by which continuous coordinates can
  819. attached to voxels. The discussion below emphasizes 3D volumes, and
  820. the continuous coordinates are referred to as (x,y,z). The voxel
  821. index coordinates (i.e., the array indexes) are referred to as (i,j,k),
  822. with valid ranges:
  823. i = 0 .. dim[1]-1
  824. j = 0 .. dim[2]-1 (if dim[0] >= 2)
  825. k = 0 .. dim[3]-1 (if dim[0] >= 3)
  826. The (x,y,z) coordinates refer to the CENTER of a voxel. In methods
  827. 2 and 3, the (x,y,z) axes refer to a subject-based coordinate system,
  828. with
  829. +x = Right +y = Anterior +z = Superior.
  830. This is a right-handed coordinate system. However, the exact direction
  831. these axes point with respect to the subject depends on qform_code
  832. (Method 2) and sform_code (Method 3).
  833. N.B.: The i index varies most rapidly, j index next, k index slowest.
  834. Thus, voxel (i,j,k) is stored starting at location
  835. (i + j*dim[1] + k*dim[1]*dim[2]) * (bitpix/8)
  836. into the dataset array.
  837. N.B.: The ANALYZE 7.5 coordinate system is
  838. +x = Left +y = Anterior +z = Superior
  839. which is a left-handed coordinate system. This backwardness is
  840. too difficult to tolerate, so this NIFTI-1 standard specifies the
  841. coordinate order which is most common in functional neuroimaging.
  842. N.B.: The 3 methods below all give the locations of the voxel centers
  843. in the (x,y,z) coordinate system. In many cases, programs will wish
  844. to display image data on some other grid. In such a case, the program
  845. will need to convert its desired (x,y,z) values into (i,j,k) values
  846. in order to extract (or interpolate) the image data. This operation
  847. would be done with the inverse transformation to those described below.
  848. N.B.: Method 2 uses a factor 'qfac' which is either -1 or 1; qfac is
  849. stored in the otherwise unused pixdim[0]. If pixdim[0]=0.0 (which
  850. should not occur), we take qfac=1. Of course, pixdim[0] is only used
  851. when reading a NIFTI-1 header, not when reading an ANALYZE 7.5 header.
  852. N.B.: The units of (x,y,z) can be specified using the xyzt_units field.
  853. METHOD 1 (the "old" way, used only when qform_code = 0):
  854. -------------------------------------------------------
  855. The coordinate mapping from (i,j,k) to (x,y,z) is the ANALYZE
  856. 7.5 way. This is a simple scaling relationship:
  857. x = pixdim[1] * i
  858. y = pixdim[2] * j
  859. z = pixdim[3] * k
  860. No particular spatial orientation is attached to these (x,y,z)
  861. coordinates. (NIFTI-1 does not have the ANALYZE 7.5 orient field,
  862. which is not general and is often not set properly.) This method
  863. is not recommended, and is present mainly for compatibility with
  864. ANALYZE 7.5 files.
  865. METHOD 2 (used when qform_code > 0, which should be the "normal" case):
  866. ---------------------------------------------------------------------
  867. The (x,y,z) coordinates are given by the pixdim[] scales, a rotation
  868. matrix, and a shift. This method is intended to represent
  869. "scanner-anatomical" coordinates, which are often embedded in the
  870. image header (e.g., DICOM fields (0020,0032), (0020,0037), (0028,0030),
  871. and (0018,0050)), and represent the nominal orientation and location of
  872. the data. This method can also be used to represent "aligned"
  873. coordinates, which would typically result from some post-acquisition
  874. alignment of the volume to a standard orientation (e.g., the same
  875. subject on another day, or a rigid rotation to true anatomical
  876. orientation from the tilted position of the subject in the scanner).
  877. The formula for (x,y,z) in terms of header parameters and (i,j,k) is:
  878. [ x ] [ R11 R12 R13 ] [ pixdim[1] * i ] [ qoffset_x ]
  879. [ y ] = [ R21 R22 R23 ] [ pixdim[2] * j ] + [ qoffset_y ]
  880. [ z ] [ R31 R32 R33 ] [ qfac * pixdim[3] * k ] [ qoffset_z ]
  881. The qoffset_* shifts are in the NIFTI-1 header. Note that the center
  882. of the (i,j,k)=(0,0,0) voxel (first value in the dataset array) is
  883. just (x,y,z)=(qoffset_x,qoffset_y,qoffset_z).
  884. The rotation matrix R is calculated from the quatern_* parameters.
  885. This calculation is described below.
  886. The scaling factor qfac is either 1 or -1. The rotation matrix R
  887. defined by the quaternion parameters is "proper" (has determinant 1).
  888. This may not fit the needs of the data; for example, if the image
  889. grid is
  890. i increases from Left-to-Right
  891. j increases from Anterior-to-Posterior
  892. k increases from Inferior-to-Superior
  893. Then (i,j,k) is a left-handed triple. In this example, if qfac=1,
  894. the R matrix would have to be
  895. [ 1 0 0 ]
  896. [ 0 -1 0 ] which is "improper" (determinant = -1).
  897. [ 0 0 1 ]
  898. If we set qfac=-1, then the R matrix would be
  899. [ 1 0 0 ]
  900. [ 0 -1 0 ] which is proper.
  901. [ 0 0 -1 ]
  902. This R matrix is represented by quaternion [a,b,c,d] = [0,1,0,0]
  903. (which encodes a 180 degree rotation about the x-axis).
  904. METHOD 3 (used when sform_code > 0):
  905. -----------------------------------
  906. The (x,y,z) coordinates are given by a general affine transformation
  907. of the (i,j,k) indexes:
  908. x = srow_x[0] * i + srow_x[1] * j + srow_x[2] * k + srow_x[3]
  909. y = srow_y[0] * i + srow_y[1] * j + srow_y[2] * k + srow_y[3]
  910. z = srow_z[0] * i + srow_z[1] * j + srow_z[2] * k + srow_z[3]
  911. The srow_* vectors are in the NIFTI_1 header. Note that no use is
  912. made of pixdim[] in this method.
  913. WHY 3 METHODS?
  914. --------------
  915. Method 1 is provided only for backwards compatibility. The intention
  916. is that Method 2 (qform_code > 0) represents the nominal voxel locations
  917. as reported by the scanner, or as rotated to some fiducial orientation and
  918. location. Method 3, if present (sform_code > 0), is to be used to give
  919. the location of the voxels in some standard space. The sform_code
  920. indicates which standard space is present. Both methods 2 and 3 can be
  921. present, and be useful in different contexts (method 2 for displaying the
  922. data on its original grid; method 3 for displaying it on a standard grid).
  923. In this scheme, a dataset would originally be set up so that the
  924. Method 2 coordinates represent what the scanner reported. Later,
  925. a registration to some standard space can be computed and inserted
  926. in the header. Image display software can use either transform,
  927. depending on its purposes and needs.
  928. In Method 2, the origin of coordinates would generally be whatever
  929. the scanner origin is; for example, in MRI, (0,0,0) is the center
  930. of the gradient coil.
  931. In Method 3, the origin of coordinates would depend on the value
  932. of sform_code; for example, for the Talairach coordinate system,
  933. (0,0,0) corresponds to the Anterior Commissure.
  934. QUATERNION REPRESENTATION OF ROTATION MATRIX (METHOD 2)
  935. -------------------------------------------------------
  936. The orientation of the (x,y,z) axes relative to the (i,j,k) axes
  937. in 3D space is specified using a unit quaternion [a,b,c,d], where
  938. a*a+b*b+c*c+d*d=1. The (b,c,d) values are all that is needed, since
  939. we require that a = sqrt(1.0-(b*b+c*c+d*d)) be nonnegative. The (b,c,d)
  940. values are stored in the (quatern_b,quatern_c,quatern_d) fields.
  941. The quaternion representation is chosen for its compactness in
  942. representing rotations. The (proper) 3x3 rotation matrix that
  943. corresponds to [a,b,c,d] is
  944. [ a*a+b*b-c*c-d*d 2*b*c-2*a*d 2*b*d+2*a*c ]
  945. R = [ 2*b*c+2*a*d a*a+c*c-b*b-d*d 2*c*d-2*a*b ]
  946. [ 2*b*d-2*a*c 2*c*d+2*a*b a*a+d*d-c*c-b*b ]
  947. [ R11 R12 R13 ]
  948. = [ R21 R22 R23 ]
  949. [ R31 R32 R33 ]
  950. If (p,q,r) is a unit 3-vector, then rotation of angle h about that
  951. direction is represented by the quaternion
  952. [a,b,c,d] = [cos(h/2), p*sin(h/2), q*sin(h/2), r*sin(h/2)].
  953. Requiring a >= 0 is equivalent to requiring -Pi <= h <= Pi. (Note that
  954. [-a,-b,-c,-d] represents the same rotation as [a,b,c,d]; there are 2
  955. quaternions that can be used to represent a given rotation matrix R.)
  956. To rotate a 3-vector (x,y,z) using quaternions, we compute the
  957. quaternion product
  958. [0,x',y',z'] = [a,b,c,d] * [0,x,y,z] * [a,-b,-c,-d]
  959. which is equivalent to the matrix-vector multiply
  960. [ x' ] [ x ]
  961. [ y' ] = R [ y ] (equivalence depends on a*a+b*b+c*c+d*d=1)
  962. [ z' ] [ z ]
  963. Multiplication of 2 quaternions is defined by the following:
  964. [a,b,c,d] = a*1 + b*I + c*J + d*K
  965. where
  966. I*I = J*J = K*K = -1 (I,J,K are square roots of -1)
  967. I*J = K J*K = I K*I = J
  968. J*I = -K K*J = -I I*K = -J (not commutative!)
  969. For example
  970. [a,b,0,0] * [0,0,0,1] = [0,0,-b,a]
  971. since this expands to
  972. (a+b*I)*(K) = (a*K+b*I*K) = (a*K-b*J).
  973. The above formula shows how to go from quaternion (b,c,d) to
  974. rotation matrix and direction cosines. Conversely, given R,
  975. we can compute the fields for the NIFTI-1 header by
  976. a = 0.5 * sqrt(1+R11+R22+R33) (not stored)
  977. b = 0.25 * (R32-R23) / a => quatern_b
  978. c = 0.25 * (R13-R31) / a => quatern_c
  979. d = 0.25 * (R21-R12) / a => quatern_d
  980. If a=0 (a 180 degree rotation), alternative formulas are needed.
  981. See the nifti1_io.c function mat44_to_quatern() for an implementation
  982. of the various cases in converting R to [a,b,c,d].
  983. Note that R-transpose (= R-inverse) would lead to the quaternion
  984. [a,-b,-c,-d].
  985. The choice to specify the qoffset_x (etc.) values in the final
  986. coordinate system is partly to make it easy to convert DICOM images to
  987. this format. The DICOM attribute "Image Position (Patient)" (0020,0032)
  988. stores the (Xd,Yd,Zd) coordinates of the center of the first voxel.
  989. Here, (Xd,Yd,Zd) refer to DICOM coordinates, and Xd=-x, Yd=-y, Zd=z,
  990. where (x,y,z) refers to the NIFTI coordinate system discussed above.
  991. (i.e., DICOM +Xd is Left, +Yd is Posterior, +Zd is Superior,
  992. whereas +x is Right, +y is Anterior , +z is Superior. )
  993. Thus, if the (0020,0032) DICOM attribute is extracted into (px,py,pz), then
  994. qoffset_x = -px qoffset_y = -py qoffset_z = pz
  995. is a reasonable setting when qform_code=NIFTI_XFORM_SCANNER_ANAT.
  996. That is, DICOM's coordinate system is 180 degrees rotated about the z-axis
  997. from the neuroscience/NIFTI coordinate system. To transform between DICOM
  998. and NIFTI, you just have to negate the x- and y-coordinates.
  999. The DICOM attribute (0020,0037) "Image Orientation (Patient)" gives the
  1000. orientation of the x- and y-axes of the image data in terms of 2 3-vectors.
  1001. The first vector is a unit vector along the x-axis, and the second is
  1002. along the y-axis. If the (0020,0037) attribute is extracted into the
  1003. value (xa,xb,xc,ya,yb,yc), then the first two columns of the R matrix
  1004. would be
  1005. [ -xa -ya ]
  1006. [ -xb -yb ]
  1007. [ xc yc ]
  1008. The negations are because DICOM's x- and y-axes are reversed relative
  1009. to NIFTI's. The third column of the R matrix gives the direction of
  1010. displacement (relative to the subject) along the slice-wise direction.
  1011. This orientation is not encoded in the DICOM standard in a simple way;
  1012. DICOM is mostly concerned with 2D images. The third column of R will be
  1013. either the cross-product of the first 2 columns or its negative. It is
  1014. possible to infer the sign of the 3rd column by examining the coordinates
  1015. in DICOM attribute (0020,0032) "Image Position (Patient)" for successive
  1016. slices. However, this method occasionally fails for reasons that I
  1017. (RW Cox) do not understand.
  1018. -----------------------------------------------------------------------------*/
  1019. /* [qs]form_code value: */ /* x,y,z coordinate system refers to: */
  1020. /*-----------------------*/ /*---------------------------------------*/
  1021. /*! \defgroup NIFTI1_XFORM_CODES
  1022. \brief nifti1 xform codes to describe the "standard" coordinate system
  1023. @{
  1024. */
  1025. /*! Arbitrary coordinates (Method 1). */
  1026. #define NIFTI_XFORM_UNKNOWN 0
  1027. /*! Scanner-based anatomical coordinates */
  1028. #define NIFTI_XFORM_SCANNER_ANAT 1
  1029. /*! Coordinates aligned to another file's,
  1030. or to anatomical "truth". */
  1031. #define NIFTI_XFORM_ALIGNED_ANAT 2
  1032. /*! Coordinates aligned to Talairach-
  1033. Tournoux Atlas; (0,0,0)=AC, etc. */
  1034. #define NIFTI_XFORM_TALAIRACH 3
  1035. /*! MNI 152 normalized coordinates. */
  1036. #define NIFTI_XFORM_MNI_152 4
  1037. /*! Normalized coordinates (for
  1038. any general standard template
  1039. space). Added March 8, 2019. */
  1040. #define NIFTI_XFORM_TEMPLATE_OTHER 5
  1041. /* @} */
  1042. /*---------------------------------------------------------------------------*/
  1043. /* UNITS OF SPATIAL AND TEMPORAL DIMENSIONS:
  1044. ----------------------------------------
  1045. The codes below can be used in xyzt_units to indicate the units of pixdim.
  1046. As noted earlier, dimensions 1,2,3 are for x,y,z; dimension 4 is for
  1047. time (t).
  1048. - If dim[4]=1 or dim[0] < 4, there is no time axis.
  1049. - A single time series (no space) would be specified with
  1050. - dim[0] = 4 (for scalar data) or dim[0] = 5 (for vector data)
  1051. - dim[1] = dim[2] = dim[3] = 1
  1052. - dim[4] = number of time points
  1053. - pixdim[4] = time step
  1054. - xyzt_units indicates units of pixdim[4]
  1055. - dim[5] = number of values stored at each time point
  1056. Bits 0..2 of xyzt_units specify the units of pixdim[1..3]
  1057. (e.g., spatial units are values 1..7).
  1058. Bits 3..5 of xyzt_units specify the units of pixdim[4]
  1059. (e.g., temporal units are multiples of 8).
  1060. This compression of 2 distinct concepts into 1 byte is due to the
  1061. limited space available in the 348 byte ANALYZE 7.5 header. The
  1062. macros XYZT_TO_SPACE and XYZT_TO_TIME can be used to mask off the
  1063. undesired bits from the xyzt_units fields, leaving "pure" space
  1064. and time codes. Inversely, the macro SPACE_TIME_TO_XYZT can be
  1065. used to assemble a space code (0,1,2,...,7) with a time code
  1066. (0,8,16,32,...,56) into the combined value for xyzt_units.
  1067. Note that codes are provided to indicate the "time" axis units are
  1068. actually frequency in Hertz (_HZ), in part-per-million (_PPM)
  1069. or in radians-per-second (_RADS).
  1070. The toffset field can be used to indicate a nonzero start point for
  1071. the time axis. That is, time point #m is at t=toffset+m*pixdim[4]
  1072. for m=0..dim[4]-1.
  1073. -----------------------------------------------------------------------------*/
  1074. /*! \defgroup NIFTI1_UNITS
  1075. \brief nifti1 units codes to describe the unit of measurement for
  1076. each dimension of the dataset
  1077. @{
  1078. */
  1079. /*! NIFTI code for unspecified units. */
  1080. #define NIFTI_UNITS_UNKNOWN 0
  1081. /** Space codes are multiples of 1. **/
  1082. /*! NIFTI code for meters. */
  1083. #define NIFTI_UNITS_METER 1
  1084. /*! NIFTI code for millimeters. */
  1085. #define NIFTI_UNITS_MM 2
  1086. /*! NIFTI code for micrometers. */
  1087. #define NIFTI_UNITS_MICRON 3
  1088. /** Time codes are multiples of 8. **/
  1089. /*! NIFTI code for seconds. */
  1090. #define NIFTI_UNITS_SEC 8
  1091. /*! NIFTI code for milliseconds. */
  1092. #define NIFTI_UNITS_MSEC 16
  1093. /*! NIFTI code for microseconds. */
  1094. #define NIFTI_UNITS_USEC 24
  1095. /*** These units are for spectral data: ***/
  1096. /*! NIFTI code for Hertz. */
  1097. #define NIFTI_UNITS_HZ 32
  1098. /*! NIFTI code for ppm. */
  1099. #define NIFTI_UNITS_PPM 40
  1100. /*! NIFTI code for radians per second. */
  1101. #define NIFTI_UNITS_RADS 48
  1102. /* @} */
  1103. #undef XYZT_TO_SPACE
  1104. #undef XYZT_TO_TIME
  1105. #define XYZT_TO_SPACE(xyzt) ( (xyzt) & 0x07 )
  1106. #define XYZT_TO_TIME(xyzt) ( (xyzt) & 0x38 )
  1107. #undef SPACE_TIME_TO_XYZT
  1108. #define SPACE_TIME_TO_XYZT(ss,tt) ( (((char)(ss)) & 0x07) \
  1109. | (((char)(tt)) & 0x38) )
  1110. /*---------------------------------------------------------------------------*/
  1111. /* MRI-SPECIFIC SPATIAL AND TEMPORAL INFORMATION:
  1112. ---------------------------------------------
  1113. A few fields are provided to store some extra information
  1114. that is sometimes important when storing the image data
  1115. from an FMRI time series experiment. (After processing such
  1116. data into statistical images, these fields are not likely
  1117. to be useful.)
  1118. { freq_dim } = These fields encode which spatial dimension (1,2, or 3)
  1119. { phase_dim } = corresponds to which acquisition dimension for MRI data.
  1120. { slice_dim } =
  1121. Examples:
  1122. Rectangular scan multi-slice EPI:
  1123. freq_dim = 1 phase_dim = 2 slice_dim = 3 (or some permutation)
  1124. Spiral scan multi-slice EPI:
  1125. freq_dim = phase_dim = 0 slice_dim = 3
  1126. since the concepts of frequency- and phase-encoding directions
  1127. don't apply to spiral scan
  1128. slice_duration = If this is positive, AND if slice_dim is nonzero,
  1129. indicates the amount of time used to acquire 1 slice.
  1130. slice_duration*dim[slice_dim] can be less than pixdim[4]
  1131. with a clustered acquisition method, for example.
  1132. slice_code = If this is nonzero, AND if slice_dim is nonzero, AND
  1133. if slice_duration is positive, indicates the timing
  1134. pattern of the slice acquisition. The following codes
  1135. are defined:
  1136. NIFTI_SLICE_SEQ_INC == sequential increasing
  1137. NIFTI_SLICE_SEQ_DEC == sequential decreasing
  1138. NIFTI_SLICE_ALT_INC == alternating increasing
  1139. NIFTI_SLICE_ALT_DEC == alternating decreasing
  1140. NIFTI_SLICE_ALT_INC2 == alternating increasing #2
  1141. NIFTI_SLICE_ALT_DEC2 == alternating decreasing #2
  1142. { slice_start } = Indicates the start and end of the slice acquisition
  1143. { slice_end } = pattern, when slice_code is nonzero. These values
  1144. are present to allow for the possible addition of
  1145. "padded" slices at either end of the volume, which
  1146. don't fit into the slice timing pattern. If there
  1147. are no padding slices, then slice_start=0 and
  1148. slice_end=dim[slice_dim]-1 are the correct values.
  1149. For these values to be meaningful, slice_start must
  1150. be non-negative and slice_end must be greater than
  1151. slice_start. Otherwise, they should be ignored.
  1152. The following table indicates the slice timing pattern, relative to
  1153. time=0 for the first slice acquired, for some sample cases. Here,
  1154. dim[slice_dim]=7 (there are 7 slices, labeled 0..6), slice_duration=0.1,
  1155. and slice_start=1, slice_end=5 (1 padded slice on each end).
  1156. slice
  1157. index SEQ_INC SEQ_DEC ALT_INC ALT_DEC ALT_INC2 ALT_DEC2
  1158. 6 : n/a n/a n/a n/a n/a n/a n/a = not applicable
  1159. 5 : 0.4 0.0 0.2 0.0 0.4 0.2 (slice time offset
  1160. 4 : 0.3 0.1 0.4 0.3 0.1 0.0 doesn't apply to
  1161. 3 : 0.2 0.2 0.1 0.1 0.3 0.3 slices outside
  1162. 2 : 0.1 0.3 0.3 0.4 0.0 0.1 the range
  1163. 1 : 0.0 0.4 0.0 0.2 0.2 0.4 slice_start ..
  1164. 0 : n/a n/a n/a n/a n/a n/a slice_end)
  1165. The SEQ slice_codes are sequential ordering (uncommon but not unknown),
  1166. either increasing in slice number or decreasing (INC or DEC), as
  1167. illustrated above.
  1168. The ALT slice codes are alternating ordering. The 'standard' way for
  1169. these to operate (without the '2' on the end) is for the slice timing
  1170. to start at the edge of the slice_start .. slice_end group (at slice_start
  1171. for INC and at slice_end for DEC). For the 'ALT_*2' slice_codes, the
  1172. slice timing instead starts at the first slice in from the edge (at
  1173. slice_start+1 for INC2 and at slice_end-1 for DEC2). This latter
  1174. acquisition scheme is found on some Siemens scanners.
  1175. The fields freq_dim, phase_dim, slice_dim are all squished into the single
  1176. byte field dim_info (2 bits each, since the values for each field are
  1177. limited to the range 0..3). This unpleasantness is due to lack of space
  1178. in the 348 byte allowance.
  1179. The macros DIM_INFO_TO_FREQ_DIM, DIM_INFO_TO_PHASE_DIM, and
  1180. DIM_INFO_TO_SLICE_DIM can be used to extract these values from the
  1181. dim_info byte.
  1182. The macro FPS_INTO_DIM_INFO can be used to put these 3 values
  1183. into the dim_info byte.
  1184. -----------------------------------------------------------------------------*/
  1185. #undef DIM_INFO_TO_FREQ_DIM
  1186. #undef DIM_INFO_TO_PHASE_DIM
  1187. #undef DIM_INFO_TO_SLICE_DIM
  1188. #define DIM_INFO_TO_FREQ_DIM(di) ( ((di) ) & 0x03 )
  1189. #define DIM_INFO_TO_PHASE_DIM(di) ( ((di) >> 2) & 0x03 )
  1190. #define DIM_INFO_TO_SLICE_DIM(di) ( ((di) >> 4) & 0x03 )
  1191. #undef FPS_INTO_DIM_INFO
  1192. #define FPS_INTO_DIM_INFO(fd,pd,sd) ( ( ( ((char)(fd)) & 0x03) ) | \
  1193. ( ( ((char)(pd)) & 0x03) << 2 ) | \
  1194. ( ( ((char)(sd)) & 0x03) << 4 ) )
  1195. /*! \defgroup NIFTI1_SLICE_ORDER
  1196. \brief nifti1 slice order codes, describing the acquisition order
  1197. of the slices
  1198. @{
  1199. */
  1200. #define NIFTI_SLICE_UNKNOWN 0
  1201. #define NIFTI_SLICE_SEQ_INC 1
  1202. #define NIFTI_SLICE_SEQ_DEC 2
  1203. #define NIFTI_SLICE_ALT_INC 3
  1204. #define NIFTI_SLICE_ALT_DEC 4
  1205. #define NIFTI_SLICE_ALT_INC2 5 /* 05 May 2005: RWCox */
  1206. #define NIFTI_SLICE_ALT_DEC2 6 /* 05 May 2005: RWCox */
  1207. /* @} */
  1208. /*---------------------------------------------------------------------------*/
  1209. /* UNUSED FIELDS:
  1210. -------------
  1211. Some of the ANALYZE 7.5 fields marked as ++UNUSED++ may need to be set
  1212. to particular values for compatibility with other programs. The issue
  1213. of interoperability of ANALYZE 7.5 files is a murky one -- not all
  1214. programs require exactly the same set of fields. (Unobscuring this
  1215. murkiness is a principal motivation behind NIFTI-1.)
  1216. Some of the fields that may need to be set for other (non-NIFTI aware)
  1217. software to be happy are:
  1218. extents dbh.h says this should be 16384
  1219. regular dbh.h says this should be the character 'r'
  1220. glmin, } dbh.h says these values should be the min and max voxel
  1221. glmax } values for the entire dataset
  1222. It is best to initialize ALL fields in the NIFTI-1 header to 0
  1223. (e.g., with calloc()), then fill in what is needed.
  1224. -----------------------------------------------------------------------------*/
  1225. /*---------------------------------------------------------------------------*/
  1226. /* MISCELLANEOUS C MACROS
  1227. -----------------------------------------------------------------------------*/
  1228. /*.................*/
  1229. /*! Given a nifti_1_header struct, check if it has a good magic number.
  1230. Returns NIFTI version number (1..9) if magic is good, 0 if it is not. */
  1231. #define NIFTI_VERSION(h) \
  1232. ( ( (h).magic[0]=='n' && (h).magic[3]=='\0' && \
  1233. ( (h).magic[1]=='i' || (h).magic[1]=='+' ) && \
  1234. ( (h).magic[2]>='1' && (h).magic[2]<='9' ) ) \
  1235. ? (h).magic[2]-'0' : 0 )
  1236. /*.................*/
  1237. /*! Check if a nifti_1_header struct says if the data is stored in the
  1238. same file or in a separate file. Returns 1 if the data is in the same
  1239. file as the header, 0 if it is not. */
  1240. #define NIFTI_ONEFILE(h) ( (h).magic[1] == '+' )
  1241. /*.................*/
  1242. /*! Check if a nifti_1_header struct needs to be byte swapped.
  1243. Returns 1 if it needs to be swapped, 0 if it does not. */
  1244. #define NIFTI_NEEDS_SWAP(h) ( (h).dim[0] < 0 || (h).dim[0] > 7 )
  1245. /*.................*/
  1246. /*! Check if a nifti_1_header struct contains a 5th (vector) dimension.
  1247. Returns size of 5th dimension if > 1, returns 0 otherwise. */
  1248. #define NIFTI_5TH_DIM(h) ( ((h).dim[0]>4 && (h).dim[5]>1) ? (h).dim[5] : 0 )
  1249. /*****************************************************************************/
  1250. /*=================*/
  1251. #ifdef __cplusplus
  1252. }
  1253. #endif
  1254. /*=================*/
  1255. #endif /* _NIFTI_HEADER_ */