edu.washington.biostr.sig.nifti
Class AnalyzeNiftiSpmHeader

java.lang.Object
  extended by edu.washington.biostr.sig.nifti.AnalyzeNiftiSpmHeader

public class AnalyzeNiftiSpmHeader
extends Object

This takes a ByteBuffer for the header of the file and returns various pieces of useful information.
It gets the parameters on an as needed basis.
It provides methods to parse the file that handle standard Analyze 7.5, SPM's version and NIFTI 1. It also will provide some convenience methods. For example, getTransform() tries to handle this as a NIFTI file, then an SPM file (if the flag is set) and finally as a standard Analyze 7.5 file. I have tried to make version specific functions in the comments with (NIFTI) or (SPM). IMPLEMENTATION NOTE: Endian is determined by checking dim[0]. This value must be in the range 1..7, so if it is not, then we know we have the wrong endian. I think this is the preferred method to check the byte order. The image file should have the same byte order.

Version:
1.0
Author:
Eider Moore

Field Summary
static short DT_ALL
          I don't have a clue...
static short DT_BINARY
          binary 1 bit/voxel
static short DT_COMPLEX
          complex (2 floats) 64 bits/voxel
static short DT_COMPLEX128
          A double pair (128 bits/voxel)
static short DT_COMPLEX256
          A long double pair (256 bits/voxel)
static short DT_COMPLEX64
          complex (2 floats) 64 bits/voxel
static short DT_DOUBLE
          a double float 64 bits/voxel
static short DT_FLOAT
          a single float 32 bits/voxel
static short DT_FLOAT128
          A long double (128 bits/voxel).
static short DT_FLOAT32
          a single float 32 bits/voxel
static short DT_FLOAT64
          a double float 64 bits/voxel
static short DT_INT16
          A short 16 bits/voxel
static short DT_INT32
          An int, 32 bits/voxel
static short DT_INT64
          A long 64 bits/ voxel
static short DT_INT8
          A java byte 8 bits/ voxel
static short DT_NONE
          none...
static short DT_RGB
          RGB triple 24 bits/voxel
static short DT_RGB24
          RGB triple 24 bits/voxel.
static short DT_SIGNED_INT
          An int, 32 bits/voxel
static short DT_SIGNED_SHORT
          A short 16 bits/voxel
static short DT_UINT16
          A java char (as opposed to a c char) 16 bits / voxel
static short DT_UINT32
          An unsigned int in C.
static short DT_UINT64
          An unsigned long 64 bits/ voxel.
static short DT_UINT8
          in C an unsigned char, in Java this is an unsigned byte, but you will have to unsign it yourself and map it to a short.
static short DT_UNKNOWN
          I don't know either.
static short DT_UNSIGNED_CHAR
          in C an unsigned char, in Java this is an unsigned byte, but you will have to unsign it yourself and map it to a short.
protected  ByteBuffer header
           
static short NIFTI_INTENT_BETA
          Beta distribution (2 param) p1 = a, p2 = b Density(x) proportional to x^(a-1) * (1 - x)^(b - 1)
static short NIFTI_INTENT_BINOM
           
static short NIFTI_INTENT_CHI
           
static int NIFTI_INTENT_CHISQ
          Chi squared (1 param): p1 = DOF
Density(x) proportional to exp(-x/2) * x^(p1/2 - 1)
static short NIFTI_INTENT_CHISQ_NONC
           
static int NIFTI_INTENT_CORREL
          Correlation coefficient R (1 param)
p1 = degrees of freedom
R/sqrt(1 - R * R) is t distributed with p1 DOF.
static short NIFTI_INTENT_DISPVECT
           
static short NIFTI_INTENT_ESTIMATE
           
static short NIFTI_INTENT_EXTVAL
           
static int NIFTI_INTENT_FTEST
          Fisher F statistics (2 param):
p1=numerator DOF, p2 = denominator DOF
static short NIFTI_INTENT_FTEST_NONC
           
static short NIFTI_INTENT_GAMMA
           
static short NIFTI_INTENT_GENMATRIX
           
static short NIFTI_INTENT_INVGAUSS
           
static short NIFTI_INTENT_LABEL
           
static short NIFTI_INTENT_LAPLACE
           
static short NIFTI_INTENT_LOGISTIC
           
static short NIFTI_INTENT_NEURONAME
           
static short NIFTI_INTENT_NORMAL
           
static short NIFTI_INTENT_POINTSET
           
static short NIFTI_INTENT_POISSON
           
static short NIFTI_INTENT_PVAL
           
static short NIFTI_INTENT_QUATERNION
           
static short NIFTI_INTENT_SYMMATRIX
           
static short NIFTI_INTENT_TRIANGLE
           
static int NIFTI_INTENT_TTEST
          Student t statistic (1 param): p1 = DOF
static short NIFTI_INTENT_TTEST_NONC
           
static short NIFTI_INTENT_UNIFORM
           
static int NIFTI_INTENT_VECTOR
           
static short NIFTI_INTENT_VECTOR_OTHER
           
static short NIFTI_INTENT_WEIBULL
           
static int NIFTI_INTENT_ZSCORE
          Standard normal: Density = N(0, 1).
static short NIFTI_SLICE_ALT_DEC
           
static short NIFTI_SLICE_ALT_INC
           
static short NIFTI_SLICE_SEQ_DEC
           
static short NIFTI_SLICE_SEQ_INC
           
static byte NIFTI_UNITS_HZ
           
static byte NIFTI_UNITS_METER
           
static byte NIFTI_UNITS_MICRON
           
static byte NIFTI_UNITS_MM
           
static byte NIFTI_UNITS_MSEC
           
static byte NIFTI_UNITS_PPM
           
static byte NIFTI_UNITS_SEC
           
static byte NIFTI_UNITS_UNKNOWN
           
static byte NIFTI_UNITS_USEC
           
static short NIFTI_XFORM_ALIGNED_ANAT
          Coordinates aligned to another file's or to anatomical truth.
static short NIFTI_XFORM_MNI_152
          Coordinates in MNI 152 normalized.
static short NIFTI_XFORM_SCANNER_ANAT
          Scanner-based anatomical coordinates.
static short NIFTI_XFORM_TALAIRACH
          Coordinates in Talairach-Tournoux Atlas.
