Class TiffLoader

java.lang.Object
  extended by TiffLoader

public class TiffLoader
extends java.lang.Object

Class TiffLoader reads Tiff image into the class instance. variables.

 It uses class Raster when reading the image.
 All image data is expressed as a collection of pixels. Each pixel consists
 of a number of samples. A sample is a datum for one band of an image
 and a band consists of all samples of a particular type in an image. For
 example, a pixel might contain three samples representing its red, green
 and blue components. There are three bands in the image containing this
 pixel. One band consists of all the red samples from all pixels in the
 image. The second band consists of all the green samples and the 
 remaining band consists of all of the blue samples. The pixel can be 
 stored in various formats. For example, all samples from a particular
 band can be stored contiguously or all samples from a single pixel can
 be stored contiguously. In the Java 2D(tm) API, all built-in image 
 processing and display operators process samples which represent
 unsigned integral values.

 A collection of pixels is represented as a Raster, which consists of a
 DataBuffer and a SampleModel. The SampleModel allows access to samples 
 in the DataBuffer and may provide low-level information that a programmer
 can use to directly manipulate samples and pixels in the DataBuffer.

 This class is generally a fall back method for dealing with images. More
 efficient code will cast the SampleModel to the appropriate subclass and
 extract the information needed to directly manipulate pixels in the 
 DataBuffer.

 There is an option useLogInputFlag to add Log(grayscale) to take scaled
 log of grayscale data for maxBits>8-bits (e.g., 10-bits or 16-bits) for
 TIFF images prior to reading them. Scale log((2**nBitsPerPixel)-1) to 255:
   f'(g) = 255*log(g+1)/log((2**nBitsPerPixel)-1).

 This requires two JAI jar files: jai_core.jar and jai_codec.jar
 for TiffLoader.java to compile. These should be in the same class path
 as the Flicker.jar file.

Version:
$Date$ $Revision$
Author:
Jai Evans, CIT, NIH; Peter Lemkin, LECB/NCI, Frederick, MD
See Also:
http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/, See the SUN license file for JAI at these web sites.
This work was produced by Peter Lemkin of the National Cancer Institute, an agency of the United States Government. As a work of the United States Government there is no associated copyright. It is offered as open source software under the Mozilla Public License (version 1.1) subject to the limitations noted in the accompanying LEGAL file. This notice must be included with the code. The Flicker Mozilla and Legal files are available on http://open2dprot.sourceforge.net/Flicker

, Flicker Home Original: Date: 8-13-2003, Jai Evans.


Field Summary
private static boolean ALWAYS
          Fixed value of true for DEBUGGING
 boolean blackIsZeroFlag
          Black is Zero flag
 java.awt.image.ColorModel cm
           
static int count
          instance # of TiffLoader
 int dataType
          data type from sampleModel.getDataType() The types are defined as DataBuffer.TYPE_xxxx where xxxx is (BYTE, DOUBLE, FLOAT, INT, SHORT, UNDEFINED, USHORT)
private static boolean dbugFlag
          debugging flag
 ImageDecoder decoder
          Tiff Image Decoder
 java.lang.String fatalMsg
          Msg why failed if not null
 java.lang.String fileName
          filename path of image file
 float[] gray2OD
          [FUTURE] grayscale to OD lookup table [0:maxGray-1] if supplied as additional TIFF tags.
 java.awt.Image img
          Image structure required for Flicker
 boolean isComponentCMflag
          set if has ComponentColorModel
 boolean isComponentSMflag
          set if has ComponentSampleModel
 boolean isMultiplePixelPackedSMflag
          set if has a MultiplePixelPackedSampleModel
 boolean isPackedCMflag
          set if PackedColorModel
 boolean isPackedFlag
          set if pixel can be packed into a byte array
 boolean isRGBcolorImageFlag
          set if this is a RGB color image
 boolean isSinglePixelPackedSMflag
          set if has a SinglePixelPackedSampleModel
 int maxGray
          maximum gray value
 int minX
          X upper left hand corner of image origin
 int minY
          Y upper left hand corner of image origin
 int nBands
          # of samples/pixel
 int nBitsPerPixel
          # bits/pixel is sampleModel.sampleSize[0]
 int nCols
          # of columns in the image
