Class ImageData

java.lang.Object
  extended by ImageData

public class ImageData
extends java.lang.Object

ImageData class supports image data object access. This is the top level data structure for a basic image object (left or right). It contains the input and output Image objects and input and output int[] pix arrays.

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

Version:
$Date$ $Revision$
Author:
P. Lemkin (LECB/NCI), G. Thornwall (SAIC), Frederick, MD
See Also:
Flicker Home

Field Summary
 java.awt.Image bcImg
          brightness contrast filtered image if used.
 boolean blackIsZeroFlag
          Is true if original input image has BLACK as gray value 0, else WHITE is gray value 0
 Boundary bnd
          This boundary boundary is ImageData specific.
 CalibrateOD calib
          calibration data is ImageData specific
(package private)  boolean doingTransform
          set by doXform, cleared by doneWithXform
 DrawHistogram dwCalHist
          generic Calibration popup histogram for image
 DrawHistogram dwHist
          generic ROI popup histogram for image
 long endTime
          ending time of last transform
 java.lang.String errStr
          last error message associated with obj
static Flicker flk
          Flicker global classes
 boolean hasODmapFlag
          Indicates that there is an valid mapGrayToOD map else if it was set to 1:1 the flag is set false.
 int[] hist
          Histogram of data [0:maxGray]
private  java.awt.image.IndexColorModel icm
          Index Color map
 ImageDataMeas idM
          Current measured circular mask spot for this image
 ImageDataROI idROI
          Region(s) Of Interest (ROI).
 ImageDataSpotList idSL
          Spot list (measured spots) for this image
 int iHeight
          height of original input image
 java.awt.Image iImg
          input image.
 java.lang.String imageFile
          full-path input image file name
 int IMG_TYPE_GIF
          GIF image type
 int IMG_TYPE_J2K
          [FUTURE] JPEG2000 image type.
 int IMG_TYPE_JPG
          JPEG image type
 int IMG_TYPE_PPX
          GELLAB-II PPX image type
 int IMG_TYPE_TIF
          TIFF image type
 int IMG_TYPE_UNKNOWN
          Unknown image type
 int imgType
          image type is one of IMG_TYPE_xxx
 int[] iPix
          For ImageXform and display - input image pixel data for display.
 boolean isClickableDBflag
          flag set if currently selected image is clickable
 boolean isColorImgFlag
          Is true if it is a color image where red!=green or red!=blue or when it is read in.
 int iWidth
          width of original input image
(package private)  double mag
          magnification factor
(package private)  float magVal
           
 float[] mapGrayToOD
          mapGrayToOD data if not null
 int maxG
          maximum Gray value seen in the original iPix[].
 int minG
          minimum Gray value seen in the original iPix[].
 int nBitsPerPixel
          # of bits/pixel.
 java.awt.Image oImg
          output image generated by ImageXform.
 int pixelMask
          bit mask to get the pixel (1 << nBitsPerPixel) -1
static boolean reportErrorMsgsFlag
          report errors on loading else ignore messages
 int runTimeMsec
          # of milli-seconds to process last transform
 long startTime
          starting time of last transform
 SliderState state
          SliderState threshold parameters associated with the image
(package private)  boolean threadIsPaintFlag
          Ok to paint ImageScroller
 java.lang.String title
          current title for image scroller associated with iData
 boolean userClickableImageDBflag
          User enabled image as clickable DB checkbox to get DB entry
static Util util
          extended Flicker state variable class
 int xObj
          Image current object mark
 int yObj
          Image current object mark
 java.awt.Image zImg
          ZoomMag filtered image if used.
 int zoomedHeight
          zoomed height
 int zoomedWidth
          zoomed width
(package private)  int zoomMagScr
          zoom value
 
Constructor Summary
ImageData()
          ImageData() - Constructor for extensions
ImageData(java.lang.String iName, java.awt.Image newImg, java.awt.Dimension iSize, boolean blackIsZeroFlag, float[] mapGrayToOD, Flicker flkS)
          ImageData() - Constructor.
 
Method Summary
 boolean applyNTSCrgb2grayTransform()
          applyNTSCrgb2grayTransform() - optionally convert RGT to grayscale for the iPix[] data.
 void changeImageData(java.lang.String iName, java.awt.Image newImg, java.awt.Dimension iSize, boolean blackIsZeroFlag, float[] mapGrayToOD)
          changeImageData() - change values of this ImageData object
 boolean checkAndMakeIpix(boolean reportErrorMsgsFlag)
          checkAndMakeIpix() - check & make iData.iPix if !exists.
 boolean checkAndMakeIpix(java.lang.String useXform, boolean reportErrorMsgsFlag)
          checkAndMakeIpix() - check & make iData.iPix if it does not exist.