static short NIFTI_XFORM_UNKNOWN
          Arbitraty coordinates
protected  int offset
           
 
Constructor Summary
AnalyzeNiftiSpmHeader(ByteBuffer header, int offset, boolean spm, URL file)
          Create the header from the ByteBuffer.
AnalyzeNiftiSpmHeader(ByteBuffer header, URL file)
          Create a header with 0 offset and not SPM compatible.
AnalyzeNiftiSpmHeader(ByteOrder endian)
          Create a blank, editable Nifti header.
AnalyzeNiftiSpmHeader(ByteOrder endian, boolean singleFile)
          Create a blank, editable Nifti header.
 
Method Summary
static int assembleRGB(ByteBuffer img)
           
 byte[] getAuxFile()
          get a byte[24] for aux_file from 224.
 short getBitpix()
          get the bitpix field (Number of bits/voxel) from position 72.
 float getCalMax()
          get cal_max at 124.
 float getCalMin()
          get cal_min at 128.
 float getCompressed()
          get compressed from 132.
 short getDatatype()
          Get datatype, which is not data_type (stupid, I know) from position 70.
 byte[] getDataType()
          Return the 10 byte data_type field (not to be confused with datatype).
 byte[] getDBName()
          Get the 18 byte db_name field.
 double[] getDefaultSPMTrans()
          Get the transform assuming this is an SPM file.
 byte[] getDescrip()
          get a byte[80] for desrip from 148.
 short[] getDim()
          Get the dim field.
 byte getDimInfo()
          Get the dim_info field (NIFTI) used for MRI slice ordering.
 short getDimUn0()
          get dim_un0 from 74.
 String getDTName(int dt)
          Get the data type name.
 ByteOrder getEndian()
           
 byte[] getExpDate()
          get a byte[10] for exp_date from 293
 byte[] getExpTime()
          get a byte[10] for exp_time from 303
 int getExtents()
          Get the extents field.
 int getFieldSkip()
          get field_skip from 328
 float getFunused1()
          get funused1 from 112
 float getFunused2()
          get funused2 from 116
 float getFunused3()
          get funused3 from 120
 byte[] getGenerated()
          get a byte[10] for generated from 263
 int getGlmax()
          get glmax from 140
 int getGlmin()
          get glmin from 140
 byte[] getHistUn0()
          get a byte[3] for hist_un0 from position 313
 byte getHKeyUn0()
          Get the hkey_un0 field.
 short getIntentCode()
          Get intent_code (NIFTI) from position 68.
 byte[] getIntentName()
          Get the byte[16] for intent_name (NIFTI) from 328.
 float getIntentP1()
          Get intent_p1 (NIFTI) from position 56.
 float getIntentP2()
          Get intent_p2 (NIFTI) from position 60.
 float getIntentP3()
          Get intent_p3 (NIFTI) from position 64.
 byte[] getMagic()
          get the 4 bytes for magic (NIFTI).
 int getNIFTIversion()
          Return the nifti version or 0 if this is not a nifti file.
 double[] getOldTrans()
          This is the last ditch, least preferred method for getting the transform.
 int getOMax()
          get omax from 332
 int getOMin()
          get omin from 336
 byte getOrient()
          get the orient from position 252
 short[] getOrigin()
          Get the 3 byte origin (SPM) from position 253
 byte[] getOriginator()
          get a byte[10] for originator from 253
 byte[] getPatientId()
          get a byte[10] for patient_id from 283
 float[] getPixdim()
          get pixdim float[8] (grid spacings) from 76.
 short getQformCode()
          Get qform_code from 252 (NIFTI).
 float getQoffsetX()
          Get qoffset_x from 268 (NIFTI).
 float getQoffsetY()
          Get qoffset_y from 272 (NIFTI).
 float getQoffsetZ()
          Get qoffset_z from 276 (NIFTI).
 double[] getQTrans()
          Get the transform from Q in NIFTI.
 float getQuaternB()
          Get quatern_c from 256 (NIFTI).
 float getQuaternC()
          Get quatern_d from 260(NIFTI).
 float getQuaternD()
          Get quatern_d from 264 (NIFTI).
 byte getRegular()
          get the regular field.
 float getScaleFactor()
          Get the scale factor (SPM) from funused1
 byte[] getScannum()
          get a byte[10] for scannum from 273
 float getSclOffset()
          get scl_offset (NIFTI) from 116.
 float getSclSlope()
          get scl_slope (NIFTI) from 112.
 short getSessionError()
          Get the session_error field.
 short getSformCode()
          Get sform_code from 254 (NIFTI).
 int getSizeofHdr()
          Get the size of the header.
 byte getSliceCode()
          get slice_code (NIFTI) which is the slice timing order.
 float getSliceDuration()
          get slice_duration (NIFTI) at 132.
 short getSliceEnd()
          Get slice_end (NIFTI) which is the last slice index.
 short getSliceStart()
          get the first slice index.
 int getSMax()
          get smax from 340
 int getSMin()
          get smin from 344
 double[] getSPMTrans()
           
 float[] getSrowX()
          Get srow_x (NIFTI).
 float[] getSrowY()
          Get srow_y (NIFTI).
 float[] getSrowZ()
          Get srow_z (NIFTI).
 int getStartField()
          get start_field from 324
 double[] getSTrans()
          Get the NIFTI s tranform (Method 3).
 float getToffset()
          Get toffset (NIFTI) from 136.
 double[] getTransform(boolean standard)
          Get a transform that can be used.
 short getUnused10()
          Get unused10 from position 60.
 short getUnused11()
          Get unused11 from position 62.
 short getUnused12()
          Get unused12 from position 64.
 short getUnused13()
          Get unused13 from position 66.
 short getUnused14()
          Get unused11 from position 68.
 short getUnused8()
          Get unused8 from position 56.
 short getUnused9()
          Get unused9 from position 58.
 int getViews()
          get views from 316
 int getVolsAdded()
          get vols_added from 320
 float getVoxOffset()
          Get vox_offset from 108.
 byte getXyztUnits()
          get xyzt_units.
 boolean isNIFTI()
           
 boolean isSingleNIFTIFile()
          Return whether or not this is a single file nifti.
 boolean isSPM()
           