private static boolean NEVER
          Fixed value of false for DEBUGGING
 int nPixels
          # of pixels/image (is nRows*nCols)
 int nRows
          # of rows in the image
 int numDataElements
          # raster DataBuffer data elements/pixel
 int numPages
          # of TIFF pages
 PixelAccessor[] pi
          List of PixelAccessors from the RenderedImages'
private  int[] pixels
          image of size nRows of nCols pixels.
 java.awt.image.Raster ras
          Raster image read
 java.awt.image.RenderedImage[] ri
          List of Rendered images that was read in the tiff file
 java.awt.image.SampleModel sampleModel
          Tiff sample model name
 int[] sampleSizes
          bits/pixel is sample sizes [0:nBands-1] from sampleModel.getSampleSize()
 boolean useLogInputFlag
          "Use log of pixels if > 8-bits grayscale image"
 
Constructor Summary
TiffLoader()
          TiffLoader() - constructor
TiffLoader(boolean flag)
          TiffLoader() - constructor where set the debug flag
 
Method Summary
 java.lang.String doTiffLoad(java.lang.String path, boolean checkCacheFlag)
          doTiffLoad() - load the image and array grab of TIFF files
 java.awt.Image getImage()
          getImage() - get pixels from the raster
 int getNbrRGBpixels(int[] pixels, int nPixels)
          getNbrRGBpixels() - test if red==green==blue for all pixels
 int[] getTiffPixels(java.awt.image.Raster r, boolean checkCacheFlag)
          getTiffPixels() - get pixels from the raster
 void getTiffProperties(java.awt.image.Raster r)
          getTiffProperties() - get properties of the Tiff image
static void main(java.lang.String[] args)
          main() - test loader.
 java.awt.image.RenderedImage[] readTiff(java.lang.String fileName)
          readTiff() - read a tiff image file
 void setDbugFlag(boolean flag)
          setDbugFlag() - flag
 void setUseLogFlag(boolean flag)
          setUseLogFlag() - flag to set the log flag This is used if the data has more than 8-bits of grayscale so the data is transformed by the log over the range of 255*log(10**nBits-1) to 0
 java.lang.String toString()
          toString() - return string representation of this instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ALWAYS

private static boolean ALWAYS
Fixed value of true for DEBUGGING


NEVER

private static boolean NEVER
Fixed value of false for DEBUGGING


dbugFlag

private static boolean dbugFlag
debugging flag


count

public static int count
instance # of TiffLoader


fileName

public java.lang.String fileName
filename path of image file


sampleModel

public java.awt.image.SampleModel sampleModel
Tiff sample model name


ri

public java.awt.image.RenderedImage[] ri
List of Rendered images that was read in the tiff file


pi

public PixelAccessor[] pi
List of PixelAccessors from the RenderedImages'


ras

public java.awt.image.Raster ras
Raster image read


decoder

public ImageDecoder decoder
Tiff Image Decoder


cm

public java.awt.image.ColorModel cm

nRows

public int nRows
# of rows in the image


nCols

public int nCols
# of columns in the image


minX

public int minX
X upper left hand corner of image origin


minY

public int minY
Y upper left hand corner of image origin


nBands

public int nBands
# of samples/pixel


numPages

public int numPages
# of TIFF pages


numDataElements

public int numDataElements
# raster DataBuffer data elements/pixel


pixels

private int[] pixels
image of size nRows of nCols pixels. This is either 8-bit, 16-bit, 24-bit RGB, etc. If the data is 8-bits, 12-bits or 16-bits then the (R,G,B) channels of the pixels[] array data are scaled to 8-bits and are set to be the same. [TODO] If the image is 24-bit (R,G,B) or an index-colormap 8-bit RGB, then set the (R,G,B) channels separately to preserve the colors.


img

public java.awt.Image img
Image structure required for Flicker


