NiftiImageInfo.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_NiftiImageInfo_H
21 #define MIRTK_NiftiImageInfo_H
22 
23 #include "mirtk/String.h"
24 #include "mirtk/Matrix.h"
25 
26 
27 namespace mirtk {
28 
29 
30 /// NIfTI datatype codes
32 {
33  NIFTI_TYPE_UINT8 = 2,
34  NIFTI_TYPE_INT16 = 4,
35  NIFTI_TYPE_INT32 = 8,
36  NIFTI_TYPE_FLOAT32 = 16,
37  NIFTI_TYPE_COMPLEX64 = 32,
38  NIFTI_TYPE_FLOAT64 = 64,
39  NIFTI_TYPE_RGB24 = 128,
40  NIFTI_TYPE_INT8 = 256,
41  NIFTI_TYPE_UINT16 = 512,
42  NIFTI_TYPE_UINT32 = 768,
43  NIFTI_TYPE_INT64 = 1024,
44  NIFTI_TYPE_UINT64 = 1280,
45  NIFTI_TYPE_FLOAT128 = 1536,
46  NIFTI_TYPE_COMPLEX128 = 1792,
47  NIFTI_TYPE_COMPLEX256 = 2048,
48  NIFTI_TYPE_RGBA32 = 2304
49 };
50 
51 /// NIfTI intent codes, to describe intended meaning of dataset contents
53 {
54  NIFTI_INTENT_NONE = 0,
55  NIFTI_FIRST_STATCODE = 2,
56  NIFTI_INTENT_CORREL = 2,
57  NIFTI_INTENT_TTEST = 3,
58  NIFTI_INTENT_FTEST = 4,
59  NIFTI_INTENT_ZSCORE = 5,
60  NIFTI_INTENT_CHISQ = 6,
61  NIFTI_INTENT_BETA = 7,
62  NIFTI_INTENT_BINOM = 8,
63  NIFTI_INTENT_GAMMA = 9,
64  NIFTI_INTENT_POISSON = 10,
65  NIFTI_INTENT_NORMAL = 11,
66  NIFTI_INTENT_FTEST_NONC = 12,
67  NIFTI_INTENT_CHISQ_NONC = 13,
68  NIFTI_INTENT_LOGISTIC = 14,
69  NIFTI_INTENT_LAPLACE = 15,
70  NIFTI_INTENT_UNIFORM = 16,
71  NIFTI_INTENT_TTEST_NONC = 17,
72  NIFTI_INTENT_WEIBULL = 18,
73  NIFTI_INTENT_CHI = 19,
74  NIFTI_INTENT_INVGAUSS = 20,
75  NIFTI_INTENT_EXTVAL = 21,
76  NIFTI_INTENT_PVAL = 22,
77  NIFTI_INTENT_LOGPVAL = 23,
78  NIFTI_INTENT_LOG10PVAL = 24,
79  NIFTI_LAST_STATCODE = 24,
80  NIFTI_INTENT_ESTIMATE = 1001,
81  NIFTI_INTENT_LABEL = 1002,
82  NIFTI_INTENT_NEURONAME = 1003,
83  NIFTI_INTENT_GENMATRIX = 1004,
84  NIFTI_INTENT_SYMMATRIX = 1005,
85  NIFTI_INTENT_DISPVECT = 1006,
86  NIFTI_INTENT_VECTOR = 1007,
87  NIFTI_INTENT_POINTSET = 1008,
88  NIFTI_INTENT_TRIANGLE = 1009,
89  NIFTI_INTENT_QUATERNION = 1010,
90  NIFTI_INTENT_DIMLESS = 1011,
91  NIFTI_INTENT_TIME_SERIES = 2001,
92  NIFTI_INTENT_NODE_INDEX = 2002,
93  NIFTI_INTENT_RGB_VECTOR = 2003,
94  NIFTI_INTENT_RGBA_VECTOR = 2004,
95  NIFTI_INTENT_SHAPE = 2005
96 };
97 
98 /// Convert string to NIfTI intent code
99 template <> bool FromString(const char *str, NiftiIntent &value);
100 
101 /// Convert NIfTI intent code to string
102 template <> string ToString(const NiftiIntent &value, int w, char c, bool left);
103 
104 /// NIfTI xform codes to describe the "standard" coordinate system
106 {
107  NIFTI_XFORM_UNKNOWN = 0, ///< Arbitrary coordinates (Method 1)
108  NIFTI_XFORM_SCANNER_ANAT = 1, ///< Scanner-based anatomical coordinates
109  NIFTI_XFORM_ALIGNED_ANAT = 2, ///< Coordinates aligned to another file's,
110  ///< or to anatomical "truth"
111  NIFTI_XFORM_TALAIRACH = 3, ///< Coordinates aligned to Talairach-
112  ///< Tournoux Atlas; (0,0,0)=AC, etc.
113  NIFTI_XFORM_MNI_152 = 4 ///< MNI 152 normalized coordinates
114 };
115 
116 /// NIfTI units codes to describe the unit of measurement for
117 /// each dimension of the dataset
119 {
120  NIFTI_UNITS_UNKNOWN = 0, ///< NIFTI code for unspecified units
121  NIFTI_UNITS_METER = 1, ///< NIFTI code for meters
122  NIFTI_UNITS_MM = 2, ///< NIFTI code for millimeters
123  NIFTI_UNITS_MICRON = 3, ///< NIFTI code for micrometers
124  NIFTI_UNITS_SEC = 8, ///< NIFTI code for seconds
125  NIFTI_UNITS_MSEC = 16, ///< NIFTI code for milliseconds
126  NIFTI_UNITS_USEC = 24, ///< NIFTI code for microseconds
127  NIFTI_UNITS_HZ = 32, ///< NIFTI code for Hertz
128  NIFTI_UNITS_PPM = 40, ///< NIFTI code for ppm
129  NIFTI_UNITS_RADS = 48 ///< NIFTI code for radians per second
130 };
131 
132 /// Convert string to NIfTI units code
133 bool FromString(const char *, NiftiUnits &);
134 
135 /**
136  * NIfTI image header information.
137  *
138  * \note Only contains most commonly used entries of nifti_image struct
139  * and uses MIRTK types for non-builtin types.
140  */
142 {
143  int ndim; ///< last dimension greater than 1 (1..7)
144  int nx; ///< dimensions of grid array
145  int ny; ///< dimensions of grid array
146  int nz; ///< dimensions of grid array
147  int nt; ///< dimensions of grid array
148  int nu; ///< dimensions of grid array
149  int nv; ///< dimensions of grid array
150  int nw; ///< dimensions of grid array
151  size_t nvox; ///< number of voxels = nx*ny*nz*...*nw
152  int nbyper; ///< bytes per voxel, matches datatype
153  int datatype; ///< type of data in voxels: DT_* code
154  double dx; ///< grid spacings
155  double dy; ///< grid spacings
156  double dz; ///< grid spacings
157  double dt; ///< grid spacings
158  double du; ///< grid spacings
159  double dv; ///< grid spacings
160  double dw; ///< grid spacings
161  double scl_slope; ///< scaling parameter - slope
162  double scl_inter; ///< scaling parameter - intercept
163  double cal_min; ///< calibration parameter, minimum
164  double cal_max; ///< calibration parameter, maximum
165  int slice_code; ///< code for slice timing pattern
166  int slice_start; ///< index for start of slices
167  int slice_end; ///< index for end of slices
168  double slice_duration; ///< time between individual slices
169  int qform_code; ///< codes for (x,y,z) space meaning
170  Matrix qto_xyz; ///< qform: transform (i,j,k) to (x,y,z)
171  Matrix qto_ijk; ///< qform: transform (x,y,z) to (i,j,k)
172  int sform_code; ///< codes for (x,y,z) space meaning
173  Matrix sto_xyz; ///< sform: transform (i,j,k) to (x,y,z)
174  Matrix sto_ijk; ///< sform: transform (x,y,z) to (i,j,k)
175  double toffset; ///< time coordinate offset
176  int xyz_units; ///< dx,dy,dz units: NIFTI_UNITS_* code
177  int time_units; ///< dt units: NIFTI_UNITS_* code
178  int nifti_type; ///< 0==ANALYZE, 1==NIFTI-1 (1 file),
179  /// 2==NIFTI-1 (2 files),
180  /// 3==NIFTI-ASCII (1 file)
181  int intent_code; ///< statistic type (or something)
182  double intent_p1; ///< intent parameters
183  double intent_p2; ///< intent parameters
184  double intent_p3; ///< intent parameters
185  string intent_name; ///< optional description of intent data
186  string descrip; ///< optional text to describe dataset
187  string aux_file; ///< auxiliary filename
188  string fname; ///< header filename (.hdr or .nii)
189  string iname; ///< image filename (.img or .nii)
190  int iname_offset; ///< offset into iname where data starts
191  int swapsize; ///< swap unit in image data (might be 0)
192  int byteorder; ///< byte order on disk (MSB_ or LSB_FIRST)
193 
194  /// Constructor, reads header from NIfTI image file
195  NiftiImageInfo(const char * = nullptr);
196 };
197 
198 
199 } // namespace mirtk
200 
201 #endif // MIRTK_NiftiImageInfo_H
string fname
header filename (.hdr or .nii)
string descrip
optional text to describe dataset
string intent_name
optional description of intent data
double slice_duration
time between individual slices
double dx
grid spacings
NiftiImageInfo(const char *=nullptr)
Constructor, reads header from NIfTI image file.
NiftiIntent
NIfTI intent codes, to describe intended meaning of dataset contents.
int nv
dimensions of grid array
NIFTI code for ppm.
double cal_min
calibration parameter, minimum
Matrix sto_ijk
sform: transform (x,y,z) to (i,j,k)
double dz
grid spacings
int slice_end
index for end of slices
int qform_code
codes for (x,y,z) space meaning
int nu
dimensions of grid array
int nw
dimensions of grid array
int swapsize
swap unit in image data (might be 0)
Arbitrary coordinates (Method 1)
double scl_inter
scaling parameter - intercept
double du
grid spacings
double intent_p2
intent parameters
MNI 152 normalized coordinates.
int slice_code
code for slice timing pattern
Matrix qto_xyz
qform: transform (i,j,k) to (x,y,z)
NIFTI code for radians per second.
int xyz_units
dx,dy,dz units: NIFTI_UNITS_* code
int iname_offset
offset into iname where data starts
Matrix sto_xyz
sform: transform (i,j,k) to (x,y,z)
Definition: IOConfig.h:41
int slice_start
index for start of slices
string aux_file
auxiliary filename
double toffset
time coordinate offset
NIFTI code for millimeters.
double intent_p1
intent parameters
int ndim
last dimension greater than 1 (1..7)
size_t nvox
number of voxels = nx*ny*nz*...*nw
Matrix qto_ijk
qform: transform (x,y,z) to (i,j,k)
int ny
dimensions of grid array
int time_units
dt units: NIFTI_UNITS_* code
NiftiXForm
NIfTI xform codes to describe the "standard" coordinate system.
int intent_code
statistic type (or something)
int nx
dimensions of grid array
double dw
grid spacings
string ToString(const EnergyMeasure &value, int w, char c, bool left)
Convert energy measure enumeration value to string.
double dv
grid spacings
double intent_p3
intent parameters
bool FromString(const char *str, EnergyMeasure &value)
Convert energy measure string to enumeration value.
NIFTI code for seconds.
double cal_max
calibration parameter, maximum
double scl_slope
scaling parameter - slope
NIFTI code for microseconds.
double dy
grid spacings
Scanner-based anatomical coordinates.
int sform_code
codes for (x,y,z) space meaning
double dt
grid spacings
NIFTI code for meters.
string iname
image filename (.img or .nii)
int nz
dimensions of grid array
int byteorder
byte order on disk (MSB_ or LSB_FIRST)
NIFTI code for unspecified units.
int datatype
type of data in voxels: DT_* code
int nt
dimensions of grid array
NIFTI code for Hertz.
NiftiDataType
NIfTI datatype codes.
int nbyper
bytes per voxel, matches datatype
NIFTI code for micrometers.
NIFTI code for milliseconds.