static AnalyzeNiftiSpmHeader loadHeader(URL hdr)
           
 double readNext(ByteBuffer img)
          Read the next value from the image buffer and return it as a double.
 long readNextInteger(ByteBuffer img)
           
 Object readNextObj(ByteBuffer img)
          Read the next value as an object.
 void resetBuffer(ByteOrder endian, boolean singleFile)
          Reset the buffer to the initial state for Nifti.
Be careful with this method, it will throw out all information in the buffer.
 void setAuxFile(byte[] auxFile)
          set a byte[24] for aux_file from 224.
 void setBitpix(short bitpix)
          set the bitpix field (Number of bits/voxel) from position 72.
 void setCalMax(float calMax)
          set cal_max at 124.
 void setCalMin(float calMin)
          set cal_min at 128.
 void setCompressed(float compressed)
          set compressed from 132.
 void setDataType(byte[] dataType)
          Return the 10 byte data_type field (not to be confused with datatype).
 void setDatatype(short datatype)
          set datatype, which is not data_type (stupid, I know) from position 70.
 void setDBName(byte[] dbName)
          set the 18 byte db_name field.
 void setDescrip(byte[] descrip)
          set a byte[80] for desrip from 148.
 void setDim(short[] dim)
          set the dim field.
 void setDimInfo(byte dimInfo)
          set the dim_info field (NIFTI) used for MRI slice ordering.
 void setDimUn0(short dimUn0)
          set dim_un0 from 74.
 void setExpDate(byte[] expDate)
          set a byte[10] for exp_date from 293
 void setExpTime(byte[] expTime)
          set a byte[10] for exp_time from 303
 void setExtents(int extents)
          set the extents field.
 void setFieldSkip(int fieldSkip)
          set field_skip from 328
 void setFunused1(float funused1)
          set funused1 from 112
 void setFunused2(float funused2)
          set funused2 from 116
 void setFunused3(float funused3)
          set funused3 from 120
 void setGenerated(byte[] generated)
          set a byte[10] for generated from 263
 void setGlmax(int glmax)
          set glmax from 140
 void setGlmin(int glmin)
          set glmin from 140
 void setHistUn0(byte[] hist)
          set a byte[3] for hist_un0 from position 313
 void setHKeyUn0(byte hkeyUn0)
          set the hkey_un0 field.
 void setIntentCode(short intentCode)
          set intent_code (NIFTI) from position 68.
 void setIntentName(byte[] intentName)
          set the byte[16] for intent_name (NIFTI) from 328.
 void setIntentP1(float intentP1)
          set intent_p1 (NIFTI) from position 56.
 void setIntentP2(float intentP2)
          set intent_p2 (NIFTI) from position 60.
 void setIntentP3(float intentP3)
          set intent_p3 (NIFTI) from position 64.
 void setMagic(boolean singleFile)
          set the 4 bytes for magic (NIFTI).
 void setOMax(int omax)
          set omax from 332
 void setOMin(int omin)
          set omin from 336
 void setOrient(byte orient)
          set the orient from position 252
 void setOrigin(short[] origin)
          set the 3 byte origin (SPM) from position 253
 void setOriginator(byte[] originator)
          set a byte[10] for originator from 253
 void setPatientId(byte[] patientId)
          set a byte[10] for patient_id from 283
 void setPixdim(float[] pixDim)
          set pixdim float[8] (grid spacings) from 76.
 void setQformCode(short qformCode)
          set qform_code from 252 (NIFTI).
 void setQoffsetX(float qoffsetX)
          set qoffset_x from 268 (NIFTI).
 void setQoffsetY(float qoffsetY)
          set qoffset_y from 272 (NIFTI).
 void setQoffsetZ(float qoffsetZ)
          set qoffset_z from 276 (NIFTI).
 void setQuaternB(float quaternB)
          set quatern_c from 256 (NIFTI).
 void setQuaternC(float quaternC)
          set quatern_d from 260(NIFTI).
 void setQuaternD(float quaternD)
          set quatern_d from 264 (NIFTI).
 void setRegular(byte regular)
          set the regular field.
 void setScaleFactor(float scaleFactor)
          set the scale factor (SPM) from funused1
 void setScannum(byte[] scannum)
          set a byte[10] for scannum from 273
 void setSclOffset(float sclOffset)
          set scl_offset (NIFTI) from 116.
 void setSclSlope(float sclSlope)
          set scl_slope (NIFTI) from 112.
 void setSessionError(short sessionError)
          set the session_error field.
 void setSformCode(short sformCode)
          set sform_code from 254 (NIFTI).
 void setSliceCode(byte sliceCode)
          set slice_code (NIFTI) which is the slice timing order.
 void setSliceDuration(float sliceDuration)
          set slice_duration (NIFTI) at 132.
 void setSliceEnd(short sliceEnd)
          set slice_end (NIFTI) which is the last slice index.
 void setSliceStart(short sliceStart)
          set the first slice index.
 void setSMax(int smax)
          set smax from 340
 void setSMin(int smin)
          set smin from 344
 void setSrowX(float[] srowX)
          set srow_x (NIFTI).
 void setSrowY(float[] srowY)
          set srow_y (NIFTI).
 void setSrowZ(float[] srowZ)
          set srow_z (NIFTI).
 void setStartField(int field)
          set start_field from 324
 void setSTrans(double[] trans)
          set the NIFTI s tranform (Method 3).
 void setToffset(float toffset)
          set toffset (NIFTI) from 136.
 void setUnused10(short unused10)
          set unused10 from position 60.
 void setUnused11(short unused11)
          set unused11 from position 62.
 void setUnused12(short unused12)
          set unused12 from position 64.
 void setUnused13(short unused13)
          set unused13 from position 66.
 void setUnused14(short unused14)
          set unused11 from position 68.
 void setUnused8(short unused8)
          set unused8 from position 56.
 void setUnused9(short unused9)
          set unused9 from position 58.
 void setViews(int views)
          set views from 316
 void setVolsAdded(int volsAdded)
          set vols_added from 320
 void setVoxOffset(float voxOffset)
          set vox_offset from 108.
 void setXyztUnits(byte xyztUnits)
          set xyzt_units.