dataType

public int dataType
data type from sampleModel.getDataType() The types are defined as DataBuffer.TYPE_xxxx where xxxx is (BYTE, DOUBLE, FLOAT, INT, SHORT, UNDEFINED, USHORT)


sampleSizes

public int[] sampleSizes
bits/pixel is sample sizes [0:nBands-1] from sampleModel.getSampleSize()


isPackedFlag

public boolean isPackedFlag
set if pixel can be packed into a byte array


isPackedCMflag

public boolean isPackedCMflag
set if PackedColorModel


isComponentCMflag

public boolean isComponentCMflag
set if has ComponentColorModel


isComponentSMflag

public boolean isComponentSMflag
set if has ComponentSampleModel


isSinglePixelPackedSMflag

public boolean isSinglePixelPackedSMflag
set if has a SinglePixelPackedSampleModel


isMultiplePixelPackedSMflag

public boolean isMultiplePixelPackedSMflag
set if has a MultiplePixelPackedSampleModel


nBitsPerPixel

public int nBitsPerPixel
# bits/pixel is sampleModel.sampleSize[0]


nPixels

public int nPixels
# of pixels/image (is nRows*nCols)


blackIsZeroFlag

public boolean blackIsZeroFlag
Black is Zero flag


isRGBcolorImageFlag

public boolean isRGBcolorImageFlag
set if this is a RGB color image


gray2OD

public float[] gray2OD
[FUTURE] grayscale to OD lookup table [0:maxGray-1] if supplied as additional TIFF tags. Format specific....


maxGray

public int maxGray
maximum gray value


useLogInputFlag

public boolean useLogInputFlag
"Use log of pixels if > 8-bits grayscale image"


fatalMsg

public java.lang.String fatalMsg
Msg why failed if not null

Constructor Detail

TiffLoader

public TiffLoader()
TiffLoader() - constructor


TiffLoader

public TiffLoader(boolean flag)
TiffLoader() - constructor where set the debug flag

Method Detail

setDbugFlag

public void setDbugFlag(boolean flag)
setDbugFlag() - flag


setUseLogFlag

public void setUseLogFlag(boolean flag)
setUseLogFlag() - flag to set the log flag This is used if the data has more than 8-bits of grayscale so the data is transformed by the log over the range of 255*log(10**nBits-1) to 0


readTiff

public java.awt.image.RenderedImage[] readTiff(java.lang.String fileName)
                                        throws java.io.IOException
readTiff() - read a tiff image file

Parameters:
fileName - is the file to be read
Returns:
image rendered raster instance that may be an array of images
Throws:
java.io.IOException

getTiffPixels

public int[] getTiffPixels(java.awt.image.Raster r,
                           boolean checkCacheFlag)
getTiffPixels() - get pixels from the raster

Parameters:
r - is the image raster instance
checkCacheFlag - to see if pixels data exists, then return it
Returns:
1D array encoding a raster 2D image of size width X height.

getTiffProperties

public void getTiffProperties(java.awt.image.Raster r)
getTiffProperties() - get properties of the Tiff image

Parameters:
r - is the image raster instance

getImage

public java.awt.Image getImage()
getImage() - get pixels from the raster

Parameters:
r - is the image raster instance
Returns:
1D array encoding a raster 2D image of size width X height.

doTiffLoad

public java.lang.String doTiffLoad(java.lang.String path,
                                   boolean checkCacheFlag)
doTiffLoad() - load the image and array grab of TIFF files

Parameters:
path - of the image
checkCacheFlag - to see if pixels data exists, then return it
Returns:
null if succeed, else error message

getNbrRGBpixels

public int getNbrRGBpixels(int[] pixels,
                           int nPixels)
getNbrRGBpixels() - test if red==green==blue for all pixels

Returns:
# of color pixels. 0 means gray value image

toString

public java.lang.String toString()
toString() - return string representation of this instance

Overrides:
toString in class java.lang.Object
Returns:
string instance

main

public static void main(java.lang.String[] args)
main() - test loader. Replace hard code here with local path for testing