NPL
Neurological Programs and Libraries
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
nifti.h
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright 2014 Micah C Chambers (micahc.vt@gmail.com)
3
*
4
* NPL is free software: you can redistribute it and/or modify it under the
5
* terms of the BSD 2-Clause License available in LICENSE or at
6
* http://opensource.org/licenses/BSD-2-Clause
7
*
8
* @file nifti.h
9
*
10
*****************************************************************************/
11
18
#ifndef NIFTI_H
19
#define NIFTI_H
20
21
typedef
struct
__attribute__
((packed))
22
{
23
int32_t sizeof_hdr;
// = 348
24
25
// unused
26
char
data_type[10];
27
char
db_name[18];
28
int32_t extents;
29
int16_t session_error;
30
char
regular;
31
32
union
{
33
char
byte;
34
struct
__attribute__
((packed)) {
35
unsigned
int
freqdim : 2;
36
unsigned
int
phasedim : 2;
37
unsigned
int
slicedim : 2;
38
unsigned
int
unused : 2;
39
} bits;
40
} dim_info;
41
42
int16_t ndim;
// number of dimensions
43
int16_t dim[7];
// size in each of ndim dimensions
44
45
// currently ignored
46
float
intent_p1;
47
float
intent_p2;
48
float
intent_p3;
49
int16_t intent_code;
50
51
int16_t datatype;
// pixel type
52
int16_t bitpix;
53
int16_t slice_start;
54
float
qfac;
// used for quaternions
55
float
pixdim[7];
// pixel spacing
56
float
vox_offset;
// where to start reading pixel data
57
58
float
scl_slope;
// y = scl_slope*x + scl_inter
59
float
scl_inter;
60
61
// currently ignored
62
int16_t slice_end;
63
char
slice_code;
64
char
xyzt_units;
65
float
cal_max;
66
float
cal_min;
67
float
slice_duration;
68
float
toffset;
69
int32_t glmax;
70
int32_t glmin;
71
char
descrip[80];
72
char
aux_file[24];
73
74
int16_t qform_code ;
75
int16_t sform_code ;
76
float
quatern[3];
//b,c,d
77
float
qoffset[3];
//x,y,z
78
float
saffine[12];
//row0 = x, row1 = y, row2 = z
79
char
intent_name[16];
80
char
magic[4];
81
}
nifti1_header
;
82
83
typedef
struct
__attribute__
((packed))
84
{
85
int32_t sizeof_hdr;
86
char
magic[8] ;
87
int16_t datatype;
88
int16_t bitpix;
89
int64_t ndim;
90
int64_t dim[7];
91
double
intent_p1 ;
92
double
intent_p2 ;
93
double
intent_p3 ;
94
double
qfac;
95
double
pixdim[7];
96
int64_t vox_offset;
97
double
scl_slope ;
98
double
scl_inter ;
99
double
cal_max;
100
double
cal_min;
101
double
slice_duration;
102
double
toffset;
103
int64_t slice_start;
104
int64_t slice_end;
105
char
descrip[80];
106
char
aux_file[24];
107
int32_t qform_code ;
108
int32_t sform_code ;
109
double
quatern[3];
110
double
qoffset[3];
111
double
saffine[12] ;
// row-major order
112
int32_t slice_code ;
113
int32_t xyzt_units ;
114
int32_t intent_code ;
115
char
intent_name[16];
116
union
{
117
char
byte;
118
struct
__attribute__
((packed)) {
119
unsigned
int
freqdim : 2;
120
unsigned
int
phasedim : 2;
121
unsigned
int
slicedim : 2;
122
unsigned
int
unused : 2;
123
} bits;
124
} dim_info;
125
char
unused_str[15];
126
}
nifti2_header
;
127
128
enum
NIFTI_TYPE
{
129
// covered by get/set int64
130
NIFTI_TYPE_UINT8
=2,
131
NIFTI_TYPE_INT8
=256,
132
NIFTI_TYPE_INT16
=4,
133
NIFTI_TYPE_INT32
=8,
134
NIFTI_TYPE_UINT16
=512,
135
NIFTI_TYPE_UINT32
=768,
136
NIFTI_TYPE_INT64
=1024,
137
NIFTI_TYPE_UINT64
=1280,
// overflowing an int64 is hard
138
139
// covered by get/set dbl
140
NIFTI_TYPE_FLOAT32
=16,
141
NIFTI_TYPE_FLOAT64
=64,
142
143
// covered by get/set cdbl
144
NIFTI_TYPE_COMPLEX64
=32,
145
NIFTI_TYPE_COMPLEX128
=1792,
146
147
// covered by get/set RGBA
148
NIFTI_TYPE_RGB24
=128,
149
NIFTI_TYPE_RGBA32
=2304,
150
151
// NOT SUPPORTED
152
// covered by get/set cquad
153
NIFTI_TYPE_COMPLEX256
=2048,
154
155
// covered by get/set quad
156
NIFTI_TYPE_FLOAT128
=1536
157
158
};
159
160
/*---------------------------------------------------------------------------*/
161
/* INTERPRETATION OF VOXEL DATA:
162
----------------------------
163
The intent_code field can be used to indicate that the voxel data has
164
some particular meaning. In particular, a large number of codes is
165
given to indicate that the the voxel data should be interpreted as
166
being drawn from a given probability distribution.
167
168
VECTOR-VALUED DATASETS:
169
----------------------
170
The 5th dimension of the dataset, if present (i.e., dim[0]=5 and
171
dim[5] > 1), contains multiple values (e.g., a vector) to be stored
172
at each spatiotemporal location. For example, the header values
173
- dim[0] = 5
174
- dim[1] = 64
175
- dim[2] = 64
176
- dim[3] = 20
177
- dim[4] = 1 (indicates no time axis)
178
- dim[5] = 3
179
- datatype = DT_FLOAT
180
- intent_code = NIFTI_INTENT_VECTOR
181
mean that this dataset should be interpreted as a 3D volume (64x64x20),
182
with a 3-vector of floats defined at each point in the 3D grid.
183
184
A program reading a dataset with a 5th dimension may want to reformat
185
the image data to store each voxels' set of values together in a struct
186
or array. This programming detail, however, is beyond the scope of the
187
NIFTI-1 file specification! Uses of dimensions 6 and 7 are also not
188
specified here.
189
190
STATISTICAL PARAMETRIC DATASETS (i.e., SPMs):
191
--------------------------------------------
192
Values of intent_code from NIFTI_FIRST_STATCODE to NIFTI_LAST_STATCODE
193
(inclusive) indicate that the numbers in the dataset should be interpreted
194
as being drawn from a given distribution. Most such distributions have
195
auxiliary parameters (e.g., NIFTI_INTENT_TTEST has 1 DOF parameter).
196
197
If the dataset DOES NOT have a 5th dimension, then the auxiliary parameters
198
are the same for each voxel, and are given in header fields intent_p1,
199
intent_p2, and intent_p3.
200
201
If the dataset DOES have a 5th dimension, then the auxiliary parameters
202
are different for each voxel. For example, the header values
203
- dim[0] = 5
204
- dim[1] = 128
205
- dim[2] = 128
206
- dim[3] = 1 (indicates a single slice)
207
- dim[4] = 1 (indicates no time axis)
208
- dim[5] = 2
209
- datatype = DT_FLOAT
210
- intent_code = NIFTI_INTENT_TTEST
211
mean that this is a 2D dataset (128x128) of t-statistics, with the
212
t-statistic being in the first "plane" of data and the degrees-of-freedom
213
parameter being in the second "plane" of data.
214
215
If the dataset 5th dimension is used to store the voxel-wise statistical
216
parameters, then dim[5] must be 1 plus the number of parameters required
217
by that distribution (e.g., intent_code=NIFTI_INTENT_TTEST implies dim[5]
218
must be 2, as in the example just above).
219
220
Note: intent_code values 2..10 are compatible with AFNI 1.5x (which is
221
why there is no code with value=1, which is obsolescent in AFNI).
222
223
OTHER INTENTIONS:
224
----------------
225
The purpose of the intent_* fields is to help interpret the values
226
stored in the dataset. Some non-statistical values for intent_code
227
and conventions are provided for storing other complex data types.
228
229
The intent_name field provides space for a 15 character (plus 0 byte)
230
'name' string for the type of data stored. Examples:
231
- intent_code = NIFTI_INTENT_ESTIMATE; intent_name = "T1";
232
could be used to signify that the voxel values are estimates of the
233
NMR parameter T1.
234
- intent_code = NIFTI_INTENT_TTEST; intent_name = "House";
235
could be used to signify that the voxel values are t-statistics
236
for the significance of 'activation' response to a House stimulus.
237
- intent_code = NIFTI_INTENT_DISPVECT; intent_name = "ToMNI152";
238
could be used to signify that the voxel values are a displacement
239
vector that transforms each voxel (x,y,z) location to the
240
corresponding location in the MNI152 standard brain.
241
- intent_code = NIFTI_INTENT_SYMMATRIX; intent_name = "DTI";
242
could be used to signify that the voxel values comprise a diffusion
243
tensor image.
244
245
If no data name is implied or needed, intent_name[0] should be set to 0.
246
-----------------------------------------------------------------------------*/
247
250
#define NIFTI_INTENT_NONE 0
251
252
/*-------- These codes are for probability distributions ---------------*/
253
/* Most distributions have a number of parameters,
254
below denoted by p1, p2, and p3, and stored in
255
- intent_p1, intent_p2, intent_p3 if dataset doesn't have 5th dimension
256
- image data array if dataset does have 5th dimension
257
258
Functions to compute with many of the distributions below can be found
259
in the CDF library from U Texas.
260
261
Formulas for and discussions of these distributions can be found in the
262
following books:
263
264
[U] Univariate Discrete Distributions,
265
NL Johnson, S Kotz, AW Kemp.
266
267
[C1] Continuous Univariate Distributions, vol. 1,
268
NL Johnson, S Kotz, N Balakrishnan.
269
270
[C2] Continuous Univariate Distributions, vol. 2,
271
NL Johnson, S Kotz, N Balakrishnan. */
272
/*----------------------------------------------------------------------*/
273
282
#define NIFTI_INTENT_CORREL 2
283
286
#define NIFTI_INTENT_TTEST 3
287
291
#define NIFTI_INTENT_FTEST 4
292
295
#define NIFTI_INTENT_ZSCORE 5
296
300
#define NIFTI_INTENT_CHISQ 6
301
305
#define NIFTI_INTENT_BETA 7
306
311
#define NIFTI_INTENT_BINOM 8
312
317
#define NIFTI_INTENT_GAMMA 9
318
322
#define NIFTI_INTENT_POISSON 10
323
327
#define NIFTI_INTENT_NORMAL 11
328
333
#define NIFTI_INTENT_FTEST_NONC 12
334
338
#define NIFTI_INTENT_CHISQ_NONC 13
339
344
#define NIFTI_INTENT_LOGISTIC 14
345
350
#define NIFTI_INTENT_LAPLACE 15
351
354
#define NIFTI_INTENT_UNIFORM 16
355
359
#define NIFTI_INTENT_TTEST_NONC 17
360
366
#define NIFTI_INTENT_WEIBULL 18
367
374
#define NIFTI_INTENT_CHI 19
375
381
#define NIFTI_INTENT_INVGAUSS 20
382
387
#define NIFTI_INTENT_EXTVAL 21
388
391
#define NIFTI_INTENT_PVAL 22
392
399
#define NIFTI_INTENT_LOGPVAL 23
400
406
#define NIFTI_INTENT_LOG10PVAL 24
407
410
#define NIFTI_FIRST_STATCODE 2
411
414
#define NIFTI_LAST_STATCODE 24
415
416
/*---------- these values for intent_code aren't for statistics ----------*/
417
422
#define NIFTI_INTENT_ESTIMATE 1001
423
428
#define NIFTI_INTENT_LABEL 1002
429
433
#define NIFTI_INTENT_NEURONAME 1003
434
447
#define NIFTI_INTENT_GENMATRIX 1004
448
460
#define NIFTI_INTENT_SYMMATRIX 1005
461
469
#define NIFTI_INTENT_DISPVECT 1006
/* specifically for displacements */
470
#define NIFTI_INTENT_VECTOR 1007
/* for any other type of vector */
471
483
#define NIFTI_INTENT_POINTSET 1008
484
496
#define NIFTI_INTENT_TRIANGLE 1009
497
505
#define NIFTI_INTENT_QUATERNION 1010
506
510
#define NIFTI_INTENT_DIMLESS 1011
511
512
/*---------- these values apply to GIFTI datasets ----------*/
513
516
#define NIFTI_INTENT_TIME_SERIES 2001
517
521
#define NIFTI_INTENT_NODE_INDEX 2002
522
532
#define NIFTI_INTENT_RGB_VECTOR 2003
533
543
#define NIFTI_INTENT_RGBA_VECTOR 2004
544
548
#define NIFTI_INTENT_SHAPE 2005
549
550
/* @} */
551
552
/*---------------------------------------------------------------------------*/
553
/* 3D IMAGE (VOLUME) ORIENTATION AND LOCATION IN SPACE:
554
---------------------------------------------------
555
There are 3 different methods by which continuous coordinates can
556
attached to voxels. The discussion below emphasizes 3D volumes, and
557
the continuous coordinates are referred to as (x,y,z). The voxel
558
index coordinates (i.e., the array indexes) are referred to as (i,j,k),
559
with valid ranges:
560
i = 0 .. dim[1]-1
561
j = 0 .. dim[2]-1 (if dim[0] >= 2)
562
k = 0 .. dim[3]-1 (if dim[0] >= 3)
563
The (x,y,z) coordinates refer to the CENTER of a voxel. In methods
564
2 and 3, the (x,y,z) axes refer to a subject-based coordinate system,
565
with
566
+x = Right +y = Anterior +z = Superior.
567
This is a right-handed coordinate system. However, the exact direction
568
these axes point with respect to the subject depends on qform_code
569
(Method 2) and sform_code (Method 3).
570
571
N.B.: The i index varies most rapidly, j index next, k index slowest.
572
Thus, voxel (i,j,k) is stored starting at location
573
(i + j*dim[1] + k*dim[1]*dim[2]) * (bitpix/8)
574
into the dataset array.
575
576
N.B.: The ANALYZE 7.5 coordinate system is
577
+x = Left +y = Anterior +z = Superior
578
which is a left-handed coordinate system. This backwardness is
579
too difficult to tolerate, so this NIFTI-1 standard specifies the
580
coordinate order which is most common in functional neuroimaging.
581
582
N.B.: The 3 methods below all give the locations of the voxel centers
583
in the (x,y,z) coordinate system. In many cases, programs will wish
584
to display image data on some other grid. In such a case, the program
585
will need to convert its desired (x,y,z) values into (i,j,k) values
586
in order to extract (or interpolate) the image data. This operation
587
would be done with the inverse transformation to those described below.
588
589
N.B.: Method 2 uses a factor 'qfac' which is either -1 or 1; qfac is
590
stored in the otherwise unused pixdim[0]. If pixdim[0]=0.0 (which
591
should not occur), we take qfac=1. Of course, pixdim[0] is only used
592
when reading a NIFTI-1 header, not when reading an ANALYZE 7.5 header.
593
594
N.B.: The units of (x,y,z) can be specified using the xyzt_units field.
595
596
METHOD 1 (the "old" way, used only when qform_code = 0):
597
-------------------------------------------------------
598
The coordinate mapping from (i,j,k) to (x,y,z) is the ANALYZE
599
7.5 way. This is a simple scaling relationship:
600
601
x = pixdim[1] * i
602
y = pixdim[2] * j
603
z = pixdim[3] * k
604
605
No particular spatial orientation is attached to these (x,y,z)
606
coordinates. (NIFTI-1 does not have the ANALYZE 7.5 orient field,
607
which is not general and is often not set properly.) This method
608
is not recommended, and is present mainly for compatibility with
609
ANALYZE 7.5 files.
610
611
METHOD 2 (used when qform_code > 0, which should be the "normal" case):
612
---------------------------------------------------------------------
613
The (x,y,z) coordinates are given by the pixdim[] scales, a rotation
614
matrix, and a shift. This method is intended to represent
615
"scanner-anatomical" coordinates, which are often embedded in the
616
image header (e.g., DICOM fields (0020,0032), (0020,0037), (0028,0030),
617
and (0018,0050)), and represent the nominal orientation and location of
618
the data. This method can also be used to represent "aligned"
619
coordinates, which would typically result from some post-acquisition
620
alignment of the volume to a standard orientation (e.g., the same
621
subject on another day, or a rigid rotation to true anatomical
622
orientation from the tilted position of the subject in the scanner).
623
The formula for (x,y,z) in terms of header parameters and (i,j,k) is:
624
625
[ x ] [ R11 R12 R13 ] [ pixdim[1] * i ] [ qoffset_x ]
626
[ y ] = [ R21 R22 R23 ] [ pixdim[2] * j ] + [ qoffset_y ]
627
[ z ] [ R31 R32 R33 ] [ qfac * pixdim[3] * k ] [ qoffset_z ]
628
629
The qoffset_* shifts are in the NIFTI-1 header. Note that the center
630
of the (i,j,k)=(0,0,0) voxel (first value in the dataset array) is
631
just (x,y,z)=(qoffset_x,qoffset_y,qoffset_z).
632
633
The rotation matrix R is calculated from the quatern_* parameters.
634
This calculation is described below.
635
636
The scaling factor qfac is either 1 or -1. The rotation matrix R
637
defined by the quaternion parameters is "proper" (has determinant 1).
638
This may not fit the needs of the data; for example, if the image
639
grid is
640
i increases from Left-to-Right
641
j increases from Anterior-to-Posterior
642
k increases from Inferior-to-Superior
643
Then (i,j,k) is a left-handed triple. In this example, if qfac=1,
644
the R matrix would have to be
645
646
[ 1 0 0 ]
647
[ 0 -1 0 ] which is "improper" (determinant = -1).
648
[ 0 0 1 ]
649
650
If we set qfac=-1, then the R matrix would be
651
652
[ 1 0 0 ]
653
[ 0 -1 0 ] which is proper.
654
[ 0 0 -1 ]
655
656
This R matrix is represented by quaternion [a,b,c,d] = [0,1,0,0]
657
(which encodes a 180 degree rotation about the x-axis).
658
659
METHOD 3 (used when sform_code > 0):
660
-----------------------------------
661
The (x,y,z) coordinates are given by a general affine transformation
662
of the (i,j,k) indexes:
663
664
x = srow_x[0] * i + srow_x[1] * j + srow_x[2] * k + srow_x[3]
665
y = srow_y[0] * i + srow_y[1] * j + srow_y[2] * k + srow_y[3]
666
z = srow_z[0] * i + srow_z[1] * j + srow_z[2] * k + srow_z[3]
667
668
The srow_* vectors are in the NIFTI_1 header. Note that no use is
669
made of pixdim[] in this method.
670
671
WHY 3 METHODS?
672
--------------
673
Method 1 is provided only for backwards compatibility. The intention
674
is that Method 2 (qform_code > 0) represents the nominal voxel locations
675
as reported by the scanner, or as rotated to some fiducial orientation and
676
location. Method 3, if present (sform_code > 0), is to be used to give
677
the location of the voxels in some standard space. The sform_code
678
indicates which standard space is present. Both methods 2 and 3 can be
679
present, and be useful in different contexts (method 2 for displaying the
680
data on its original grid; method 3 for displaying it on a standard grid).
681
682
In this scheme, a dataset would originally be set up so that the
683
Method 2 coordinates represent what the scanner reported. Later,
684
a registration to some standard space can be computed and inserted
685
in the header. Image display software can use either transform,
686
depending on its purposes and needs.
687
688
In Method 2, the origin of coordinates would generally be whatever
689
the scanner origin is; for example, in MRI, (0,0,0) is the center
690
of the gradient coil.
691
692
In Method 3, the origin of coordinates would depend on the value
693
of sform_code; for example, for the Talairach coordinate system,
694
(0,0,0) corresponds to the Anterior Commissure.
695
696
QUATERNION REPRESENTATION OF ROTATION MATRIX (METHOD 2)
697
-------------------------------------------------------
698
The orientation of the (x,y,z) axes relative to the (i,j,k) axes
699
in 3D space is specified using a unit quaternion [a,b,c,d], where
700
a*a+b*b+c*c+d*d=1. The (b,c,d) values are all that is needed, since
701
we require that a = sqrt(1.0-(b*b+c*c+d*d)) be nonnegative. The (b,c,d)
702
values are stored in the (quatern_b,quatern_c,quatern_d) fields.
703
704
The quaternion representation is chosen for its compactness in
705
representing rotations. The (proper) 3x3 rotation matrix that
706
corresponds to [a,b,c,d] is
707
708
[ a*a+b*b-c*c-d*d 2*b*c-2*a*d 2*b*d+2*a*c ]
709
R = [ 2*b*c+2*a*d a*a+c*c-b*b-d*d 2*c*d-2*a*b ]
710
[ 2*b*d-2*a*c 2*c*d+2*a*b a*a+d*d-c*c-b*b ]
711
712
[ R11 R12 R13 ]
713
= [ R21 R22 R23 ]
714
[ R31 R32 R33 ]
715
716
If (p,q,r) is a unit 3-vector, then rotation of angle h about that
717
direction is represented by the quaternion
718
719
[a,b,c,d] = [cos(h/2), p*sin(h/2), q*sin(h/2), r*sin(h/2)].
720
721
Requiring a >= 0 is equivalent to requiring -Pi <= h <= Pi. (Note that
722
[-a,-b,-c,-d] represents the same rotation as [a,b,c,d]; there are 2
723
quaternions that can be used to represent a given rotation matrix R.)
724
To rotate a 3-vector (x,y,z) using quaternions, we compute the
725
quaternion product
726
727
[0,x',y',z'] = [a,b,c,d] * [0,x,y,z] * [a,-b,-c,-d]
728
729
which is equivalent to the matrix-vector multiply
730
731
[ x' ] [ x ]
732
[ y' ] = R [ y ] (equivalence depends on a*a+b*b+c*c+d*d=1)
733
[ z' ] [ z ]
734
735
Multiplication of 2 quaternions is defined by the following:
736
737
[a,b,c,d] = a*1 + b*I + c*J + d*K
738
where
739
I*I = J*J = K*K = -1 (I,J,K are square roots of -1)
740
I*J = K J*K = I K*I = J
741
J*I = -K K*J = -I I*K = -J (not commutative!)
742
For example
743
[a,b,0,0] * [0,0,0,1] = [0,0,-b,a]
744
since this expands to
745
(a+b*I)*(K) = (a*K+b*I*K) = (a*K-b*J).
746
747
The above formula shows how to go from quaternion (b,c,d) to
748
rotation matrix and direction cosines. Conversely, given R,
749
we can compute the fields for the NIFTI-1 header by
750
751
a = 0.5 * sqrt(1+R11+R22+R33) (not stored)
752
b = 0.25 * (R32-R23) / a => quatern_b
753
c = 0.25 * (R13-R31) / a => quatern_c
754
d = 0.25 * (R21-R12) / a => quatern_d
755
756
If a=0 (a 180 degree rotation), alternative formulas are needed.
757
See the nifti1_io.c function mat44_to_quatern() for an implementation
758
of the various cases in converting R to [a,b,c,d].
759
760
Note that R-transpose (= R-inverse) would lead to the quaternion
761
[a,-b,-c,-d].
762
763
The choice to specify the qoffset_x (etc.) values in the final
764
coordinate system is partly to make it easy to convert DICOM images to
765
this format. The DICOM attribute "Image Position (Patient)" (0020,0032)
766
stores the (Xd,Yd,Zd) coordinates of the center of the first voxel.
767
Here, (Xd,Yd,Zd) refer to DICOM coordinates, and Xd=-x, Yd=-y, Zd=z,
768
where (x,y,z) refers to the NIFTI coordinate system discussed above.
769
(i.e., DICOM +Xd is Left, +Yd is Posterior, +Zd is Superior,
770
whereas +x is Right, +y is Anterior , +z is Superior. )
771
Thus, if the (0020,0032) DICOM attribute is extracted into (px,py,pz), then
772
qoffset_x = -px qoffset_y = -py qoffset_z = pz
773
is a reasonable setting when qform_code=NIFTI_XFORM_SCANNER_ANAT.
774
775
That is, DICOM's coordinate system is 180 degrees rotated about the z-axis
776
from the neuroscience/NIFTI coordinate system. To transform between DICOM
777
and NIFTI, you just have to negate the x- and y-coordinates.
778
779
The DICOM attribute (0020,0037) "Image Orientation (Patient)" gives the
780
orientation of the x- and y-axes of the image data in terms of 2 3-vectors.
781
The first vector is a unit vector along the x-axis, and the second is
782
along the y-axis. If the (0020,0037) attribute is extracted into the
783
value (xa,xb,xc,ya,yb,yc), then the first two columns of the R matrix
784
would be
785
[ -xa -ya ]
786
[ -xb -yb ]
787
[ xc yc ]
788
The negations are because DICOM's x- and y-axes are reversed relative
789
to NIFTI's. The third column of the R matrix gives the direction of
790
displacement (relative to the subject) along the slice-wise direction.
791
This orientation is not encoded in the DICOM standard in a simple way;
792
DICOM is mostly concerned with 2D images. The third column of R will be
793
either the cross-product of the first 2 columns or its negative. It is
794
possible to infer the sign of the 3rd column by examining the coordinates
795
in DICOM attribute (0020,0032) "Image Position (Patient)" for successive
796
slices. However, this method occasionally fails for reasons that I
797
(RW Cox) do not understand.
798
-----------------------------------------------------------------------------*/
799
800
/* [qs]form_code value: */
/* x,y,z coordinate system refers to: */
801
/*-----------------------*/
/*---------------------------------------*/
802
808
#define NIFTI_XFORM_UNKNOWN 0
809
#define NIFTI_XFORM_SCANNER_ANAT 1
810
#define NIFTI_XFORM_ALIGNED_ANAT 2
811
#define NIFTI_XFORM_TALAIRACH 3
812
#define NIFTI_XFORM_MNI_152 4
813
/* @} */
814
815
/*---------------------------------------------------------------------------*/
816
/* UNITS OF SPATIAL AND TEMPORAL DIMENSIONS:
817
----------------------------------------
818
The codes below can be used in xyzt_units to indicate the units of pixdim.
819
As noted earlier, dimensions 1,2,3 are for x,y,z; dimension 4 is for
820
time (t).
821
- If dim[4]=1 or dim[0] < 4, there is no time axis.
822
- A single time series (no space) would be specified with
823
- dim[0] = 4 (for scalar data) or dim[0] = 5 (for vector data)
824
- dim[1] = dim[2] = dim[3] = 1
825
- dim[4] = number of time points
826
- pixdim[4] = time step
827
- xyzt_units indicates units of pixdim[4]
828
- dim[5] = number of values stored at each time point
829
830
Bits 0..2 of xyzt_units specify the units of pixdim[1..3]
831
(e.g., spatial units are values 1..7).
832
Bits 3..5 of xyzt_units specify the units of pixdim[4]
833
(e.g., temporal units are multiples of 8).
834
835
This compression of 2 distinct concepts into 1 byte is due to the
836
limited space available in the 348 byte ANALYZE 7.5 header. The
837
macros XYZT_TO_SPACE and XYZT_TO_TIME can be used to mask off the
838
undesired bits from the xyzt_units fields, leaving "pure" space
839
and time codes. Inversely, the macro SPACE_TIME_TO_XYZT can be
840
used to assemble a space code (0,1,2,...,7) with a time code
841
(0,8,16,32,...,56) into the combined value for xyzt_units.
842
843
Note that codes are provided to indicate the "time" axis units are
844
actually frequency in Hertz (_HZ), in part-per-million (_PPM)
845
or in radians-per-second (_RADS).
846
847
The toffset field can be used to indicate a nonzero start point for
848
the time axis. That is, time point #m is at t=toffset+m*pixdim[4]
849
for m=0..dim[4]-1.
850
-----------------------------------------------------------------------------*/
851
857
#define NIFTI_UNITS_UNKNOWN 0
858
#define NIFTI_UNITS_METER 1
859
#define NIFTI_UNITS_MM 2
860
#define NIFTI_UNITS_MICRON 3
861
#define NIFTI_UNITS_SEC 8
862
#define NIFTI_UNITS_MSEC 16
863
#define NIFTI_UNITS_USEC 24
864
#define NIFTI_UNITS_HZ 32
865
#define NIFTI_UNITS_PPM 40
866
#define NIFTI_UNITS_RADS 48
867
/* @} */
868
869
#undef XYZT_TO_SPACE
870
#undef XYZT_TO_TIME
871
#define XYZT_TO_SPACE(xyzt) ( (xyzt) & 0x07 )
872
#define XYZT_TO_TIME(xyzt) ( (xyzt) & 0x38 )
873
874
#undef SPACE_TIME_TO_XYZT
875
#define SPACE_TIME_TO_XYZT(ss,tt) ( (((char)(ss)) & 0x07) \
876
| (((char)(tt)) & 0x38) )
877
878
/*---------------------------------------------------------------------------*/
879
/* MRI-SPECIFIC SPATIAL AND TEMPORAL INFORMATION:
880
---------------------------------------------
881
A few fields are provided to store some extra information
882
that is sometimes important when storing the image data
883
from an FMRI time series experiment. (After processing such
884
data into statistical images, these fields are not likely
885
to be useful.)
886
887
{ freq_dim } = These fields encode which spatial dimension (1,2, or 3)
888
{ phase_dim } = corresponds to which acquisition dimension for MRI data.
889
{ slice_dim } =
890
Examples:
891
Rectangular scan multi-slice EPI:
892
freq_dim = 1 phase_dim = 2 slice_dim = 3 (or some permutation)
893
Spiral scan multi-slice EPI:
894
freq_dim = phase_dim = 0 slice_dim = 3
895
since the concepts of frequency- and phase-encoding directions
896
don't apply to spiral scan
897
898
slice_duration = If this is positive, AND if slice_dim is nonzero,
899
indicates the amount of time used to acquire 1 slice.
900
slice_duration*dim[slice_dim] can be less than pixdim[4]
901
with a clustered acquisition method, for example.
902
903
slice_code = If this is nonzero, AND if slice_dim is nonzero, AND
904
if slice_duration is positive, indicates the timing
905
pattern of the slice acquisition. The following codes
906
are defined:
907
NIFTI_SLICE_SEQ_INC == sequential increasing
908
NIFTI_SLICE_SEQ_DEC == sequential decreasing
909
NIFTI_SLICE_ALT_INC == alternating increasing
910
NIFTI_SLICE_ALT_DEC == alternating decreasing
911
NIFTI_SLICE_ALT_INC2 == alternating increasing #2
912
NIFTI_SLICE_ALT_DEC2 == alternating decreasing #2
913
{ slice_start } = Indicates the start and end of the slice acquisition
914
{ slice_end } = pattern, when slice_code is nonzero. These values
915
are present to allow for the possible addition of
916
"padded" slices at either end of the volume, which
917
don't fit into the slice timing pattern. If there
918
are no padding slices, then slice_start=0 and
919
slice_end=dim[slice_dim]-1 are the correct values.
920
For these values to be meaningful, slice_start must
921
be non-negative and slice_end must be greater than
922
slice_start. Otherwise, they should be ignored.
923
924
The following table indicates the slice timing pattern, relative to
925
time=0 for the first slice acquired, for some sample cases. Here,
926
dim[slice_dim]=7 (there are 7 slices, labeled 0..6), slice_duration=0.1,
927
and slice_start=1, slice_end=5 (1 padded slice on each end).
928
929
slice
930
index SEQ_INC SEQ_DEC ALT_INC ALT_DEC ALT_INC2 ALT_DEC2
931
6 : n/a n/a n/a n/a n/a n/a n/a = not applicable
932
5 : 0.4 0.0 0.2 0.0 0.4 0.2 (slice time offset
933
4 : 0.3 0.1 0.4 0.3 0.1 0.0 doesn't apply to
934
3 : 0.2 0.2 0.1 0.1 0.3 0.3 slices outside
935
2 : 0.1 0.3 0.3 0.4 0.0 0.1 the range
936
1 : 0.0 0.4 0.0 0.2 0.2 0.4 slice_start ..
937
0 : n/a n/a n/a n/a n/a n/a slice_end)
938
939
The SEQ slice_codes are sequential ordering (uncommon but not unknown),
940
either increasing in slice number or decreasing (INC or DEC), as
941
illustrated above.
942
943
The ALT slice codes are alternating ordering. The 'standard' way for
944
these to operate (without the '2' on the end) is for the slice timing
945
to start at the edge of the slice_start .. slice_end group (at slice_start
946
for INC and at slice_end for DEC). For the 'ALT_*2' slice_codes, the
947
slice timing instead starts at the first slice in from the edge (at
948
slice_start+1 for INC2 and at slice_end-1 for DEC2). This latter
949
acquisition scheme is found on some Siemens scanners.
950
951
The fields freq_dim, phase_dim, slice_dim are all squished into the single
952
byte field dim_info (2 bits each, since the values for each field are
953
limited to the range 0..3). This unpleasantness is due to lack of space
954
in the 348 byte allowance.
955
956
The macros DIM_INFO_TO_FREQ_DIM, DIM_INFO_TO_PHASE_DIM, and
957
DIM_INFO_TO_SLICE_DIM can be used to extract these values from the
958
dim_info byte.
959
960
The macro FPS_INTO_DIM_INFO can be used to put these 3 values
961
into the dim_info byte.
962
-----------------------------------------------------------------------------*/
963
969
#define NIFTI_SLICE_UNKNOWN 0
970
#define NIFTI_SLICE_SEQ_INC 1
971
#define NIFTI_SLICE_SEQ_DEC 2
972
#define NIFTI_SLICE_ALT_INC 3
973
#define NIFTI_SLICE_ALT_DEC 4
974
#define NIFTI_SLICE_ALT_INC2 5
/* 05 May 2005: RWCox */
975
#define NIFTI_SLICE_ALT_DEC2 6
/* 05 May 2005: RWCox */
976
980
#endif
/* _NIFTI_HEADER_ */
NIFTI_TYPE_COMPLEX128
Definition:
nifti.h:145
NIFTI_TYPE_UINT16
Definition:
nifti.h:134
NIFTI_TYPE_FLOAT32
Definition:
nifti.h:140
NIFTI_TYPE_FLOAT128
Definition:
nifti.h:156
NIFTI_TYPE_COMPLEX256
Definition:
nifti.h:153
NIFTI_TYPE_UINT32
Definition:
nifti.h:135
NIFTI_TYPE_UINT8
Definition:
nifti.h:130
NIFTI_TYPE
NIFTI_TYPE
Definition:
nifti.h:128
NIFTI_TYPE_INT32
Definition:
nifti.h:133
nifti2_header
nifti2_header
Definition:
nifti.h:126
NIFTI_TYPE_RGB24
Definition:
nifti.h:148
NIFTI_TYPE_COMPLEX64
Definition:
nifti.h:144
NIFTI_TYPE_UINT64
Definition:
nifti.h:137
NIFTI_TYPE_INT16
Definition:
nifti.h:132
NIFTI_TYPE_INT8
Definition:
nifti.h:131
NIFTI_TYPE_FLOAT64
Definition:
nifti.h:141
NIFTI_TYPE_RGBA32
Definition:
nifti.h:149
NIFTI_TYPE_INT64
Definition:
nifti.h:136
nifti1_header
nifti1_header
Definition:
nifti.h:81
__attribute__
struct __attribute__((packed))
Definition:
nifti.h:21
lib
nifti.h
Generated on Tue May 5 2015 22:14:57 for NPL by
1.8.9.1