static double[] transform(double[] matrix4x4, double[] point)
           
 void write(OutputStream dest)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NIFTI_INTENT_VECTOR

public static final int NIFTI_INTENT_VECTOR
See Also:
Constant Field Values

NIFTI_INTENT_CORREL

public static final int NIFTI_INTENT_CORREL
Correlation coefficient R (1 param)
p1 = degrees of freedom
R/sqrt(1 - R * R) is t distributed with p1 DOF.

See Also:
Constant Field Values

NIFTI_INTENT_TTEST

public static final int NIFTI_INTENT_TTEST
Student t statistic (1 param): p1 = DOF

See Also:
Constant Field Values

NIFTI_INTENT_FTEST

public static final int NIFTI_INTENT_FTEST
Fisher F statistics (2 param):
p1=numerator DOF, p2 = denominator DOF

See Also:
Constant Field Values

NIFTI_INTENT_ZSCORE

public static final int NIFTI_INTENT_ZSCORE
Standard normal: Density = N(0, 1).

See Also:
Constant Field Values

NIFTI_INTENT_CHISQ

public static final int NIFTI_INTENT_CHISQ
Chi squared (1 param): p1 = DOF
Density(x) proportional to exp(-x/2) * x^(p1/2 - 1)

See Also:
Constant Field Values

NIFTI_INTENT_BETA

public static final short NIFTI_INTENT_BETA
Beta distribution (2 param) p1 = a, p2 = b Density(x) proportional to x^(a-1) * (1 - x)^(b - 1)

See Also:
Constant Field Values

NIFTI_INTENT_BINOM

public static final short NIFTI_INTENT_BINOM
See Also:
Constant Field Values

NIFTI_INTENT_GAMMA

public static final short NIFTI_INTENT_GAMMA
See Also:
Constant Field Values

NIFTI_INTENT_POISSON

public static final short NIFTI_INTENT_POISSON
See Also:
Constant Field Values

NIFTI_INTENT_NORMAL

public static final short NIFTI_INTENT_NORMAL
See Also:
Constant Field Values

NIFTI_INTENT_FTEST_NONC

public static final short NIFTI_INTENT_FTEST_NONC
See Also:
Constant Field Values

NIFTI_INTENT_CHISQ_NONC

public static final short NIFTI_INTENT_CHISQ_NONC
See Also:
Constant Field Values

NIFTI_INTENT_LOGISTIC

public static final short NIFTI_INTENT_LOGISTIC
See Also:
Constant Field Values

NIFTI_INTENT_LAPLACE

public static final short NIFTI_INTENT_LAPLACE
See Also:
Constant Field Values

NIFTI_INTENT_UNIFORM

public static final short NIFTI_INTENT_UNIFORM
See Also:
Constant Field Values

NIFTI_INTENT_TTEST_NONC

public static final short NIFTI_INTENT_TTEST_NONC
See Also:
Constant Field Values

NIFTI_INTENT_WEIBULL

public static final short NIFTI_INTENT_WEIBULL
See Also:
Constant Field Values

NIFTI_INTENT_CHI

public static final short NIFTI_INTENT_CHI
See Also:
Constant Field Values

NIFTI_INTENT_INVGAUSS

public static final short NIFTI_INTENT_INVGAUSS
See Also:
Constant Field Values

NIFTI_INTENT_EXTVAL

public static final short NIFTI_INTENT_EXTVAL
See Also:
Constant Field Values

NIFTI_INTENT_PVAL

public static final short NIFTI_INTENT_PVAL
See Also:
Constant Field Values

NIFTI_INTENT_ESTIMATE

public static final short NIFTI_INTENT_ESTIMATE
See Also:
Constant Field Values

NIFTI_INTENT_LABEL

public static final short NIFTI_INTENT_LABEL
See Also:
Constant Field Values

NIFTI_INTENT_NEURONAME

public static final short NIFTI_INTENT_NEURONAME
See Also:
Constant Field Values

NIFTI_INTENT_GENMATRIX

public static final short NIFTI_INTENT_GENMATRIX
See Also:
Constant Field Values

NIFTI_INTENT_SYMMATRIX

public static final short NIFTI_INTENT_SYMMATRIX
See Also:
Constant Field Values

NIFTI_INTENT_DISPVECT

public static final short NIFTI_INTENT_DISPVECT
See Also:
Constant Field Values

NIFTI_INTENT_VECTOR_OTHER

public static final short NIFTI_INTENT_VECTOR_OTHER
See Also:
Constant Field Values

NIFTI_INTENT_POINTSET

public static final short NIFTI_INTENT_POINTSET
See Also:
Constant Field Values

NIFTI_INTENT_TRIANGLE

public static final short NIFTI_INTENT_TRIANGLE
See Also:
Constant Field Values

NIFTI_INTENT_QUATERNION

public static final short NIFTI_INTENT_QUATERNION
See Also:
Constant Field Values

NIFTI_XFORM_UNKNOWN

public static final short NIFTI_XFORM_UNKNOWN
Arbitraty coordinates

See Also:
Constant Field Values

NIFTI_XFORM_SCANNER_ANAT

public static final short NIFTI_XFORM_SCANNER_ANAT
Scanner-based anatomical coordinates.

See Also:
Constant Field Values

NIFTI_XFORM_ALIGNED_ANAT

public static final short NIFTI_XFORM_ALIGNED_ANAT
Coordinates aligned to another file's or to anatomical truth.

See Also:
Constant Field Values

NIFTI_XFORM_TALAIRACH

public static final short NIFTI_XFORM_TALAIRACH
Coordinates in Talairach-Tournoux Atlas. AC = (0,0,0)

See Also:
Constant Field Values

NIFTI_XFORM_MNI_152

public static final short NIFTI_XFORM_MNI_152
Coordinates in MNI 152 normalized.

See Also:
Constant Field Values

DT_NONE

public static final short DT_NONE
none...

See Also:
Constant Field Values

DT_UNKNOWN

public static final short DT_UNKNOWN
I don't know either.

See Also:
Constant Field Values

DT_BINARY

public static final short DT_BINARY
binary 1 bit/voxel

See Also:
Constant Field Values

DT_UNSIGNED_CHAR

public static final short DT_UNSIGNED_CHAR
in C an unsigned char, in Java this is an unsigned byte, but you will have to unsign it yourself and map it to a short. 8 bits/voxel