static int cvtRGBvalToNTSCgrayVal(int rgbPixelVal)
          cvtRGBvalToNTSCgrayVal() - convert RGB value to NTSC grayscale value.
 java.awt.Image getImageForBCInput()
          getImageForBCInput() - get image for input to Brightness/Contrast filter.
 java.awt.Image getImageForDisplayInput()
          getImageForDisplayInput() - get image for input to display painting.
 java.awt.Image getImageForXformInput()
          getImageForXformInput() - get the image for input to image transform.
 java.awt.Image getImageForZoomInput()
          getImageForZoomInput() - get image for input to ZoomMag filter.
 int getImgType()
          getImgType() - get image type from IMG_TYPE_xxx
private static int[] getPixelDataFromImage(java.awt.Image img, int width, int height)
          getPixelDataFromImage() - get the pixel data from the image
 boolean isRGBcolorImage()
          isRGBcolorImage() - test if red!=green!=blue for any pixels
 ImageData loadBlankImageData(java.lang.String name, int w, int h)
          loadBlankImageData() - create and return a blank ImageData object [NOTE] This code has a bug since it does not create the empty window correctly.
 java.awt.Point mapStateToZoom(java.awt.Point XYobjToMap)
          mapStateToZoom() - map state point to zoomed/dezoomed point based on zoomMagVal.
 java.awt.Point mapZoomToState(java.awt.Point zoomedXYobjToMap)
          mapZoomToState() - map zoom point to state point based on zoomMagVal.
 java.awt.Point mapZoomToState(java.awt.Point zoomedXYobjToMap, int gw, int gh)
          mapZoomToState() - map zoom point to state point with Guard Region factored in.
 void printImgDebugState(java.lang.String msg)
          printImgDebugState() - Debugging print (iImg,oImg,zImg) object Java pointers.
 void printProperties(java.lang.String msg, java.awt.Image img, java.awt.Image zoomInputImg)
          printProperties() - Debugging print (iImg,oImg,zImg) object Java pointers, and img width & height.
 void resetImageData(boolean iImgFlushFlag)
          resetImageData() - reset this ImageData object.
static java.awt.Image resizeImageToTargetSize(java.awt.Image img, int w, int h, int minTargetSize, int maxTargetSize, int targetSize)
          resizeImageToTargetSize() - resize image to target size if the w or h is outside the range [minTargetSize : maxTargetSize].
 void setDefaultGrayscaleIndexColorMap()
          setDefaultGrayscaleIndexColorMap() - set the default grayscale colormap to a RGB IndexColorMap with all colors the same
 void setDefaultGrayscaleIndexColorMap(byte[] r, byte[] g, byte[] b)
          setDefaultGrayscaleIndexColorMap() - set the RGB IndexColorMap from (r,g,b) maps Note: see Hacking Java, pg 90 on cycling color palette [TODO] Update the display...
 void setOrigInputPixels(int[] origInputPixels, int nBitsPerPixel, boolean blackIsZeroFlag)
          setOrigInputPixels() - set the original image iPix[] pixels and associated flags.
 void setTitle(java.lang.String title)
          setTitle() - change the title for the ImageData instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

flk

public static Flicker flk
Flicker global classes


util

public static Util util
extended Flicker state variable class


IMG_TYPE_UNKNOWN

public final int IMG_TYPE_UNKNOWN
Unknown image type

See Also:
Constant Field Values

IMG_TYPE_GIF

public final int IMG_TYPE_GIF
GIF image type

See Also:
Constant Field Values

IMG_TYPE_JPG

public final int IMG_TYPE_JPG
JPEG image type

See Also:
Constant Field Values

IMG_TYPE_TIF

public final int IMG_TYPE_TIF
TIFF image type

See Also:
Constant Field Values

IMG_TYPE_PPX

public final int IMG_TYPE_PPX
GELLAB-II PPX image type

See Also:
Constant Field Values

IMG_TYPE_J2K

public final int IMG_TYPE_J2K
[FUTURE] JPEG2000 image type. Could possibly use JJ2000 at http://jj2000.epfl.ch/

See Also:
Constant Field Values

iImg

public java.awt.Image iImg
input image. This is the original image and does NOT change.


oImg

