Documentation
¶
Index ¶
- Constants
- func IsValidDatatype(datatype int32) bool
- func NewNiiWriter(filePath string, options ...func(*niiWriter)) (*niiWriter, error)
- func WithCompression(withCompression bool) func(writer *niiWriter)
- func WithHeader(header *Nii1Header) func(*niiWriter)
- func WithHeaderCompression(headerCompression bool) func(*niiWriter)
- func WithHeaderFile(headerFile string) func(*niiReader) error
- func WithInMemory(inMemory bool) func(*niiReader) error
- func WithNIfTIData(data *Nii) func(writer *niiWriter)
- func WithRetainHeader(retainHeader bool) func(*niiReader) error
- func WithWriteHeaderFile(writeHeaderFile bool) func(*niiWriter)
- type Nifti1Ext
- type Nii
- type Nii1Header
- type Nii2Header
- type NiiReader
Constants ¶
const ( INVALID = "INVALID" UNKNOWN = "UNKNOWN" ILLEGAL = "ILLEGAL" )
Variables ¶
This section is empty.
Functions ¶
func IsValidDatatype ¶
IsValidDatatype checks whether the datatype is valid for NIFTI format
func NewNiiWriter ¶
NewNiiWriter returns a new write for export
func WithCompression ¶
func WithCompression(withCompression bool) func(writer *niiWriter)
WithCompression sets the option to write compressed NIfTI image to a single file (.nii.gz)
If true, the whole file will be compressed. Default is false.
func WithHeader ¶
func WithHeader(header *Nii1Header) func(*niiWriter)
WithHeader sets the option to allow user to provide predefined NIfTI-1 header structure.
If no header provided, the header will be converted from the NIfTI image structure
func WithHeaderCompression ¶
func WithHeaderCompression(headerCompression bool) func(*niiWriter)
WithHeaderCompression sets the option to write compressed NIfTI header structure to file (.hdr.gz)
If true, the header will be compressed. It only works when WithWriteHeaderFile is provided with option `true`. Default is false.
func WithHeaderFile ¶
WithHeaderFile allows option to specify the separate header file
func WithInMemory ¶
WithInMemory allows option to read the whole file into memory
func WithNIfTIData ¶
func WithNIfTIData(data *Nii) func(writer *niiWriter)
WithNIfTIData sets the option to allow user to provide predefined NIfTI-1 data structure.
func WithRetainHeader ¶
WithRetainHeader allows option to keep the header after parsing instead of just keeping the NIfTI data structure
func WithWriteHeaderFile ¶
func WithWriteHeaderFile(writeHeaderFile bool) func(*niiWriter)
WithWriteHeaderFile sets the option to write NIfTI image to a header/image (.hdr/.img) file pair
If true, output will be two files for the header and the image. Default is false.
Types ¶
type Nii ¶
type Nii struct { NDim int64 // last dimension greater than 1 (1..7) Nx int64 // dimensions of grid array Ny int64 // dimensions of grid array Nz int64 // dimensions of grid array Nt int64 // dimensions of grid array Nu int64 // dimensions of grid array Nv int64 // dimensions of grid array Nw int64 // dimensions of grid array Dim [8]int64 // dim[0] = ndim, dim[1] = nx, etc NVox int64 // number of voxels = nx*ny*nz*...*nw NByPer int32 // bytes per voxel, matches datatype (Datatype) Datatype int32 // type of data in voxels: DT_* code Dx float64 // grid spacings Dy float64 // grid spacings Dz float64 // grid spacings Dt float64 // grid spacings Du float64 // grid spacings Dv float64 // grid spacings Dw float64 // grid spacings tEStataILSTERIOn PixDim [8]float64 // pixdim[1]=dx, etc SclSlope float64 // scaling parameter: slope SclInter float64 // scaling parameter: intercept CalMin float64 // calibration parameter: minimum CalMax float64 // calibration parameter: maximum QformCode int32 // codes for (x,y,z) space meaning SformCode int32 // codes for (x,y,z) space meaning FreqDim int32 // indices (1,2,3, or 0) for MRI PhaseDim int32 // directions in dim[]/pixdim[] SliceDim int32 // directions in dim[]/pixdim[] SliceCode int32 // code for slice timing pattern SliceStart int64 // index for start of slices SliceEnd int64 // index for end of slices SliceDuration float64 // time between individual slices QuaternB float64 // Quaternion transform parameters [when writing a dataset, these are used for qform, NOT qto_xyz] QuaternC float64 // Quaternion transform parameters [when writing a dataset, these are used for qform, NOT qto_xyz] QuaternD float64 // Quaternion transform parameters [when writing a dataset, these are used for qform, NOT qto_xyz] QoffsetX float64 // Quaternion transform parameters [when writing a dataset, these are used for qform, NOT qto_xyz] QoffsetY float64 // Quaternion transform parameters [when writing a dataset, these are used for qform, NOT qto_xyz] QoffsetZ float64 // Quaternion transform parameters [when writing a dataset, these are used for qform, NOT qto_xyz] QFac float64 // Quaternion transform parameters [when writing a dataset, these are used for qform, NOT qto_xyz] QtoXYZ matrix.DMat44 // qform: transform (i,j,k) to (x,y,z) QtoIJK matrix.DMat44 // qform: transform (x,y,z) to (i,j,k) StoXYZ matrix.DMat44 // sform: transform (i,j,k) to (x,y,z) StoIJK matrix.DMat44 // sform: transform (x,y,z) to (i,j,k) TOffset float64 // time coordinate offset XYZUnits int32 // dx,dy,dz units: NIFTI_UNITS_* code TimeUnits int32 // dt units: NIFTI_UNITS_* code NiftiType int32 // 0==Analyze, 1==NIFTI-1 (file), 2==NIFTI-1 (2 files), 3==NIFTI-ASCII (1 file) IntentCode int32 // statistic type (or something) IntentP1 float64 // intent parameters IntentP2 float64 // intent parameters IntentP3 float64 // intent parameters IntentName [16]byte // optional description of intent data Descrip [80]byte // optional text to describe dataset AuxFile [24]byte // auxiliary filename FName *byte // header filename IName *byte // image filename INameOffset int32 // offset into IName where data start SwapSize int32 // swap unit in image data (might be 0) ByteOrder binary.ByteOrder // byte order on disk (MSB_ or LSB_FIRST) Volume []byte // slice of data: nbyper*nvox bytes NumExt int32 // number of extensions in extList Nifti1Ext []Nifti1Ext // array of extension structs (with data) IJKOrtient [3]int32 // self-add. Orientation ini, j, k coordinate Affine matrix.DMat44 // self-add. Affine matrix VoxOffset float64 // self-add. Voxel offset Version int // self-add. Used for version identification when writing }
Nii defines the structure of the NIFTI-1 data for I/O purpose
type Nii1Header ¶
type Nii1Header struct { SizeofHdr int32 DataTypeUnused [10]uint8 DbName [18]uint8 Extents int32 SessionError int16 Regular uint8 DimInfo uint8 Dim [8]int16 IntentP1 float32 IntentP2 float32 IntentP3 float32 IntentCode int16 Datatype int16 Bitpix int16 SliceStart int16 Pixdim [8]float32 VoxOffset float32 SclSlope float32 SclInter float32 SliceEnd int16 SliceCode uint8 XyztUnits uint8 CalMax float32 CalMin float32 SliceDuration float32 Toffset float32 Glmax int32 Glmin int32 Descrip [80]uint8 AuxFile [24]uint8 QformCode int16 SformCode int16 QuaternB float32 QuaternC float32 QuaternD float32 QoffsetX float32 QoffsetY float32 QoffsetZ float32 SrowX [4]float32 SrowY [4]float32 SrowZ [4]float32 IntentName [16]uint8 Magic [4]uint8 }
Nii1Header defines the structure of the NIFTI-1 header
func MakeNewNii1Header ¶
func MakeNewNii1Header(inDim *[8]int16, inDatatype int32) *Nii1Header
type Nii2Header ¶
type Nii2Header struct { SizeofHdr int32 Magic [8]uint8 Datatype int16 Bitpix int16 Dim [8]int64 IntentP1 float64 IntentP2 float64 IntentP3 float64 Pixdim [8]float64 VoxOffset int64 SclSlope float64 SclInter float64 CalMax float64 CalMin float64 SliceDuration float64 Toffset float64 SliceStart int64 SliceEnd int64 Descrip [80]uint8 AuxFile [24]uint8 QformCode int32 SformCode int32 QuaternB float64 QuaternC float64 QuaternD float64 QoffsetX float64 QoffsetY float64 QoffsetZ float64 SrowX [4]float64 SrowY [4]float64 SrowZ [4]float64 SliceCode int32 XyztUnits int32 IntentCode int32 IntentName [16]uint8 DimInfo uint8 UnusedStr [15]uint8 }
Nii2Header defines the structure of the NIFTI-2 header
type NiiReader ¶
type NiiReader interface { // Parse returns the input NIFTI as header and image data Parse() error // GetOrientation returns the image orientation GetOrientation() [3]string // GetSliceCode returns the slice code GetSliceCode() string // GetDatatype returns the datatype of the NIFTI image GetDatatype() string // GetSFormCode returns the SForm code string GetSFormCode() string // GetQFormCode returns the QForm code string GetQFormCode() string // GetImgShape returns the image shape [x, y, z, t] GetImgShape() [4]int64 // GetAt returns the value at [x, y, z, t] as float64 GetAt(x, y, z, t int64) float64 // GetBinaryOrder returns the binary order of the NIFTI image GetBinaryOrder() binary.ByteOrder // GetUnitsOfMeasurements returns the spatial and temporal units of the NIFTI image GetUnitsOfMeasurements() ([2]string, error) // GetTimeSeries returns the time series of value at [x, y, z] GetTimeSeries(x, y, z int64) ([]float64, error) // GetSlice returns the X-Y slice at [z, t] GetSlice(z, t int64) ([][]float64, error) // GetVolume returns the image data as 3-D matrix GetVolume(t int64) ([][][]float64, error) // GetAffine returns the affine matrix of the NIFTI image GetAffine() matrix.DMat44 // QuaternToMatrix converts the quarternions parameters to matrix QuaternToMatrix() matrix.DMat44 // GetNiiData returns the raw NIFTI header and image data GetNiiData() *Nii }