See Also:
Constant Field Values

DT_SIGNED_SHORT

public static final short DT_SIGNED_SHORT
A short 16 bits/voxel

See Also:
Constant Field Values

DT_SIGNED_INT

public static final short DT_SIGNED_INT
An int, 32 bits/voxel

See Also:
Constant Field Values

DT_FLOAT

public static final short DT_FLOAT
a single float 32 bits/voxel

See Also:
Constant Field Values

DT_COMPLEX

public static final short DT_COMPLEX
complex (2 floats) 64 bits/voxel

See Also:
Constant Field Values

DT_DOUBLE

public static final short DT_DOUBLE
a double float 64 bits/voxel

See Also:
Constant Field Values

DT_RGB

public static final short DT_RGB
RGB triple 24 bits/voxel

See Also:
Constant Field Values

DT_ALL

public static final short DT_ALL
I don't have a clue...

See Also:
Constant Field Values

DT_UINT8

public static final short DT_UINT8
in C an unsigned char, in Java this is an unsigned byte, but you will have to unsign it yourself and map it to a short. 8 bits/voxel

See Also:
Constant Field Values

DT_INT16

public static final short DT_INT16
A short 16 bits/voxel

See Also:
Constant Field Values

DT_INT32

public static final short DT_INT32
An int, 32 bits/voxel

See Also:
Constant Field Values

DT_FLOAT32

public static final short DT_FLOAT32
a single float 32 bits/voxel

See Also:
Constant Field Values

DT_COMPLEX64

public static final short DT_COMPLEX64
complex (2 floats) 64 bits/voxel

See Also:
Constant Field Values

DT_FLOAT64

public static final short DT_FLOAT64
a double float 64 bits/voxel

See Also:
Constant Field Values

DT_RGB24

public static final short DT_RGB24
RGB triple 24 bits/voxel.

See Also:
Constant Field Values

DT_INT8

public static final short DT_INT8
A java byte 8 bits/ voxel

See Also:
Constant Field Values

DT_UINT16

public static final short DT_UINT16
A java char (as opposed to a c char) 16 bits / voxel

See Also:
Constant Field Values

DT_UINT32

public static final short DT_UINT32
An unsigned int in C. In java this will have to mapped to a long by your 32 bits/voxel code.

See Also:
Constant Field Values

DT_INT64

public static final short DT_INT64
A long 64 bits/ voxel

See Also:
Constant Field Values

DT_UINT64

public static final short DT_UINT64
An unsigned long 64 bits/ voxel. In Java you will have to map this up. The only data type above it that I know of is either a BigInteger or a double. The trade off is on performance (a BigInteger object) vs precision ( a double)

See Also:
Constant Field Values

DT_FLOAT128

public static final short DT_FLOAT128
A long double (128 bits/voxel). This will have to be represented by a BigDecimal in Java (as far as I know).

See Also:
Constant Field Values

DT_COMPLEX128

public static final short DT_COMPLEX128
A double pair (128 bits/voxel)

See Also:
Constant Field Values

DT_COMPLEX256

public static final short DT_COMPLEX256
A long double pair (256 bits/voxel)

See Also:
Constant Field Values

NIFTI_UNITS_UNKNOWN

public static final byte NIFTI_UNITS_UNKNOWN
See Also:
Constant Field Values

NIFTI_UNITS_METER

public static final byte NIFTI_UNITS_METER
See Also:
Constant Field Values

NIFTI_UNITS_MM

public static final byte NIFTI_UNITS_MM
See Also:
Constant Field Values

NIFTI_UNITS_MICRON

public static final byte NIFTI_UNITS_MICRON
See Also:
Constant Field Values

NIFTI_UNITS_SEC

public static final byte NIFTI_UNITS_SEC
See Also:
Constant Field Values

NIFTI_UNITS_MSEC

public static final byte NIFTI_UNITS_MSEC
See Also:
Constant Field Values

NIFTI_UNITS_USEC

public static final byte NIFTI_UNITS_USEC
See Also:
Constant Field Values

NIFTI_UNITS_HZ

public static final byte NIFTI_UNITS_HZ
See Also:
Constant Field Values

NIFTI_UNITS_PPM

public static final byte NIFTI_UNITS_PPM
See Also:
Constant Field Values

NIFTI_SLICE_SEQ_INC

public static final short NIFTI_SLICE_SEQ_INC
See Also:
Constant Field Values

NIFTI_SLICE_SEQ_DEC

public static final short NIFTI_SLICE_SEQ_DEC
See Also:
Constant Field Values

NIFTI_SLICE_ALT_INC

public static final short NIFTI_SLICE_ALT_INC
See Also:
Constant Field Values

NIFTI_SLICE_ALT_DEC

public static final short NIFTI_SLICE_ALT_DEC
See Also:
Constant Field Values

header

protected ByteBuffer header

offset

protected int offset
Constructor Detail

AnalyzeNiftiSpmHeader

public AnalyzeNiftiSpmHeader(ByteBuffer header,
                             URL file)
Create a header with 0 offset and not SPM compatible.

Parameters:
header -

AnalyzeNiftiSpmHeader

public AnalyzeNiftiSpmHeader(ByteOrder endian)
Create a blank, editable Nifti header. This header will be appropriate for a 2 file solution. Use resetBuffer() to change this to a single file.

Parameters:
endian - Specify the byte order. The header must have the same order as the img file.

AnalyzeNiftiSpmHeader

public AnalyzeNiftiSpmHeader(ByteOrder endian,
                             boolean singleFile)
Create a blank, editable Nifti header.

Parameters:
endian - Specify the byte order. The header must have the same order as the img file.
singleFile - TODO

AnalyzeNiftiSpmHeader

public AnalyzeNiftiSpmHeader(ByteBuffer header,
                             int offset,
                             boolean spm,
                             URL file)
Create the header from the ByteBuffer. Because the bytebuffer may contain other information, the offset is the first position of the header.
The header is automatically changed to the correct Endian value.
If a file is both spm and NIFTI compatible (which I think are mutually exclusive)then NIFTI should win and wins in any code within this file.

Parameters:
header -
offset -
spm - Whether or not this is an SPM compatible file.
Method Detail

