Class 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:
    FileIO, FileInfoTiff, FileRaw
    • Field Detail

      • IMAGE_DESCRIPTION

        public static final int IMAGE_DESCRIPTION
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • SAMPLES_PER_PIXEL

        public static final int SAMPLES_PER_PIXEL
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • STRIP_BYTE_COUNTS

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

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

        public static final int MAX_SAMPLE_VALUE
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • TILE_BYTE_COUNTS

        public static final int TILE_BYTE_COUNTS
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • byteBuffer

        private byte[] byteBuffer
        DOCUMENT ME!
      • chunky

        private boolean chunky
        DOCUMENT ME!
      • dataOffsets

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

        private byte[] dateTime
        DOCUMENT ME!
      • doTile

        private boolean doTile
        DOCUMENT ME!
      • endianess

        private boolean endianess
        DOCUMENT ME!
      • file

        private java.io.File file
        DOCUMENT ME!
      • fileDir

        private java.lang.String fileDir
        DOCUMENT ME!
      • fileName

        private java.lang.String fileName
        DOCUMENT ME!
      • IFDoffsets

        private int[] IFDoffsets
        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 java.lang.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 Detail

      • FileSTK

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

      • 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 java.io.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:
        java.io.IOException - if there is an error reading the file
      • setFileName

        public void setFileName​(java.lang.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 java.io.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:
        java.io.IOException - if there is an error writing the file.
      • openIFD

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

        private void readBuffer​(int slice,
                                float[] buffer)
                         throws java.io.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:
        java.io.IOException - if there is an error reading the file
      • readTileBuffer

        private void readTileBuffer​(int slice,
                                    float[] buffer)
                             throws java.io.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:
        java.io.IOException - if there is an error reading the file
      • writeColorMap

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

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

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

        private void writeIFDs​(int imageOffset,
                               int nextIFD,
                               int index,
                               int theStripCount,
                               boolean writePackBit)
                        throws java.io.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:
        java.io.IOException - DOCUMENT ME!