public java.awt.Image oImg
output image generated by ImageXform. If sequential transforms are used, then this will also be used for the next round of tranform as the input image and then replaced with the computed output image.


zImg

public java.awt.Image zImg
ZoomMag filtered image if used.


bcImg

public java.awt.Image bcImg
brightness contrast filtered image if used.


xObj

public int xObj
Image current object mark


yObj

public int yObj
Image current object mark


iWidth

public int iWidth
width of original input image


iHeight

public int iHeight
height of original input image


zoomedWidth

public int zoomedWidth
zoomed width


zoomedHeight

public int zoomedHeight
zoomed height


imgType

public int imgType
image type is one of IMG_TYPE_xxx


isColorImgFlag

public boolean isColorImgFlag
Is true if it is a color image where red!=green or red!=blue or when it is read in. This flag can then be tested if we want to map the (R,G,B) to NTSC(R,G,B) grayscale on a pixel level so we could quantify the color data.


blackIsZeroFlag

public boolean blackIsZeroFlag
Is true if original input image has BLACK as gray value 0, else WHITE is gray value 0


nBitsPerPixel

public int nBitsPerPixel
# of bits/pixel. E.g., 8, 12, 16 bits


pixelMask

public int pixelMask
bit mask to get the pixel (1 << nBitsPerPixel) -1


maxG

public int maxG
maximum Gray value seen in the original iPix[]. -1 means it is not defined.


minG

public int minG
minimum Gray value seen in the original iPix[]. -1 means it is not defined.


iPix

public int[] iPix
For ImageXform and display - input image pixel data for display. Although the original image can be 8, 12, 16-bits, it is scaled in the image loaders to 8-bits if it is a grayscale image. By default we get the 8-bit data from the LSB or blue 8-bit channel.


reportErrorMsgsFlag

public static boolean reportErrorMsgsFlag
report errors on loading else ignore messages


errStr

public java.lang.String errStr
last error message associated with obj


imageFile

public java.lang.String imageFile
full-path input image file name


startTime

public long startTime
starting time of last transform


endTime

public long endTime
ending time of last transform


runTimeMsec

public int runTimeMsec
# of milli-seconds to process last transform


userClickableImageDBflag

public boolean userClickableImageDBflag
User enabled image as clickable DB checkbox to get DB entry


isClickableDBflag

public boolean isClickableDBflag
flag set if currently selected image is clickable


icm

private java.awt.image.IndexColorModel icm
Index Color map


doingTransform

boolean doingTransform
set by doXform, cleared by doneWithXform


threadIsPaintFlag

boolean threadIsPaintFlag
Ok to paint ImageScroller


title

public java.lang.String title
current title for image scroller associated with iData


zoomMagScr

int zoomMagScr
zoom value


mag

double mag
magnification factor


magVal

float magVal

state

public SliderState state
SliderState threshold parameters associated with the image


bnd

public Boundary bnd
This boundary boundary is ImageData specific.


calib

public CalibrateOD calib
calibration data is ImageData specific


mapGrayToOD

public float[] mapGrayToOD
mapGrayToOD data if not null


hasODmapFlag

public boolean hasODmapFlag
Indicates that there is an valid mapGrayToOD map else if it was set to 1:1 the flag is set false.


hist

public int[] hist
Histogram of data [0:maxGray]


dwHist

public DrawHistogram dwHist
generic ROI popup histogram for image


dwCalHist

public DrawHistogram dwCalHist
generic Calibration popup histogram for image


idSL

public ImageDataSpotList idSL
Spot list (measured spots) for this image


idM

public ImageDataMeas idM
Current measured circular mask spot for this image


idROI

public ImageDataROI idROI
Region(s) Of Interest (ROI). Note that the ND step wedge ROI is kept in and maintained by calib.{ndcwx1,ndcwx2,ndcwy1,ndcwy2}

Constructor Detail

ImageData

public ImageData(java.lang.String iName,
                 java.awt.Image newImg,
                 java.awt.Dimension iSize,
                 boolean blackIsZeroFlag,
                 float[] mapGrayToOD,
                 Flicker flkS)
ImageData() - Constructor. Obj keeps all image data together. Assumption: image, widthA, heightA and iPixA must exist before the class instance is created. Note: newImg must exist completely in memory at this point. Setup up a 1:1 mapGrayToOD[0:maxGray] if mapGrayToOD is null.

Parameters:
iName - is name of image
newImg - is existing input image to setthis.iImg.
iSize - is size of image
blackIsZeroFlag - is true if image has black as 0 gray value
mapGrayToOD - is Map of Gray to OD if exists
flk - is instance of Flicker