loadHeader

public static AnalyzeNiftiSpmHeader loadHeader(URL hdr)
                                        throws IOException
Throws:
IOException

getNIFTIversion

public int getNIFTIversion()
Return the nifti version or 0 if this is not a nifti file.

Returns:

write

public void write(OutputStream dest)
           throws IOException
Throws:
IOException

isSPM

public boolean isSPM()

isNIFTI

public boolean isNIFTI()

isSingleNIFTIFile

public boolean isSingleNIFTIFile()
Return whether or not this is a single file nifti. This is not valid if NIFTI version is 0.

Returns:

getEndian

public ByteOrder getEndian()

getSizeofHdr

public int getSizeofHdr()
Get the size of the header. In NIFTI and all Analyze files I have seen, this is always 348. It starts at position 0.

Returns:

getDataType

public byte[] getDataType()
Return the 10 byte data_type field (not to be confused with datatype). This starts at position 4.

Returns:

readNextInteger

public long readNextInteger(ByteBuffer img)

readNext

public double readNext(ByteBuffer img)
Read the next value from the image buffer and return it as a double. This doesn't support all data types. RGB is returned as an integer that represents ARGB (8 bits each)

Parameters:
img - A buffer that contains data pulled directly from the image file.
Returns:
the double representation.

assembleRGB

public static int assembleRGB(ByteBuffer img)

readNextObj

public Object readNextObj(ByteBuffer img)
Read the next value as an object. RGB are returned as Integers, most values are numbers. This will eventually support complex numbers and maybe long doubles.

Parameters:
buffer -
Returns:

getDTName

public String getDTName(int dt)
Get the data type name.

Parameters:
dt -
Returns:

getDBName

public byte[] getDBName()
Get the 18 byte db_name field. It starts at position 14.

Returns:

getExtents

public int getExtents()
Get the extents field. It starts at position 32.

Returns:

getSessionError

public short getSessionError()
Get the session_error field. It starts at position 36.

Returns:

getRegular

public byte getRegular()
get the regular field. It starts at position 38

Returns:

getDimInfo

public byte getDimInfo()
Get the dim_info field (NIFTI) used for MRI slice ordering. This starts at 39.


getHKeyUn0

public byte getHKeyUn0()
Get the hkey_un0 field. This starts at 39.

Returns:

getDim

public short[] getDim()
Get the dim field. This contains the data array dimensions. Starts at 40.

Returns:

getUnused8

public short getUnused8()
Get unused8 from position 56.

Returns:

getUnused9

public short getUnused9()
Get unused9 from position 58.

Returns:

getIntentP1

public float getIntentP1()
Get intent_p1 (NIFTI) from position 56.

Returns:

getUnused10

public short getUnused10()
Get unused10 from position 60.

Returns:

getUnused11

public short getUnused11()
Get unused11 from position 62.

Returns:

getIntentP2

public float getIntentP2()
Get intent_p2 (NIFTI) from position 60.

Returns:

getUnused12

public short getUnused12()
Get unused12 from position 64.

Returns:

getUnused13

public short getUnused13()
Get unused13 from position 66.

Returns:

getIntentP3

public float getIntentP3()
Get intent_p3 (NIFTI) from position 64.

Returns:

getUnused14

public short getUnused14()
Get unused11 from position 68.

Returns:

getIntentCode

public short getIntentCode()
Get intent_code (NIFTI) from position 68. The intent code should be one of the NIFTI_INTENT variables if the file is well formatted for this version.

Returns:

getDatatype

public short getDatatype()
Get datatype, which is not data_type (stupid, I know) from position 70.

Returns:

getBitpix

public short getBitpix()
get the bitpix field (Number of bits/voxel) from position 72.

Returns:

getSliceStart

public short getSliceStart()
get the first slice index. This is field slice_start from 74

Returns:

getDimUn0

public short getDimUn0()
get dim_un0 from 74.

Returns:

getPixdim

public float[] getPixdim()
get pixdim float[8] (grid spacings) from 76.

Returns:

getVoxOffset

public float getVoxOffset()
Get vox_offset from 108. This is the offset into the .nii file in NIFTI.

Returns:

getFunused1

public float getFunused1()
get funused1 from 112

Returns:

getFunused2

public float getFunused2()
get funused2 from 116

Returns:

getFunused3

public float getFunused3()
get funused3 from 120

Returns:

getSclSlope

public float getSclSlope()
get scl_slope (NIFTI) from 112. This is the slope for data scaling.

Returns:

getSclOffset

public float getSclOffset()
get scl_offset (NIFTI) from 116. This is the offset for data scaling.

Returns:

getSliceEnd

public short getSliceEnd()
Get slice_end (NIFTI) which is the last slice index. Position 120.

Returns:

getSliceCode

public byte getSliceCode()
get slice_code (NIFTI) which is the slice timing order. Position 122.

Returns:

getXyztUnits

public byte getXyztUnits()
get xyzt_units. These are the units for pixdim[1..4]. Position 123

Returns:

getCalMax

public float getCalMax()
get cal_max at 124. This is the max display intensity.

Returns:

getCalMin

public float getCalMin()
get cal_min at 128. This is the min display intensity.

Returns:

getSliceDuration

public float getSliceDuration()
get slice_duration (NIFTI) at 132. This is time for 1 slice.

Returns:

getCompressed

public float getCompressed()
get compressed from 132.

Returns:

getToffset

public float getToffset()
Get toffset (NIFTI) from 136. This is the time axis shift.

Returns:

getGlmax

public int getGlmax()
get glmax from 140

Returns:

getGlmin

public int getGlmin()
get glmin from 140

Returns:

getDescrip

public byte[] getDescrip()
get a byte[80] for desrip from 148. This is any text you want.

Returns:

getAuxFile

public byte[] getAuxFile()
get a byte[24] for aux_file from 224. auxilary filename.

Returns:

getOrient

public byte getOrient()
get the orient from position 252

Returns:

getOriginator

public byte[] getOriginator()
get a byte[10] for originator from 253

Returns:

getGenerated

public byte[] getGenerated()
get a byte[10] for generated from 263

Returns:

getScannum

public byte[] getScannum()
get a byte[10] for scannum from 273

Returns:

getPatientId

