Class NIFTI2Image

All Implemented Interfaces:
ReadableImage, WritableImage, InfoStorer, AutoCloseable, Cloneable

public class NIFTI2Image extends NIFTIImage implements InfoStorer, AutoCloseable
This class is a representation of a multi-dimensional image in the NIFTI-2 format, the updated NIFTI format.
  • Constructor Details

    • NIFTI2Image

      public NIFTI2Image()
      Creates an uninitialised instance of a NIFTI2Image. Needed so that newInstance() method can be called on the class.
    • NIFTI2Image

      public NIFTI2Image(long nCols, long nRows, long nSlices, long nFrames, ANZPixFormat dataType) throws ANZException, IOException
      Creates a new in-memory NIFTI2Image. This image exists in memory, and will only be written with an explicit write() method call.
      Parameters:
      nCols - the number of columns in the image x-direction.
      nRows - the number of rows in the image y-direction.
      nSlices - the number of slice in the image.
      nFrames - the number of frames (time points) in the image.
      dataType - the ANZPixFormat for the image.
      Throws:
      ANZException - if the image cannot be created.
      IOException - if an I/O error occurs.
    • NIFTI2Image

      public NIFTI2Image(ANZPixFormat dataType, Long... dims) throws ANZException, IOException
      Creates a new in-memory NIFTI2Image. This image exists in memory, and will only be written with an explicit write() method call.
      Parameters:
      dims - the number of samples in each of the image dimensions. The number of arguments supplied determines the dimensionality of the image.
      dataType - an ANZPixFormat.
      Throws:
      ANZException - if the header cannot be created.
      IOException - if an I/O error occurs.
    • NIFTI2Image

      public NIFTI2Image(NIFTIHeader hdr) throws ANZException, IOException
      Creates a new in-memory NIFTI2Image, using information from an existing NIFTIHeader. This image exists in memory, and will only be written with an explicit write() method call. The supplied NIFTIHeader object is cloned and can therefore be re-used.
      Parameters:
      hdr - the NIFTIHeader that will be used for dimensional information etc.
      Throws:
      ANZException - if the image cannot be created.
      IOException - if an I/O error occurs.
    • NIFTI2Image

      public NIFTI2Image(String fileName, long nCols, long nRows, long nSlices, long nFrames, ANZPixFormat dataType) throws IOException, ANZException
      Creates a new disk-based NIFTI2Image. After manipulation, a call to the close() method is necessary for any changes to be reflected on disk.
      Parameters:
      fileName - the root of the Analyze file name (i.e. without the ".img" or ".hdr" extension). If the fileName does have an extension, then this will be handled.
      nCols - the number of columns in the image x-direction.
      nRows - the number of rows in the image y-direction.
      nSlices - the number of slice in the image.
      nFrames - the number of frames (time points) in the image.
      dataType - the ANZPixFormat for the image.
      Throws:
      ANZException - if the NIFTI2Image cannot be instantiated.
      IOException - if an I/O error occurs.
    • NIFTI2Image

      public NIFTI2Image(String fileName, ANZPixFormat dataType, Long... dims) throws IOException, ANZException
      Creates a new disk-based NIFTI2Image. After manipulation, a call to the close() method is necessary for any changes to be reflected on disk.
      Parameters:
      fileName - the root of the NIFTI file name (i.e. without any ".img" ".hdr", ".nii", ".img.gz", ".hdr.gz" or ".nii.gz" extension). If the fileName does have an extension, then this will be handled gracefully.
      dataType - an ANZPixFormat.
      dims - the number of samples in each of the image dimensions. The number of arguments supplied determines the dimensionality of the image.
      Throws:
      ANZException - if the header cannot be created.
      IOException - if an I/O error occurs.
    • NIFTI2Image

      public NIFTI2Image(File f, NIFTI2Header header) throws IOException, ANZException
      Creates a new disk-based NIFTI2Image, using an existing header as a template for the new image. After manipulation, a call to the close() method is necessary for any changes to the header to be reflected on disk.
      Parameters:
      f - the File object that will form the root of the Analyze file name (i.e. without the ".hdr" extension). If f's name does have an extension, then this will be handled.
      header - the NIFTI2Header to use as the template.
      Throws:
      ANZException - if the new image cannot be created on disk.
      IOException - if an I/O error occurs.
    • NIFTI2Image

      public NIFTI2Image(String fileName, String mode) throws InvalidImageException, IOException, FileNotFoundException
      Opens an existing NIFTI2Image, with pixel data remaining on disk until requested.
      Parameters:
      fileName - the name of the image file.
      mode - the open mode. Can be either "r" (read-only) or "rw" (read-write).
      Throws:
      InvalidImageException - if the image cannot be opened or loaded, or if mode is invalid.
      FileNotFoundException - if the image file doesn't exist.
      IOException - if an I/O error occurs.
  • Method Details

    • getCommonName

      public static String getCommonName()
      Returns the common name for this type of image.
      Returns:
      the String "NIFTI-2".
    • main

      public static void main(String[] args)
      Run the self-test for the NIFTI2Image class.
      Parameters:
      args - a list of images to try to open.