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 class
FileSTK.Index
Simple class to store image offsets and bytes located at the offset.
-
Field Summary
Fields Modifier and Type Field Description static int
ASCII
DOCUMENT ME!static int
BITS_PER_SAMPLE
DOCUMENT ME!static int
BYTE
TIFF Types.private byte[]
byteBuffer
DOCUMENT ME!private boolean
chunky
DOCUMENT ME!static int
COLOR_MAP
DOCUMENT ME!static int
COMPRESSION
DOCUMENT ME!private java.util.Vector<FileSTK.Index>[]
dataOffsets
static int
DATE_TIME
DOCUMENT ME!private byte[]
dateTime
DOCUMENT ME!private boolean
doTile
DOCUMENT ME!static int
DOUBLE
DOCUMENT ME!private boolean
endianess
DOCUMENT ME!private java.io.File
file
DOCUMENT ME!private java.lang.String
fileDir
DOCUMENT ME!private FileInfoSTK
fileInfo
DOCUMENT ME!private java.lang.String
fileName
DOCUMENT ME!private FilePackBit
filePB
DOCUMENT ME!private FileRawChunk
fileRW
DOCUMENT ME!static int
FLOAT
DOCUMENT ME!private int[]
IFDoffsets
DOCUMENT ME!private ModelImage
image
DOCUMENT ME!static int
IMAGE_DESCRIPTION
DOCUMENT ME!static int
IMAGE_LENGTH
DOCUMENT ME!static int
IMAGE_WIDTH
DOCUMENT ME!private byte[]
imageDescription
DOCUMENT ME!private int
imageSlice
DOCUMENT ME!private float[]
imgBuffer
DOCUMENT ME!private float[]
imgResols
DOCUMENT ME!static int
LONG
DOCUMENT ME!private ModelLUT
LUT
DOCUMENT ME!private int
LUTOffset
DOCUMENT ME!static int
MAX_SAMPLE_VALUE
DOCUMENT ME!static int
MIN_SAMPLE_VALUE
DOCUMENT ME!private short
nDirEntries
DOCUMENT ME!static int
NEW_SUBFILE_TYPE
TIFF Tags.private int
numberImages
DOCUMENT ME!private int
offsetConstant
DOCUMENT ME!private boolean
packBit
DOCUMENT ME!static int
PHOTO_INTERP
DOCUMENT ME!static int
PLANAR_CONFIG
DOCUMENT ME!private int
planeOffset
DOCUMENT ME!static int
PREDICTOR
DOCUMENT ME!static int
RATIONAL
DOCUMENT ME!static int
RESOLUTION_UNIT
DOCUMENT ME!static int
ROWS_PER_STRIP
DOCUMENT ME!static int
SAMPLE_FORMAT
DOCUMENT ME!static int
SAMPLES_PER_PIXEL
DOCUMENT ME!private int
samplesPerPixel
DOCUMENT ME!static int
SBYTE
DOCUMENT ME!static int
SHORT
DOCUMENT ME!static int
SLONG
DOCUMENT ME!private byte[]
software
DOCUMENT ME!static int
SOFTWARE
DOCUMENT ME!static int
SRATIONAL
DOCUMENT ME!static int
SSHORT
DOCUMENT ME!private java.lang.String
str
DOCUMENT ME!static int
STRIP_BYTE_COUNTS
DOCUMENT ME!static int
STRIP_OFFSETS
DOCUMENT ME!static int
TILE_BYTE_COUNTS
DOCUMENT ME!static int
TILE_LENGTH
DOCUMENT ME!static int
TILE_OFFSETS
DOCUMENT ME!static int
TILE_WIDTH
DOCUMENT ME!private int[]
tileByteCounts
DOCUMENT ME!private int
tileByteNumber
DOCUMENT ME!private int
tileLength
DOCUMENT ME!private int
tileOffsetNumber
DOCUMENT ME!private int[]
tileOffsets
DOCUMENT ME!private int
tilesAcross
DOCUMENT ME!private int
tilesDown
DOCUMENT ME!private int
tilesPerImage
DOCUMENT ME!private int
tilesPerSlice
DOCUMENT ME!private int[]
tileTemp
DOCUMENT ME!private int
tileWidth
DOCUMENT ME!private double
tRes
DOCUMENT ME!static int
TRESOLUTION
DOCUMENT ME!static int
UIC1Tag
DOCUMENT ME!static int
UIC2Tag
DOCUMENT ME!static int
UIC3Tag
DOCUMENT ME!static int
UIC4Tag
DOCUMENT ME!static int
UNDEFINED
DOCUMENT ME!private int
xDim
DOCUMENT ME!static int
XRESOLUTION
DOCUMENT ME!private int
yDim
DOCUMENT ME!static int
YRESOLUTION
DOCUMENT ME!private double
zRes
DOCUMENT ME!static int
ZRESOLUTION
EchoTech 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 void
finalize()
Prepares this class for cleanup.FileInfoBase
getFileInfo()
Accessor that returns the file info.float[]
getImageBuffer()
Accessor that returns the image buffer.ModelLUT
getModelLUT()
Rreturns LUT if defined.private boolean
openIFD(FileInfoSTK fileInfo)
Reads and decodes IFDs (Image File Directory).private void
readBuffer(int slice, float[] buffer)
Reads a slice of data at a time and stores the results in the buffer.ModelImage
readImage(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 void
readTileBuffer(int slice, float[] buffer)
Reads a slice of data at a time and stores the results in the buffer.void
setFileName(java.lang.String fName)
Accessor to set the file name (used when reading TIFF multiFile).private void
writeColorMap(int location)
Writes color map to the TIFF file.private void
writeHeader()
Writes TIFF starting file header.private void
writeIFD(int tag, int type, int count, int value, int value2)
Writes one 12 byte IFD entry.private void
writeIFDs(int imageOffset, int nextIFD, int index, int theStripCount, boolean writePackBit)
Writes one IFD (Image File Directory).void
writeImage(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 thefinalize
method 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
-true
if a set of files each containing a separate 2D image is presentfalse
if 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.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 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.IOException
Reads 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.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 imagesnextIFD
- DOCUMENT ME!index
- image index for file information.theStripCount
- DOCUMENT ME!writePackBit
- DOCUMENT ME!- Throws:
java.io.IOException
- DOCUMENT ME!
-
-