Reputation: 725
I have a .nii
file with the following meta data
NII Header Size: 348
NII Magic Number: n+1
Dimension Information:
Frequency Dimension: 0
Phase Dimension: 0
Slice Dimension: 0
Number of Image Dimensions: 3
Spatial Dimension X has length: 91
Spatial Dimension Y has length: 109
Spatial Dimension Z has length: 91
Intent Code: 0
Data Type: FLOAT
Number of bits per Voxel: 32
Description: 6.0.5:9e026117
Voxel Dimensions:
Voxel Dimension X has length: 2.000000
Voxel Dimension Y has length: 2.000000
Voxel Dimension Z has length: 2.000000
Image data begins at byte: 352
Data Scaling:
Slope: 1.000000
Y-Intercept: 0.000000
Color Range:
Min: 0.020708
Max: 9.358182
Slicing Information:
Slice Start: 0
Slice End: 0
Slice Duration: 0.000000
Slice Code: 0
Measurement Units:
Spatial Dimension: MILLIMETER
Temporal Dimension: SECOND
Auxiliary File: render1t
Q Form Code: 4
b: 0.000000
c: 1.000000
d: 0.000000
x offset: 90.000000
y offset: -126.000000
z offset: -72.000000
S Form Code: 4
Affine Matrix:
-2.000000 0.000000 0.000000 90.000000
0.000000 2.000000 0.000000 -126.000000
0.000000 0.000000 2.000000 -72.000000
0.000000 0.000000 0.000000 1.000000
Total number of voxels: 902629
How do I know how to read the image data? I know it is an array of floats, but for each index in that array how do I translate it to a ijk
voxel coordinate? I'm really looking for what's the correct function to use that translates each float index in the .nii file to an appropriate ijk
voxel coordinate.
I've been looking at this: https://brainder.org/2012/09/23/the-nifti-file-format/, but either it was never mentioned, or I'm not understanding something.
Upvotes: 0
Views: 125
Reputation: 1158
From a comment by A. M. Winkler on the page you linked:
The storage is RAS, i.e., the the first dimension to be filled (i.e., that runs faster), is “x”, from left to right, then “y” from posterior to anterior, then “z”, from inferior to superior. Of course these directions may not correspond to the actual brain orientation (if this is at all a brain), but once read, you adjust the orientation using one of the 3 orientation methods from the header, as described above.
Upvotes: 0