public byte[] getPatientId()
get a byte[10] for patient_id from 283

Returns:

getExpDate

public byte[] getExpDate()
get a byte[10] for exp_date from 293

Returns:

getExpTime

public byte[] getExpTime()
get a byte[10] for exp_time from 303

Returns:

getHistUn0

public byte[] getHistUn0()
get a byte[3] for hist_un0 from position 313


getViews

public int getViews()
get views from 316

Returns:

getVolsAdded

public int getVolsAdded()
get vols_added from 320

Returns:

getStartField

public int getStartField()
get start_field from 324

Returns:

getFieldSkip

public int getFieldSkip()
get field_skip from 328

Returns:

getOMin

public int getOMin()
get omin from 336

Returns:

getOMax

public int getOMax()
get omax from 332

Returns:

getSMin

public int getSMin()
get smin from 344

Returns:

getSMax

public int getSMax()
get smax from 340

Returns:

getQformCode

public short getQformCode()
Get qform_code from 252 (NIFTI). This is an NIFTI_XFORM_* code.

Returns:

getSformCode

public short getSformCode()
Get sform_code from 254 (NIFTI). This is an NIFTI_XFORM_* code.

Returns:

getQuaternB

public float getQuaternB()
Get quatern_c from 256 (NIFTI). This is the quaternion b param.

Returns:

getQuaternC

public float getQuaternC()
Get quatern_d from 260(NIFTI). This is the quaternion c param.

Returns:

getQuaternD

public float getQuaternD()
Get quatern_d from 264 (NIFTI). This is the quaternion d param.

Returns:

getQoffsetX

public float getQoffsetX()
Get qoffset_x from 268 (NIFTI). This is the quaternion z shift.

Returns:

getQoffsetY

public float getQoffsetY()
Get qoffset_y from 272 (NIFTI). This is the quaternion z shift.

Returns:

getQoffsetZ

public float getQoffsetZ()
Get qoffset_z from 276 (NIFTI). This is the quaternion z shift.

Returns:

getSrowX

public float[] getSrowX()
Get srow_x (NIFTI). This is 1st row affine transform. Position 280.

Returns:

getSrowY

public float[] getSrowY()
Get srow_y (NIFTI). This is 2nd row affine transform. Position 296.

Returns:

getSrowZ

public float[] getSrowZ()
Get srow_z (NIFTI). This is 3rd row affine transform. Position 312.

Returns:

getIntentName

public byte[] getIntentName()
Get the byte[16] for intent_name (NIFTI) from 328. This is the 'name' or meaning of the data.

Returns:

getMagic

public byte[] getMagic()
get the 4 bytes for magic (NIFTI). This must be ni1\0 or n+1\0, but 1 may change with versions of NIFTI. Position 344.

Returns:

getOrigin

public short[] getOrigin()
Get the 3 byte origin (SPM) from position 253

Returns:

getScaleFactor

public float getScaleFactor()
Get the scale factor (SPM) from funused1

Returns:

getTransform

public double[] getTransform(boolean standard)
Get a transform that can be used. In the case of SPM files, external code should read the mat file and this should only be used as a default. Only NIFTI files have a standard coordinate system option. The transform is 0 indexed (ie x goes from [0, xMax) or the same for y and z)

Parameters:
standard - Get the space in a standard coordinate system if it exists.
Returns:

getOldTrans

public double[] getOldTrans()
This is the last ditch, least preferred method for getting the transform. It is only for compatibility with previous versions.

Returns:

getSPMTrans

public double[] getSPMTrans()

transform

public static double[] transform(double[] matrix4x4,
                                 double[] point)

getDefaultSPMTrans

public double[] getDefaultSPMTrans()
Get the transform assuming this is an SPM file.

Returns:

getQTrans

public double[] getQTrans()
Get the transform from Q in NIFTI. This is the quaternion or method 2 in the file. If this file follows the specification, then this will be on the original grid or close to it. It will only be valid if qform_code > 0.

Returns:

getSTrans

public double[] getSTrans()
Get the NIFTI s tranform (Method 3). This is designed to represent the grid in some standard space. It will only be valid if sform_code > 0.

Returns:

setDataType

public void setDataType(byte[] dataType)
Return the 10 byte data_type field (not to be confused with datatype). This starts at position 4.


setDBName

public void setDBName(byte[] dbName)
set the 18 byte db_name field. It starts at position 14.


setExtents

public void setExtents(int extents)
set the extents field. It starts at position 32.


setSessionError

public void setSessionError(short sessionError)
set the session_error field. It starts at position 36.


setRegular

public void setRegular(byte regular)
set the regular field. It starts at position 38


setDimInfo

public void setDimInfo(byte dimInfo)
set the dim_info field (NIFTI) used for MRI slice ordering. This starts at 39.


setHKeyUn0

public void setHKeyUn0(byte hkeyUn0)
set the hkey_un0 field. This starts at 39.


setDim

public void setDim(short[] dim)
set the dim field. This contains the data array dimensions. Starts at 40.


setUnused8

public void setUnused8(short unused8)
set unused8 from position 56.


setUnused9

public void setUnused9(short unused9)
set unused9 from position 58.


setIntentP1

public void setIntentP1(float intentP1)
set intent_p1 (NIFTI) from position 56.


setUnused10

public void setUnused10(short unused10)
set unused10 from position 60.


setUnused11

public void setUnused11(short unused11)
set unused11 from position 62.


setIntentP2

public void setIntentP2(float intentP2)
set intent_p2 (NIFTI) from position 60.


setUnused12

public void setUnused12(short unused12)
set unused12 from position 64.


setUnused13

public void setUnused13(short unused13)
set unused13 from position 66.


setIntentP3

public void setIntentP3(float intentP3)
set intent_p3 (NIFTI) from position 64.


setUnused14

public void setUnused14(short unused14)
set unused11 from position 68.


setIntentCode

public void setIntentCode(short intentCode)
set intent_code (NIFTI) from position 68. The intent code should be one of the NIFTI_INTENT variables if the file is well formatted for this version.


setDatatype

public void setDatatype(short datatype)
set datatype, which is not data_type (stupid, I know) from position 70. Automatically setBitPix()


setBitpix

public void setBitpix(short bitpix)
set the bitpix field (Number of bits/voxel) from position 72.