ImageData

public ImageData()
ImageData() - Constructor for extensions

Method Detail

getImgType

public int getImgType()
getImgType() - get image type from IMG_TYPE_xxx

Returns:
image type

setTitle

public void setTitle(java.lang.String title)
setTitle() - change the title for the ImageData instance. You can do a temporary change or a permanent change.

Parameters:
title - to use

setDefaultGrayscaleIndexColorMap

public void setDefaultGrayscaleIndexColorMap(byte[] r,
                                             byte[] g,
                                             byte[] b)
setDefaultGrayscaleIndexColorMap() - set the RGB IndexColorMap from (r,g,b) maps Note: see Hacking Java, pg 90 on cycling color palette [TODO] Update the display...

Parameters:
r - is red map
g - is green map
b - is blue map

setDefaultGrayscaleIndexColorMap

public void setDefaultGrayscaleIndexColorMap()
setDefaultGrayscaleIndexColorMap() - set the default grayscale colormap to a RGB IndexColorMap with all colors the same


resetImageData

public void resetImageData(boolean iImgFlushFlag)
resetImageData() - reset this ImageData object. It does not change the name of the file, black is white flag nor mapGrayToOD.

Parameters:
iImgFlushFlag - to flush iImg if true

changeImageData

public void changeImageData(java.lang.String iName,
                            java.awt.Image newImg,
                            java.awt.Dimension iSize,
                            boolean blackIsZeroFlag,
                            float[] mapGrayToOD)
changeImageData() - change values of this ImageData object

Parameters:
iName - is name of image
newImg - is existing input image to set to this ImageData instance
iSize - is size of image
blackIsZeroFlag - is true if image has black as 0 gray value
mapGrayToOD - is Map of Gray to OD if exists and is not null

resizeImageToTargetSize

public static java.awt.Image resizeImageToTargetSize(java.awt.Image img,
                                                     int w,
                                                     int h,
                                                     int minTargetSize,
                                                     int maxTargetSize,
                                                     int targetSize)
resizeImageToTargetSize() - resize image to target size if the w or h is outside the range [minTargetSize : maxTargetSize]. We resize if we DO need to resize AND (targetSize!=0). Also keep the (h/w) aspect ratio the same.

Parameters:
img - is image to resize
w - is actual width
h - is actual height
minTargetSize - allowed
maxTargetSize - allowed
targetSize - to set the image to if resizing and it is not 0
Returns:
new image if had to resize it, else return the old image

getPixelDataFromImage

private static int[] getPixelDataFromImage(java.awt.Image img,
                                           int width,
                                           int height)
getPixelDataFromImage() - get the pixel data from the image

Parameters:
img - image to use
width - of image
height - of image
Returns:
int[] array of pixel data,

loadBlankImageData

public ImageData loadBlankImageData(java.lang.String name,
                                    int w,
                                    int h)
loadBlankImageData() - create and return a blank ImageData object [NOTE] This code has a bug since it does not create the empty window correctly. It could be called initially from flk.initialImageLoad() if the call to load an initial image using loadPixIntoImageData() fails.

Parameters:
name - of empty image to create
w - is width of empty image
h - is height of empty image
Returns:
ImageData instance

checkAndMakeIpix

public boolean checkAndMakeIpix(boolean reportErrorMsgsFlag)
checkAndMakeIpix() - check & make iData.iPix if !exists. This gets the generic iImg or oImg data.

Parameters:
reportErrorMsgsFlag - to report error it it occurs on load
Returns:
false if an error.

checkAndMakeIpix

public boolean checkAndMakeIpix(java.lang.String useXform,
                                boolean reportErrorMsgsFlag)
