Class FileSTK

java.lang.Object
gov.nih.mipav.model.file.FileBase
gov.nih.mipav.model.file.FileSTK

public class FileSTK extends FileBase
The MetaMorph Stack (STK) file format is derived from the TIFF format. Note that the IMAGE_DESCRIPTION and STRIP_OFFSETS tags are handled differently in STK file format than in TIFF file format. Also note that the UIC1Tag, UIC2Tag, UIC3Tag, and UIC4Tag are found in STK but not in TIFF. While TIFF files can be either big-endian or little-endian, STK files must be little endian. Only packed bit compression is supported at this time. Note that although EchoTech has a tResolution field, there is no provision for 4D in TIFF.
See Also:
  • Field Details

    • BYTE

      public static final int BYTE
      TIFF Types.
      See Also:
    • ASCII

      public static final int ASCII
      DOCUMENT ME!
      See Also:
    • SHORT

      public static final int SHORT
      DOCUMENT ME!
      See Also:
    • LONG

      public static final int LONG
      DOCUMENT ME!
      See Also:
    • RATIONAL

      public static final int RATIONAL
      DOCUMENT ME!
      See Also:
    • SBYTE

      public static final int SBYTE
      DOCUMENT ME!
      See Also:
    • UNDEFINED

      public static final int UNDEFINED
      DOCUMENT ME!
      See Also:
    • SSHORT

      public static final int SSHORT
      DOCUMENT ME!
      See Also:
    • SLONG

      public static final int SLONG
      DOCUMENT ME!
      See Also:
    • SRATIONAL

      public static final int SRATIONAL
      DOCUMENT ME!
      See Also:
    • FLOAT

      public static final int FLOAT
      DOCUMENT ME!
      See Also:
    • DOUBLE

      public static final int DOUBLE
      DOCUMENT ME!
      See Also:
    • NEW_SUBFILE_TYPE

      public static final int NEW_SUBFILE_TYPE
      TIFF Tags.
      See Also:
    • IMAGE_WIDTH

      public static final int IMAGE_WIDTH
      DOCUMENT ME!
      See Also:
    • IMAGE_LENGTH

      public static final int IMAGE_LENGTH
      DOCUMENT ME!
      See Also:
    • BITS_PER_SAMPLE

      public static final int BITS_PER_SAMPLE
      DOCUMENT ME!
      See Also:
    • COMPRESSION

      public static final int COMPRESSION
      DOCUMENT ME!
      See Also:
    • PHOTO_INTERP

      public static final int PHOTO_INTERP
      DOCUMENT ME!
      See Also:
    • IMAGE_DESCRIPTION

      public static final int IMAGE_DESCRIPTION
      DOCUMENT ME!
      See Also:
    • STRIP_OFFSETS

      public static final int STRIP_OFFSETS
      DOCUMENT ME!
      See Also:
    • SAMPLES_PER_PIXEL

      public static final int SAMPLES_PER_PIXEL
      DOCUMENT ME!
      See Also:
    • ROWS_PER_STRIP

      public static final int ROWS_PER_STRIP
      DOCUMENT ME!
      See Also:
    • STRIP_BYTE_COUNTS

      public static final int STRIP_BYTE_COUNTS
      DOCUMENT ME!
      See Also:
    • MIN_SAMPLE_VALUE

      public static final int MIN_SAMPLE_VALUE
      DOCUMENT ME!
      See Also:
    • MAX_SAMPLE_VALUE

      public static final int MAX_SAMPLE_VALUE
      DOCUMENT ME!
      See Also:
    • XRESOLUTION

      public static final int XRESOLUTION
      DOCUMENT ME!
      See Also:
    • YRESOLUTION

      public static final int YRESOLUTION
      DOCUMENT ME!
      See Also:
    • PLANAR_CONFIG

      public static final int PLANAR_CONFIG
      DOCUMENT ME!
      See Also:
    • RESOLUTION_UNIT

      public static final int RESOLUTION_UNIT
      DOCUMENT ME!
      See Also:
    • SOFTWARE

      public static final int SOFTWARE
      DOCUMENT ME!
      See Also:
    • DATE_TIME

      public static final int DATE_TIME
      DOCUMENT ME!
      See Also:
    • PREDICTOR

      public static final int PREDICTOR
      DOCUMENT ME!
      See Also:
    • COLOR_MAP

      public static final int COLOR_MAP
      DOCUMENT ME!
      See Also:
    • TILE_WIDTH

      public static final int TILE_WIDTH
      DOCUMENT ME!
      See Also:
    • TILE_LENGTH

      public static final int TILE_LENGTH
      DOCUMENT ME!
      See Also:
    • TILE_OFFSETS

      public static final int TILE_OFFSETS
      DOCUMENT ME!
      See Also:
    • TILE_BYTE_COUNTS

      public static final int TILE_BYTE_COUNTS
      DOCUMENT ME!
      See Also:
    • SAMPLE_FORMAT

      public static final int SAMPLE_FORMAT
      DOCUMENT ME!
      See Also:
    • UIC1Tag

      public static final int UIC1Tag
      DOCUMENT ME!
      See Also:
    • UIC2Tag

      public static final int UIC2Tag
      DOCUMENT ME!
      See Also:
    • UIC3Tag

      public static final int UIC3Tag
      DOCUMENT ME!
      See Also:
    • UIC4Tag

      public static final int UIC4Tag
      DOCUMENT ME!
      See Also:
    • ZRESOLUTION

      public static final int ZRESOLUTION
      EchoTech Tiff TAGS.
      See Also:
    • TRESOLUTION

      public static final int TRESOLUTION
      DOCUMENT ME!
      See Also:
    • byteBuffer

      private byte[] byteBuffer
      DOCUMENT ME!
    • chunky

      private boolean chunky
      DOCUMENT ME!
    • dataOffsets

      private Vector<FileSTK.Index>[] dataOffsets
    • dateTime

      private byte[] dateTime
      DOCUMENT ME!
    • doTile

      private boolean doTile
      DOCUMENT ME!
    • endianess

      private boolean endianess
      DOCUMENT ME!
    • file

      private File file
      DOCUMENT ME!
    • fileDir

      private String fileDir
      DOCUMENT ME!
    • fileInfo

      private FileInfoSTK fileInfo
      DOCUMENT ME!
    • fileName

      private String fileName
      DOCUMENT ME!
    • filePB

      private FilePackBit filePB
      DOCUMENT ME!
    • fileRW

      private FileRawChunk fileRW
      DOCUMENT ME!
    • IFDoffsets

      private int[] IFDoffsets
      DOCUMENT ME!
    • image

      private ModelImage image
      DOCUMENT ME!
    • imageDescription

      private byte[] imageDescription
      DOCUMENT ME!
    • imageSlice

      private int imageSlice
      DOCUMENT ME!
    • imgBuffer

      private float[] imgBuffer
      DOCUMENT ME!
    • imgResols

      private float[] imgResols
      DOCUMENT ME!
    • LUT

      private ModelLUT LUT
      DOCUMENT ME!
    • LUTOffset

      private int LUTOffset
      DOCUMENT ME!
    • nDirEntries

      private short nDirEntries
      DOCUMENT ME!
    • numberImages

      private int numberImages
      DOCUMENT ME!
    • offsetConstant

      private int offsetConstant
      DOCUMENT ME!
    • packBit

      private boolean packBit
      DOCUMENT ME!
    • planeOffset

      private int planeOffset
      DOCUMENT ME!
    • samplesPerPixel

      private int samplesPerPixel
      DOCUMENT ME!
    • software

      private byte[] software
      DOCUMENT ME!
    • str

      private String str
      DOCUMENT ME!
    • tileByteCounts

      private int[] tileByteCounts
      DOCUMENT ME!
    • tileByteNumber

      private int tileByteNumber
      DOCUMENT ME!
    • tileLength

      private int tileLength
      DOCUMENT ME!
    • tileOffsetNumber

      private int tileOffsetNumber
      DOCUMENT ME!
    • tileOffsets

      private int[] tileOffsets
      DOCUMENT ME!
    • tilesAcross

      private int tilesAcross
      DOCUMENT ME!
    • tilesDown

      private int tilesDown
      DOCUMENT ME!
    • tilesPerImage

      private int tilesPerImage
      DOCUMENT ME!
    • tilesPerSlice

      private int tilesPerSlice
      DOCUMENT ME!
    • tileTemp

      private int[] tileTemp
      DOCUMENT ME!
    • tileWidth

      private int tileWidth
      DOCUMENT ME!
    • tRes

      private double tRes
      DOCUMENT ME!
    • xDim

      private int xDim
      DOCUMENT ME!
    • yDim

      private int yDim
      DOCUMENT ME!
    • zRes

      private double zRes
      DOCUMENT ME!
  • Constructor Details

    • FileSTK

      public FileSTK(String fileName, String fileDir) throws IOException
      STK reader/writer constructor.
      Parameters:
      fileName - file name
      fileDir - file directory
      Throws:
      IOException - if there is an error making the file
  • Method Details

    • finalize

      public void finalize()
      Prepares this class for cleanup. Calls the finalize method for existing elements, closes any open files and sets other elements to null.
      Overrides:
      finalize in class FileBase
    • getFileInfo

      public FileInfoBase getFileInfo()
      Accessor that returns the file info.
      Returns:
      FileInfoBase containing the file info
    • getImageBuffer

      public float[] getImageBuffer()
      Accessor that returns the image buffer.
      Returns:
      buffer of image.
    • getModelLUT

      public ModelLUT getModelLUT()
      Rreturns LUT if defined.
      Returns:
      the LUT if defined else it is null
    • readImage

      public ModelImage readImage(boolean multiFile, boolean one) throws IOException
      Reads the Tiff header which indicates endianess, the TIFF magic number, and the offset in bytes of the first IFD. It then reads all the IFDs. This method then opens a Model of an image and imports the the images one slice at a time. Image slices are separated by an IFD.
      Parameters:
      multiFile - true if a set of files each containing a separate 2D image is present false if one file with either a 2D image or a stack of 2D images
      one - DOCUMENT ME!
      Returns:
      returns the image
      Throws:
      IOException - if there is an error reading the file
    • setFileName

      public void setFileName(String fName)
      Accessor to set the file name (used when reading TIFF multiFile).
      Parameters:
      fName - file name of image to read.
    • writeImage

      public void writeImage(ModelImage image, ModelLUT LUT, FileWriteOptions options) throws IOException
      This method writes a STK image file.
      Parameters:
      image - image model where the data is stored.
      LUT - LUT to be saved with image if not null.
      options - DOCUMENT ME!
      Throws:
      IOException - if there is an error writing the file.
    • openIFD

      private boolean openIFD(FileInfoSTK fileInfo) throws IOException
      Reads and decodes IFDs (Image File Directory).
      Parameters:
      fileInfo - DOCUMENT ME!
      Returns:
      DOCUMENT ME!
      Throws:
      IOException - if there is an error reading the file
    • readBuffer

      private void readBuffer(int slice, float[] buffer) throws IOException
      Reads a slice of data at a time and stores the results in the buffer.
      Parameters:
      slice - offset into the file stored in the dataOffset array
      buffer - buffer where the info is stored
      Throws:
      IOException - if there is an error reading the file
    • readTileBuffer

      private void readTileBuffer(int slice, float[] buffer) throws IOException
      Reads a slice of data at a time and stores the results in the buffer.
      Parameters:
      slice - image slice
      buffer - buffer where the info is stored
      Throws:
      IOException - if there is an error reading the file
    • writeColorMap

      private void writeColorMap(int location) throws IOException
      Writes color map to the TIFF file.
      Parameters:
      location - Location to write at.
      Throws:
      IOException - DOCUMENT ME!
    • writeHeader

      private void writeHeader() throws IOException
      Writes TIFF starting file header.
      Throws:
      IOException - DOCUMENT ME!
    • writeIFD

      private void writeIFD(int tag, int type, int count, int value, int value2) throws IOException
      Writes one 12 byte IFD entry.
      Parameters:
      tag - DOCUMENT ME!
      type - DOCUMENT ME!
      count - DOCUMENT ME!
      value - DOCUMENT ME!
      value2 - DOCUMENT ME!
      Throws:
      IOException - DOCUMENT ME!
    • writeIFDs

      private void writeIFDs(int imageOffset, int nextIFD, int index, int theStripCount, boolean writePackBit) throws IOException
      Writes one IFD (Image File Directory). One IFD per image
      Parameters:
      imageOffset - offset to next IFD. If equal to zero then end of images
      nextIFD - DOCUMENT ME!
      index - image index for file information.
      theStripCount - DOCUMENT ME!
      writePackBit - DOCUMENT ME!
      Throws:
      IOException - DOCUMENT ME!