setSliceStart

public void setSliceStart(short sliceStart)
set the first slice index. This is field slice_start from 74


setDimUn0

public void setDimUn0(short dimUn0)
set dim_un0 from 74.


setPixdim

public void setPixdim(float[] pixDim)
set pixdim float[8] (grid spacings) from 76.


setVoxOffset

public void setVoxOffset(float voxOffset)
set vox_offset from 108. This is the offset into the .nii file in NIFTI.


setFunused1

public void setFunused1(float funused1)
set funused1 from 112


setFunused2

public void setFunused2(float funused2)
set funused2 from 116


setFunused3

public void setFunused3(float funused3)
set funused3 from 120


setSclSlope

public void setSclSlope(float sclSlope)
set scl_slope (NIFTI) from 112. This is the slope for data scaling.


setSclOffset

public void setSclOffset(float sclOffset)
set scl_offset (NIFTI) from 116. This is the offset for data scaling.


setSliceEnd

public void setSliceEnd(short sliceEnd)
set slice_end (NIFTI) which is the last slice index. Position 120.


setSliceCode

public void setSliceCode(byte sliceCode)
set slice_code (NIFTI) which is the slice timing order. Position 122.


setXyztUnits

public void setXyztUnits(byte xyztUnits)
set xyzt_units. These are the units for pixdim[1..4]. Position 123


setCalMax

public void setCalMax(float calMax)
set cal_max at 124. This is the max display intensity.


setCalMin

public void setCalMin(float calMin)
set cal_min at 128. This is the min display intensity.


setSliceDuration

public void setSliceDuration(float sliceDuration)
set slice_duration (NIFTI) at 132. This is time for 1 slice.


setCompressed

public void setCompressed(float compressed)
set compressed from 132.


setToffset

public void setToffset(float toffset)
set toffset (NIFTI) from 136. This is the time axis shift.


setGlmax

public void setGlmax(int glmax)
set glmax from 140


setGlmin

public void setGlmin(int glmin)
set glmin from 140


setDescrip

public void setDescrip(byte[] descrip)
set a byte[80] for desrip from 148. This is any text you want.


setAuxFile

public void setAuxFile(byte[] auxFile)
set a byte[24] for aux_file from 224. auxilary filename.


setOrient

public void setOrient(byte orient)
set the orient from position 252


setOriginator

public void setOriginator(byte[] originator)
set a byte[10] for originator from 253


setGenerated

public void setGenerated(byte[] generated)
set a byte[10] for generated from 263


setScannum

public void setScannum(byte[] scannum)
set a byte[10] for scannum from 273


setPatientId

public void setPatientId(byte[] patientId)
set a byte[10] for patient_id from 283


setExpDate

public void setExpDate(byte[] expDate)
set a byte[10] for exp_date from 293


setExpTime

public void setExpTime(byte[] expTime)
set a byte[10] for exp_time from 303


setHistUn0

public void setHistUn0(byte[] hist)
set a byte[3] for hist_un0 from position 313


setViews

public void setViews(int views)
set views from 316


setVolsAdded

public void setVolsAdded(int volsAdded)
set vols_added from 320


setStartField

public void setStartField(int field)
set start_field from 324


setFieldSkip

public void setFieldSkip(int fieldSkip)
set field_skip from 328


setOMin

public void setOMin(int omin)
set omin from 336


setOMax

public void setOMax(int omax)
set omax from 332


setSMin

public void setSMin(int smin)
set smin from 344


setSMax

public void setSMax(int smax)
set smax from 340


setQformCode

public void setQformCode(short qformCode)
set qform_code from 252 (NIFTI). This is an NIFTI_XFORM_* code.


setSformCode

public void setSformCode(short sformCode)
set sform_code from 254 (NIFTI). This is an NIFTI_XFORM_* code.


setQuaternB

public void setQuaternB(float quaternB)
set quatern_c from 256 (NIFTI). This is the quaternion b param.


setQuaternC

public void setQuaternC(float quaternC)
set quatern_d from 260(NIFTI). This is the quaternion c param.


setQuaternD

public void setQuaternD(float quaternD)
set quatern_d from 264 (NIFTI). This is the quaternion d param.


setQoffsetX

public void setQoffsetX(float qoffsetX)
set qoffset_x from 268 (NIFTI). This is the quaternion z shift.


setQoffsetY

public void setQoffsetY(float qoffsetY)
set qoffset_y from 272 (NIFTI). This is the quaternion z shift.


setQoffsetZ

public void setQoffsetZ(float qoffsetZ)
set qoffset_z from 276 (NIFTI). This is the quaternion z shift.


setSrowX

public void setSrowX(float[] srowX)
set srow_x (NIFTI). This is 1st row affine transform. Position 280.


setSrowY

public void setSrowY(float[] srowY)
set srow_y (NIFTI). This is 2nd row affine transform. Position 296.


setSrowZ

public void setSrowZ(float[] srowZ)
set srow_z (NIFTI). This is 3rd row affine transform. Position 312.


setIntentName

public void setIntentName(byte[] intentName)
set the byte[16] for intent_name (NIFTI) from 328. This is the 'name' or meaning of the data.


setMagic

public void setMagic(boolean singleFile)
set the 4 bytes for magic (NIFTI). This varies depending on whether the file is a single file or 2 files. The result is ni1\0 or n+1\0, but 1 may change with versions of NIFTI. Position 344.


setOrigin

public void setOrigin(short[] origin)
set the 3 byte origin (SPM) from position 253


setScaleFactor

public void setScaleFactor(float scaleFactor)
set the scale factor (SPM) from funused1


setSTrans

public void setSTrans(double[] trans)
set the NIFTI s tranform (Method 3). This is designed to represent the grid in some standard space. It will only be valid if sform_code > 0.


resetBuffer

public void resetBuffer(ByteOrder endian,
                        boolean singleFile)
Reset the buffer to the initial state for Nifti.
Be careful with this method, it will throw out all information in the buffer. However it will also ensure that the NIFTI file is well formed if you are starting from a blank state.

Parameters:
endian - the ByteOrder for this array.
singleFile - true if you intend to save this as a single nii file


Copyright © 2006 University of Washington. All Rights Reserved.