checkAndMakeIpix() - check & make iData.iPix if it does not exist. If we are zooming, it gets the zoom input else the image Xform image which could be either iImg or oImg (if the latter exists and the switches are set according to the getImageForXformInput() rules.

Parameters:
useXform - to check for "DeZoom" transform.
reportErrorMsgsFlag - to report error it it occurs on load
Returns:
false if an error.

isRGBcolorImage

public boolean isRGBcolorImage()
isRGBcolorImage() - test if red!=green!=blue for any pixels

Returns:
true if RGB color pixels.

cvtRGBvalToNTSCgrayVal

public static final int cvtRGBvalToNTSCgrayVal(int rgbPixelVal)
cvtRGBvalToNTSCgrayVal() - convert RGB value to NTSC grayscale value. The NTSC standard to convert RGB to Grayscale is grayscale = 0.33Red + 0.5Green + 0.17Blue.

Parameters:
rgbPixelVal -

applyNTSCrgb2grayTransform

public boolean applyNTSCrgb2grayTransform()
applyNTSCrgb2grayTransform() - optionally convert RGT to grayscale for the iPix[] data. If the iPix[] data is color RGB, then apply the NTSC rgb to grayscale transform to the iPix[] data.

First we recompute the isColorImgFlag status. If it is true, it is a color image where red!=green or red!=blue. This flag is then be tested if we want to map the (R,G,B) to NTSC(R,G,B) grayscale on a pixel level so we could quantify the color data.

This is only applied if the flk.useNTSCrgbTograyCvtFlag and the iData.isColorImgFlag was recomputed as true. It always computes (minG, maxG) for the iPix[] LSB 8-bit data (AFTER the NTSC conversion if required).

Returns:
true if did conversion, else false

getImageForXformInput

public java.awt.Image getImageForXformInput()
getImageForXformInput() - get the image for input to image transform. If are not allowing image transforms (i.e. !flk.allowXformFlag), then use the iImg. Otherwise, if we are composing output images (flk.composeXformFlag and oImg exists) then use oImg else iImg.

Returns:
the Image to use, else null if error

getImageForZoomInput

public java.awt.Image getImageForZoomInput()
getImageForZoomInput() - get image for input to ZoomMag filter. If allowing image transforms (i.e. flk.allowXformFlag) and oImg exists, then use oImg, else use iImg. Note: we do not care whether the oImg was composed or not - just whether it exists!

Returns:
the Image to use, else null if error

getImageForBCInput

public java.awt.Image getImageForBCInput()
getImageForBCInput() - get image for input to Brightness/Contrast filter. If zImg exists, then use that. Else if we are allowing image transforms (i.e. flk.allowXformFlag) and oImg exists, then use oImg, else use iImg. Note: if change flk.allowXformFlag status, MUST resync zImg if zoomMagVal is not 1.0X since different data source.

Returns:
the Image to use, else null if error

getImageForDisplayInput

public java.awt.Image getImageForDisplayInput()
getImageForDisplayInput() - get image for input to display painting. If bcImg exists, then use it. Else if zImg exists, then use that. Else if we are allowing image transforms (i.e. flk.allowXformFlag) and oImg exists, then use oImg, else use iImg.

Returns:
the Image to use, else null if error

printImgDebugState

public void printImgDebugState(java.lang.String msg)
printImgDebugState() - Debugging print (iImg,oImg,zImg) object Java pointers. This is useful for debugging transforms etc.

Parameters:
msg - - to print if any

setOrigInputPixels

public final void setOrigInputPixels(int[] origInputPixels,
                                     int nBitsPerPixel,
                                     boolean blackIsZeroFlag)
setOrigInputPixels() - set the original image iPix[] pixels and associated flags.

Parameters:
origInputPixels - is the original pixels array data
nBitsPerPixel - is # bits/pixel in the original pixels
blackIsZeroFlag - is true if original input image has BLACK as gray value 0, else WHITE is gray value 0

printProperties

public void printProperties(java.lang.String msg,
                            java.awt.Image img,
                            java.awt.Image zoomInputImg)
printProperties() - Debugging print (iImg,oImg,zImg) object Java pointers, and img width & height. This is useful for debugging transforms etc.

Parameters:
msg - - to print if any
img - - to print if any
zoomInputImg - - to print if any

mapStateToZoom

public java.awt.Point mapStateToZoom(java.awt.Point XYobjToMap)
mapStateToZoom() - map state point to zoomed/dezoomed point based on zoomMagVal. This can be used for remapping overlays.

Parameters:
mappedXYobj - to use if not null, else create one.
Returns:
zoomed point

mapZoomToState

public java.awt.Point mapZoomToState(java.awt.Point zoomedXYobjToMap,
                                     int gw,
                                     int gh)
mapZoomToState() - map zoom point to state point with Guard Region factored in. This can be used for remapping overlays.

Parameters:
mappedXYobj - to use if not null, else create one.
gw - guard width
gh - guard height
Returns:
zoomed point, -1 if out of bounds

mapZoomToState

public java.awt.Point mapZoomToState(java.awt.Point zoomedXYobjToMap)
mapZoomToState() - map zoom point to state point based on zoomMagVal. This can be used for remapping overlays.

Parameters:
mappedXYobj - to use if not null, else create one.
Returns:
zoomed point, -1 if out of bounds