Package gov.nih.mipav.model.file
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:
FileIO,FileInfoTiff,FileRaw
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classFileSTK.IndexSimple class to store image offsets and bytes located at the offset.
-
Field Summary
Fields Modifier and Type Field Description static intASCIIDOCUMENT ME!static intBITS_PER_SAMPLEDOCUMENT ME!static intBYTETIFF Types.private byte[]byteBufferDOCUMENT ME!private booleanchunkyDOCUMENT ME!static intCOLOR_MAPDOCUMENT ME!static intCOMPRESSIONDOCUMENT ME!private java.util.Vector<FileSTK.Index>[]dataOffsetsstatic intDATE_TIMEDOCUMENT ME!private byte[]dateTimeDOCUMENT ME!private booleandoTileDOCUMENT ME!static intDOUBLEDOCUMENT ME!private booleanendianessDOCUMENT ME!private java.io.FilefileDOCUMENT ME!private java.lang.StringfileDirDOCUMENT ME!private FileInfoSTKfileInfoDOCUMENT ME!private java.lang.StringfileNameDOCUMENT ME!private FilePackBitfilePBDOCUMENT ME!private FileRawChunkfileRWDOCUMENT ME!static intFLOATDOCUMENT ME!private int[]IFDoffsetsDOCUMENT ME!private ModelImageimageDOCUMENT ME!static intIMAGE_DESCRIPTIONDOCUMENT ME!static intIMAGE_LENGTHDOCUMENT ME!static intIMAGE_WIDTHDOCUMENT ME!private byte[]imageDescriptionDOCUMENT ME!private intimageSliceDOCUMENT ME!private float[]imgBufferDOCUMENT ME!private float[]imgResolsDOCUMENT ME!static intLONGDOCUMENT ME!private ModelLUTLUTDOCUMENT ME!private intLUTOffsetDOCUMENT ME!static intMAX_SAMPLE_VALUEDOCUMENT ME!static intMIN_SAMPLE_VALUEDOCUMENT ME!private shortnDirEntriesDOCUMENT ME!static intNEW_SUBFILE_TYPETIFF Tags.private intnumberImagesDOCUMENT ME!private intoffsetConstantDOCUMENT ME!private booleanpackBitDOCUMENT ME!static intPHOTO_INTERPDOCUMENT ME!static intPLANAR_CONFIGDOCUMENT ME!private intplaneOffsetDOCUMENT ME!static intPREDICTORDOCUMENT ME!static intRATIONALDOCUMENT ME!static intRESOLUTION_UNITDOCUMENT ME!static intROWS_PER_STRIPDOCUMENT ME!static intSAMPLE_FORMATDOCUMENT ME!static intSAMPLES_PER_PIXELDOCUMENT ME!private intsamplesPerPixelDOCUMENT ME!static intSBYTEDOCUMENT ME!static intSHORTDOCUMENT ME!static intSLONGDOCUMENT ME!private byte[]softwareDOCUMENT ME!static intSOFTWAREDOCUMENT ME!static intSRATIONALDOCUMENT ME!static intSSHORTDOCUMENT ME!private java.lang.StringstrDOCUMENT ME!static intSTRIP_BYTE_COUNTSDOCUMENT ME!static intSTRIP_OFFSETSDOCUMENT ME!static intTILE_BYTE_COUNTSDOCUMENT ME!static intTILE_LENGTHDOCUMENT ME!static intTILE_OFFSETSDOCUMENT ME!static intTILE_WIDTHDOCUMENT ME!private int[]tileByteCountsDOCUMENT ME!private inttileByteNumberDOCUMENT ME!private inttileLengthDOCUMENT ME!private inttileOffsetNumberDOCUMENT ME!private int[]tileOffsetsDOCUMENT ME!private inttilesAcrossDOCUMENT ME!private inttilesDownDOCUMENT ME!private inttilesPerImageDOCUMENT ME!private inttilesPerSliceDOCUMENT ME!private int[]tileTempDOCUMENT ME!private inttileWidthDOCUMENT ME!private doubletResDOCUMENT ME!static intTRESOLUTIONDOCUMENT ME!static intUIC1TagDOCUMENT ME!static intUIC2TagDOCUMENT ME!static intUIC3TagDOCUMENT ME!static intUIC4TagDOCUMENT ME!static intUNDEFINEDDOCUMENT ME!private intxDimDOCUMENT ME!static intXRESOLUTIONDOCUMENT ME!private intyDimDOCUMENT ME!static intYRESOLUTIONDOCUMENT ME!private doublezResDOCUMENT ME!static intZRESOLUTIONEchoTech Tiff TAGS.-
Fields inherited from class gov.nih.mipav.model.file.FileBase
BIG_ENDIAN, bitsPerPixel, fileNames, LITTLE_ENDIAN, pBarVisible, raFile, READ, READ_WRITE
-
-
Constructor Summary
Constructors Constructor Description FileSTK(java.lang.String fileName, java.lang.String fileDir)STK reader/writer constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfinalize()Prepares this class for cleanup.FileInfoBasegetFileInfo()Accessor that returns the file info.float[]getImageBuffer()Accessor that returns the image buffer.ModelLUTgetModelLUT()Rreturns LUT if defined.private booleanopenIFD(FileInfoSTK fileInfo)Reads and decodes IFDs (Image File Directory).private voidreadBuffer(int slice, float[] buffer)Reads a slice of data at a time and stores the results in the buffer.ModelImagereadImage(boolean multiFile, boolean one)Reads the Tiff header which indicates endianess, the TIFF magic number, and the offset in bytes of the first IFD.private voidreadTileBuffer(int slice, float[] buffer)Reads a slice of data at a time and stores the results in the buffer.voidsetFileName(java.lang.String fName)Accessor to set the file name (used when reading TIFF multiFile).private voidwriteColorMap(int location)Writes color map to the TIFF file.private voidwriteHeader()Writes TIFF starting file header.private voidwriteIFD(int tag, int type, int count, int value, int value2)Writes one 12 byte IFD entry.private voidwriteIFDs(int imageOffset, int nextIFD, int index, int theStripCount, boolean writePackBit)Writes one IFD (Image File Directory).voidwriteImage(ModelImage image, ModelLUT LUT, FileWriteOptions options)This method writes a STK image file.-
Methods inherited from class gov.nih.mipav.model.file.FileBase
addProgressChangeListener, bytesToDouble, bytesToFloat, bytesToInt, bytesToShort, doubleToBytes, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, floatToBytes, getBufferDouble, getBufferFloat, getBufferInt, getBufferLong, getBufferShort, getBufferUShort, getDataType, getDouble, getFloat, getInt, getLong, getProgressChangeListeners, getRaFile, getSignedShort, getString, getUInt, getUnsignedByte, getUnsignedShort, intToBytes, isBigEndian, isProgressBarVisible, linkProgress, longToBytes, readDouble, readFloat, readInt, readLong, readShort, readString, readUnsignedShort, removeProgressChangeListener, setBigEndian, setBufferFloat, setBufferInt, setBufferLong, setBufferShort, setBufferString, setDataType, setEndianess, shortToBytes, writeBytes, writeDouble, writeFloat, writeInt, writeLong, writeShort
-
-
-
-
Field Detail
-
BYTE
public static final int BYTE
TIFF Types.- See Also:
- Constant Field Values
-
ASCII
public static final int ASCII
DOCUMENT ME!- See Also:
- Constant Field Values
-
SHORT
public static final int SHORT
DOCUMENT ME!- See Also:
- Constant Field Values
-
LONG
public static final int LONG
DOCUMENT ME!- See Also:
- Constant Field Values
-
RATIONAL
public static final int RATIONAL
DOCUMENT ME!- See Also:
- Constant Field Values
-
SBYTE
public static final int SBYTE
DOCUMENT ME!- See Also:
- Constant Field Values
-
UNDEFINED
public static final int UNDEFINED
DOCUMENT ME!- See Also:
- Constant Field Values
-
SSHORT
public static final int SSHORT
DOCUMENT ME!- See Also:
- Constant Field Values
-
SLONG
public static final int SLONG
DOCUMENT ME!- See Also:
- Constant Field Values
-
SRATIONAL
public static final int SRATIONAL
DOCUMENT ME!- See Also:
- Constant Field Values
-
FLOAT
public static final int FLOAT
DOCUMENT ME!- See Also:
- Constant Field Values
-
DOUBLE
public static final int DOUBLE
DOCUMENT ME!- See Also:
- Constant Field Values
-
NEW_SUBFILE_TYPE
public static final int NEW_SUBFILE_TYPE
TIFF Tags.- See Also:
- Constant Field Values
-
IMAGE_WIDTH
public static final int IMAGE_WIDTH
DOCUMENT ME!- See Also:
- Constant Field Values
-
IMAGE_LENGTH
public static final int IMAGE_LENGTH
DOCUMENT ME!- See Also:
- Constant Field Values
-
BITS_PER_SAMPLE
public static final int BITS_PER_SAMPLE
DOCUMENT ME!- See Also:
- Constant Field Values
-
COMPRESSION
public static final int COMPRESSION
DOCUMENT ME!- See Also:
- Constant Field Values
-
PHOTO_INTERP
public static final int PHOTO_INTERP
DOCUMENT ME!- See Also:
- Constant Field Values
-
IMAGE_DESCRIPTION
public static final int IMAGE_DESCRIPTION
DOCUMENT ME!- See Also:
- Constant Field Values
-
STRIP_OFFSETS
public static final int STRIP_OFFSETS
DOCUMENT ME!- See Also:
- Constant Field Values
-
SAMPLES_PER_PIXEL
public static final int SAMPLES_PER_PIXEL
DOCUMENT ME!- See Also:
- Constant Field Values
-
ROWS_PER_STRIP
public static final int ROWS_PER_STRIP
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
-
XRESOLUTION
public static final int XRESOLUTION
DOCUMENT ME!- See Also:
- Constant Field Values
-
YRESOLUTION
public static final int YRESOLUTION
DOCUMENT ME!- See Also:
- Constant Field Values
-
PLANAR_CONFIG
public static final int PLANAR_CONFIG
DOCUMENT ME!- See Also:
- Constant Field Values
-
RESOLUTION_UNIT
public static final int RESOLUTION_UNIT
DOCUMENT ME!- See Also:
- Constant Field Values
-
SOFTWARE
public static final int SOFTWARE
DOCUMENT ME!- See Also:
- Constant Field Values
-
DATE_TIME
public static final int DATE_TIME
DOCUMENT ME!- See Also:
- Constant Field Values
-
PREDICTOR
public static final int PREDICTOR
DOCUMENT ME!- See Also:
- Constant Field Values
-
COLOR_MAP
public static final int COLOR_MAP
DOCUMENT ME!- See Also:
- Constant Field Values
-
TILE_WIDTH
public static final int TILE_WIDTH
DOCUMENT ME!- See Also:
- Constant Field Values
-
TILE_LENGTH
public static final int TILE_LENGTH
DOCUMENT ME!- See Also:
- Constant Field Values
-
TILE_OFFSETS
public static final int TILE_OFFSETS
DOCUMENT ME!- See Also:
- Constant Field Values
-
TILE_BYTE_COUNTS
public static final int TILE_BYTE_COUNTS
DOCUMENT ME!- See Also:
- Constant Field Values
-
SAMPLE_FORMAT
public static final int SAMPLE_FORMAT
DOCUMENT ME!- See Also:
- Constant Field Values
-
UIC1Tag
public static final int UIC1Tag
DOCUMENT ME!- See Also:
- Constant Field Values
-
UIC2Tag
public static final int UIC2Tag
DOCUMENT ME!- See Also:
- Constant Field Values
-
UIC3Tag
public static final int UIC3Tag
DOCUMENT ME!- See Also:
- Constant Field Values
-
UIC4Tag
public static final int UIC4Tag
DOCUMENT ME!- See Also:
- Constant Field Values
-
ZRESOLUTION
public static final int ZRESOLUTION
EchoTech Tiff TAGS.- See Also:
- Constant Field Values
-
TRESOLUTION
public static final int TRESOLUTION
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!
-
fileInfo
private FileInfoSTK fileInfo
DOCUMENT ME!
-
fileName
private java.lang.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 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!
-
-
Method Detail
-
finalize
public void finalize()
Prepares this class for cleanup. Calls thefinalizemethod for existing elements, closes any open files and sets other elements tonull.
-
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-trueif a set of files each containing a separate 2D image is presentfalseif one file with either a 2D image or a stack of 2D imagesone- 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.IOExceptionReads a slice of data at a time and stores the results in the buffer.- Parameters:
slice- offset into the file stored in the dataOffset arraybuffer- 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.IOExceptionReads a slice of data at a time and stores the results in the buffer.- Parameters:
slice- image slicebuffer- 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.IOExceptionWrites 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.IOExceptionWrites 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.IOExceptionWrites 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.IOExceptionWrites one IFD (Image File Directory). One IFD per image- Parameters:
imageOffset- offset to next IFD. If equal to zero then end of imagesnextIFD- DOCUMENT ME!index- image index for file information.theStripCount- DOCUMENT ME!writePackBit- DOCUMENT ME!- Throws:
java.io.IOException- DOCUMENT ME!
-
-