Class NIFTIHeader

java.lang.Object
com.xinapse.multisliceimage.Analyze.ANZHeader
com.xinapse.multisliceimage.Analyze.NIFTIHeader
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
NIFTI2Header

public class NIFTIHeader extends ANZHeader
This class represents a multi-dimensional NIFTI-1 image header file. The header file may either:
  • contain all the dimensional and descriptive information about a NIFTI-1 image, but none of the pixel data. This is the conventional Analyze 7.5 .img/.hdr file format.
  • contain both the dimensional and descriptive information about a NIFTI-1 image, and also the pixel data. This is the new NIFTI-1 .nii file format.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    The default setting of whether NIFTI-1 images that have qform and sform orientation both unset should be read as having an increasing a patient left coordinate value with stored pixel data column number, and whether NIFTI-1 images should be prevented from being written without orientation information.
    static final boolean
    The default setting of whether NIFTI-1 images should be saved with an orientation that is compatible with FSL, where possible.
    static final boolean
    The default setting of whether NIFTI-1 images should be saved with an orientation that is compatible with SPM, where possible.
    protected List<com.xinapse.multisliceimage.Analyze.ExtendedData>
    The extended data, if present.
    protected byte[]
    The NIFTI extension indicator, if present.
    static final String
    The property value key for setting whether NIFTI-1 images that have qform and sform orientation both unset should be read as having an increasing a patient left coordinate value with stored pixel data column number, and whether NIFTI-1 images should be prevented from being written without orientation information.
    protected byte[]
    The magic number that is used to differentiate NIFTI-1, NIFTI-2 and Analyze 7.5 images.
    The NIFTI qform parameter.
    double
    The NIFTI qoffset_x parameter.
    double
    The NIFTI qoffset_y parameter.
    double
    The NIFTI qoffset_z parameter.
    double
    The NIFTI quatern_b parameter.
    double
    The NIFTI quatern_c parameter.
    double
    The NIFTI quatern_d parameter.
    static final String
    The property value key for setting whether NIFTI-1 images should be saved with an orientation that is compatible with FSL, where possible.
    static final String
    The property value key for setting whether NIFTI-1 images should be saved with an orientation that is compatible with SPM, where possible.
    The NIFTI sform parameter.
    double[]
    The NIFTI srow_x parameter.
    double[]
    The NIFTI srow_y parameter.
    double[]
    The NIFTI srow_z parameter.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    NIFTIHeader(boolean compressed)
    Creates a new NIFTIHeader.
    protected
    NIFTIHeader(ANZPixFormat dataType, boolean compressed, Long... dims)
    Creates a new NIFTIHeader.
    protected
    NIFTIHeader(NIFTIHeader header, boolean compressed)
    Creates a new NIFTI header, copying the information from an existing NIFTI header.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns an exact copy of this NIFTI-1 header.
    protected int
    Returns the size of this NIFTI (NIFTI-1 or NIFTI-2) header.
    static boolean
    Returns the user's preference about whether NIFTI-1 images with both qform and sform orientations unset should be read as having the patient left coordinate increasing with stored pixel data column number, and whether NIFTI-1 images should be prevented from being written without orientation information.
    static boolean
    Returns the user's preference about whether NIFTI-1 images should be saved with an orientation that is compatible with FSL, where possible.
    static boolean
    Returns the user's preference about whether NIFTI-1 images should be saved with an orientation that is compatible with SPM, where possible.
    protected void
    Read the NIFTI extensions from an InputStream.
    protected void
    Read any NIFTI extensions from a RandomAccessFile.
    static void
    Saves the user's preference about whether NIFTI-1 images should be read as having the patient left coordinate increasing with stored pixel data column number.
    static void
    Saves the user's preference about whether NIFTI-1 images should be saved with an orientation that is compatible with FSL, where possible.
    static void
    Saves the user's preference about whether NIFTI-1 images should be saved with an orientation that is compatible with SPM, where possible.
    void
    setImageOrientationPositionPatient(org.jogamp.vecmath.Vector3f[] orientation, org.jogamp.vecmath.Point3f position, boolean force)
     
    Returns a String representation of this NIFTIHeader.
    toString(boolean html)
    Returns the string representation of this NIFTI-1 compliant image header, with optional presentation in HTML format.
    protected void
    Write the NIFTI extensions to an OutputStream.
    protected void
    Write the NIFTI extensions to a RandomAccessFile.

    Methods inherited from class com.xinapse.multisliceimage.Analyze.ANZHeader

    getDBName, getDescription, getMinMax, setDBName, setDims, setDims, setMinMax, setNCols, setNFrames, setNRows, setNSlices

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • SAVE_FSL_ORIENT_PROPERTY_KEY

      public static final String SAVE_FSL_ORIENT_PROPERTY_KEY
      The property value key for setting whether NIFTI-1 images should be saved with an orientation that is compatible with FSL, where possible.
      See Also:
    • SAVE_SPM_ORIENT_PROPERTY_KEY

      public static final String SAVE_SPM_ORIENT_PROPERTY_KEY
      The property value key for setting whether NIFTI-1 images should be saved with an orientation that is compatible with SPM, where possible.
      See Also:
    • FSL_COMPATIBLE_NIFTI_PROPERTY_KEY

      public static final String FSL_COMPATIBLE_NIFTI_PROPERTY_KEY
      The property value key for setting whether NIFTI-1 images that have qform and sform orientation both unset should be read as having an increasing a patient left coordinate value with stored pixel data column number, and whether NIFTI-1 images should be prevented from being written without orientation information.
      See Also:
    • DEFAULT_SAVE_FSL_ORIENT

      public static final boolean DEFAULT_SAVE_FSL_ORIENT
      The default setting of whether NIFTI-1 images should be saved with an orientation that is compatible with FSL, where possible.
      See Also:
    • DEFAULT_SAVE_SPM_ORIENT

      public static final boolean DEFAULT_SAVE_SPM_ORIENT
      The default setting of whether NIFTI-1 images should be saved with an orientation that is compatible with SPM, where possible.
      See Also:
    • DEFAULT_FSL_COMPATIBLE_NIFTI

      public static final boolean DEFAULT_FSL_COMPATIBLE_NIFTI
      The default setting of whether NIFTI-1 images that have qform and sform orientation both unset should be read as having an increasing a patient left coordinate value with stored pixel data column number, and whether NIFTI-1 images should be prevented from being written without orientation information.
      See Also:
    • qForm

      public NIFTIXForm qForm
      The NIFTI qform parameter. It is not recommended to manipulate this directly. Use the methods to set the image position and orientation in NIFTImage.
    • sForm

      public NIFTIXForm sForm
      The NIFTI sform parameter. It is not recommended to manipulate this directly. Use the methods to set the image position and orientation in NIFTImage.
    • quaternB

      public double quaternB
      The NIFTI quatern_b parameter. It is not recommended to manipulate this directly. Use the methods to set the image position and orientation in NIFTImage.
    • quaternC

      public double quaternC
      The NIFTI quatern_c parameter. It is not recommended to manipulate this directly. Use the methods to set the image position and orientation in NIFTImage.
    • quaternD

      public double quaternD
      The NIFTI quatern_d parameter. It is not recommended to manipulate this directly. Use the methods to set the image position and orientation in NIFTImage.
    • qOffsetX

      public double qOffsetX
      The NIFTI qoffset_x parameter. It is not recommended to manipulate this directly. Use the methods to set the image position and orientation in NIFTImage.
    • qOffsetY

      public double qOffsetY
      The NIFTI qoffset_y parameter. It is not recommended to manipulate this directly. Use the methods to set the image position and orientation in NIFTImage.
    • qOffsetZ

      public double qOffsetZ
      The NIFTI qoffset_z parameter. It is not recommended to manipulate this directly. Use the methods to set the image position and orientation in NIFTImage.
    • sRowX

      public double[] sRowX
      The NIFTI srow_x parameter. This is usually set using the method NIFTIImage.setSFormAffineTransform(AffineTransform3D).
    • sRowY

      public double[] sRowY
      The NIFTI srow_y parameter. This is usually set using the method NIFTIImage.setSFormAffineTransform(AffineTransform3D).
    • sRowZ

      public double[] sRowZ
      The NIFTI srow_z parameter. This is usually set using the method NIFTIImage.setSFormAffineTransform(AffineTransform3D).
    • magic

      protected byte[] magic
      The magic number that is used to differentiate NIFTI-1, NIFTI-2 and Analyze 7.5 images.
    • extension

      protected byte[] extension
      The NIFTI extension indicator, if present.
    • extData

      protected List<com.xinapse.multisliceimage.Analyze.ExtendedData> extData
      The extended data, if present.
  • Constructor Details

    • NIFTIHeader

      protected NIFTIHeader(boolean compressed)
      Creates a new NIFTIHeader.
      Parameters:
      compressed - whether the image should be compressed when written to disk.
    • NIFTIHeader

      protected NIFTIHeader(ANZPixFormat dataType, boolean compressed, Long... dims) throws ANZException
      Creates a new NIFTIHeader.
      Parameters:
      dataType - the ANZPixFormat for the pixel values.
      compressed - whether the image should be compressed when written to disk.
      dims - the image dimensions.
      Throws:
      ANZException - if the header cannot be created.
    • NIFTIHeader

      protected NIFTIHeader(NIFTIHeader header, boolean compressed) throws ANZException
      Creates a new NIFTI header, copying the information from an existing NIFTI header.
      Parameters:
      header - the NIFTIHeader to use as a template.
      compressed - true if the new header is to be compressed.
      Throws:
      ANZException - if the header cannot be created.
  • Method Details

    • getPreferredSaveFSLOrient

      public static boolean getPreferredSaveFSLOrient()
      Returns the user's preference about whether NIFTI-1 images should be saved with an orientation that is compatible with FSL, where possible. FSL is not able to correctly display images with an orientation that is not in the expected orientation. If interoperating with FSL, it may be necessary to save images in an FSL-friendly orientation. If not set in the user's preferences, then the default is to save NIFTI-1 images with a radiological orientation.

      If the system property "analyze.fslorient" exists, and the property value is either "true" or "false", then the user's preference is overridden by the property value.

      Returns:
      whether NIFTI-1 images should be saved with an orientation that is compatible with FSL, where possible.
    • savePreferredSaveFSLOrient

      public static void savePreferredSaveFSLOrient(boolean b)
      Saves the user's preference about whether NIFTI-1 images should be saved with an orientation that is compatible with FSL, where possible.
      Parameters:
      b - true if NIFTI-1 images should have an orientation that is compatible with FSL, where possible; false otherwise.
    • getPreferredSaveSPMOrient

      public static boolean getPreferredSaveSPMOrient()
      Returns the user's preference about whether NIFTI-1 images should be saved with an orientation that is compatible with SPM, where possible. SPM is not able to correctly display images with an orientation that is not in the expected orientation. If interoperating with SPM, it may be necessary to save images in an SPM-friendly orientation. If not set in the user's preferences, then the default is to save NIFTI-1 images with a radiological orientation.

      If the system property "analyze.spmorient" exists, and the property value is either "true" or "false", then the user's preference is overridden by the property value.

      Returns:
      whether NIFTI-1 images should be saved with an orientation that is compatible with SPM, where possible.
    • savePreferredSaveSPMOrient

      public static void savePreferredSaveSPMOrient(boolean b)
      Saves the user's preference about whether NIFTI-1 images should be saved with an orientation that is compatible with SPM, where possible.
      Parameters:
      b - true if NIFTI-1 images should have an orientation that is compatible with SPM, where possible; false otherwise.
    • getPreferredFSLCompatibleNIFTI

      public static boolean getPreferredFSLCompatibleNIFTI()
      Returns the user's preference about whether NIFTI-1 images with both qform and sform orientations unset should be read as having the patient left coordinate increasing with stored pixel data column number, and whether NIFTI-1 images should be prevented from being written without orientation information. This may be necessary if interoperating with FSL.

      If not set in the user's preferences, then the default is to interpret NIFTI-1 images as axial with an increasing patient right coordinate with increasing column number.

      If the system property "nifti.fslcompatible" exists, and the property value is either "true" or "false", then the user's preference is overridden by the property value.

      Returns:
      whether NIFTI-1 images with both qform and sform unset should be interpreted as having an increasing left coordinate with stored pixel data column number.
    • savePreferredFSLCompatibleNIFTI

      public static void savePreferredFSLCompatibleNIFTI(boolean b)
      Saves the user's preference about whether NIFTI-1 images should be read as having the patient left coordinate increasing with stored pixel data column number.
      Parameters:
      b - true if NIFTI-1 images should be read as having the patient left coordinate increasing with stored pixel data column number; false otherwise.
    • readExtensions

      protected void readExtensions(RandomAccessFile raf) throws IOException
      Read any NIFTI extensions from a RandomAccessFile.
      Parameters:
      raf - the RandomAccessFile from which to read the extensions.
      Throws:
      IOException - if an I/O error occurs.
    • readExtensions

      protected void readExtensions(InputStream s) throws IOException
      Read the NIFTI extensions from an InputStream.
      Parameters:
      s - the InputStream.
      Throws:
      IOException - if an I/O error occurs.
    • writeExtensions

      protected void writeExtensions(OutputStream s) throws IOException
      Write the NIFTI extensions to an OutputStream.
      Parameters:
      s - the OutputStream.
      Throws:
      IOException - if an I/O error occurs.
    • writeExtensions

      protected void writeExtensions(RandomAccessFile raf) throws IOException
      Write the NIFTI extensions to a RandomAccessFile.
      Parameters:
      raf - the RandomAccessFile.
      Throws:
      IOException - if an I/O error occurs.
    • getHeaderSize

      protected int getHeaderSize()
      Returns the size of this NIFTI (NIFTI-1 or NIFTI-2) header.
      Returns:
      the size of this NIFTI header.
    • setImageOrientationPositionPatient

      public void setImageOrientationPositionPatient(org.jogamp.vecmath.Vector3f[] orientation, org.jogamp.vecmath.Point3f position, boolean force)
    • toString

      public String toString()
      Returns a String representation of this NIFTIHeader.
      Overrides:
      toString in class ANZHeader
      Returns:
      a String describing this NIFTIHeader.
    • toString

      public String toString(boolean html)
      Returns the string representation of this NIFTI-1 compliant image header, with optional presentation in HTML format.
      Overrides:
      toString in class ANZHeader
      Parameters:
      html - if true, then the string will contain HTML tags.
      Returns:
      a String describing the header, optionally in HTML format.
    • clone

      public NIFTIHeader clone()
      Returns an exact copy of this NIFTI-1 header.
      Overrides:
      clone in class ANZHeader
      Returns:
      an exact copy of this NIFTIHeader instance.