jsky.image
Class ImageProcessor

java.lang.Object
  extended by jsky.image.ImageProcessor

public class ImageProcessor
extends java.lang.Object

Responsible for processing images before they are displayed, including setting cut levels and manipulating colors and lookup tables.

Version:
$Revision: 1.3 $
Author:
Allan Brighton

Field Summary
static int DEFAULT_X_PERIOD
          The default number of X pixels to skip for histograms and statistics
static int DEFAULT_Y_PERIOD
          The default number of Y pixels to skip for histograms and statistics
 
Constructor Summary
ImageProcessor()
          Default constructor.
ImageProcessor(javax.media.jai.PlanarImage sourceImage, java.awt.geom.Rectangle2D.Double region)
          Constructor.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener l)
          register to receive change events from this object whenever the image or cut levels are changed.
 void autoSetCutLevels(double percent, java.awt.geom.Rectangle2D.Double region)
          Set the cut levels so that the given percent of pixels in the given region of the image are within the low and high cut values.
 void autoSetCutLevels(java.awt.geom.Rectangle2D.Double region)
          Set the image cut levels automatically using median filtering on the given area of the image.
protected  void calculateImageStatistics(java.awt.geom.Rectangle2D.Double region)
          Examine the given region of the source image to determine the min and max pixel values as well as the default cut levels (using median filter).
 void copySettings(ImageProcessor ip)
          Copy the settings from the given ImageProcessor to this one.
protected  void fireChange(ImageChangeEvent changeEvent)
          Notify any listeners of a change in the image or cut levels.
 double getAngle()
          Return the rotation angle.
 float getBlank()
          Return the value used for bad or blank pixels (taken from "BLANK" image property).
 javax.media.jai.LookupTableJAI getColorLookupTable()
          Return the current lookup table used to add color to a grayscale image.
 java.lang.String getColorLookupTableName()
          Return the name of the current color lookup table
 javax.media.jai.PlanarImage getDisplayImage()
          Returns the current display image.
 boolean getFlipX()
          Return the value of the flipX flag.
 boolean getFlipY()
          Return the value of the flipY flag.
 double getHighCut()
          Get the high cutoff level
 javax.media.jai.Histogram getHistogram(int size, javax.media.jai.ROI roi)
          Return a histogram for the image with the given size (number of bins) and region of interest and default settings for the other arguments.
 java.lang.String getIntensityLookupTableName()
          Return the name of the current intensity lookup table
 javax.media.jai.Interpolation getInterpolation()
          Return the type of interpolation to use (for rotating).
 double getLowCut()
          Get the low cutoff level
 double getMaxValue()
          Return the max pixel value in the region specified in the last call to calculateImageStatistics.
 double getMinValue()
          Return the min pixel value in the region specified in the last call to calculateImageStatistics.
 java.lang.String getName()
          Return the name of this object
 javax.media.jai.PlanarImage getRescaledSourceImage()
          Returns the current source image, after applying BZERO and BSCALE, if needed.
 boolean getReverseY()
          Return the value of the reverseY flag.
 int getScaleAlgorithm()
          Return the current image scaling algorithm (one of the constants defined in the ImageLookup class (default: ImageLookup.LINEAR_SCALE).
 javax.media.jai.LookupTableJAI getScaleLookupTable()
          Return the lookup table used to scale the image to byte range
 javax.media.jai.PlanarImage getSourceImage()
          Returns the current source image.
 boolean isInvertedYAxis()
          Return true if the Y axis of the image was inverted while reading.
protected  boolean isUpdatePending()
          Return true if something was changed and a call to update() is needed.
 boolean isUserSetCutLevels()
          Return true if the user has set the cut levels and they were not automatically set.
 void removeChangeListener(javax.swing.event.ChangeListener l)
          Stop receiving change events from this object.
protected  javax.media.jai.PlanarImage rescaleImage(javax.media.jai.PlanarImage im)
          Rescale the given image, if needed, using the given factor and offset and return the result.
 void resetColormap()
          Reset the colormap to the default.
protected  javax.media.jai.PlanarImage rotate(javax.media.jai.PlanarImage im)
          Rotate the image about the center by the specified angle (in radians).
 void rotateColormap(int amount)
          Rotate the colormap by the given amount.
 void saveColormap()
          Save the current colormap state for the next shift, rotate or scale operation.
 void scaleColormap(int amount)
          Scale the colormap by the given amount.
 void setAngle(double angle)
          Set the rotation angle.
 void setColorLookupTable(java.lang.String name)
          Create a color RGB lookup table that can be added to the image processing chain, so that we can manipulate the image colors.
 void setCutLevels(double lowCut, double highCut)
          Set the image cutoff levels.
 void setCutLevels(double lowCut, double highCut, boolean userSetCutLevels)
          Set the image cutoff levels.
 void setDefaultColormap()
          Reset the colormap to the default.
 void setFlipX(boolean flipX)
          Set the value of the flipX flag.
 void setFlipY(boolean flipY)
          Set the value of the flipY flag.
 void setHighCut(double highCut)
          Set the high cutoff level
 void setIntensityLookupTable(java.lang.String name)
          Create an intensity lookup table that can be added to the image processing chain to rearrange the order of the colors in the colormap.
 void setInterpolation(javax.media.jai.Interpolation i)
          Set the type of interpolation to use (for rotating).
 void setInvertedYAxis(boolean invertedYAxis)
          Set to true if the Y axis of the image was inverted while reading.
 void setLowCut(double lowCut)
          Set the low cutoff level
 void setName(java.lang.String name)
          Set the name to use for this object (for testing and debugging).
protected  void setRegionOfInterest(java.awt.geom.Rectangle2D.Double region)
          Set the current region of interest in the image (normally the currently visible area).
 void setReverseY(boolean reverseY)
          Set the value of the reverseY flag.
 void setScaleAlgorithm(int scaleAlgorithm)
          Set the algorithm to use to scale the image to byte range.
 void setSourceImage(javax.media.jai.PlanarImage sourceImage, ImageProcessor imageProcessor)
          Set the source image and copy all of the image processing settings from the given ImageProcessor object.
 void setSourceImage(javax.media.jai.PlanarImage sourceImage, java.awt.geom.Rectangle2D.Double region)
          Set the source image and the region of interest and perform any requested image processing to make the display image.
protected  javax.media.jai.PlanarImage setTrans(javax.media.jai.PlanarImage im)
          Perform a transpose operation on the given image using the current rotate, flipX and flipY settings and return the resulting image.
protected  void setUpdatePending(boolean b)
          Set to true if something was changed and a call to update() is needed.
 void setUserSetCutLevels(boolean b)
          Set to true if the user has set the cut levels and they were not automatically set.
 void shiftColormap(int amount)
          Shift the colormap by the given amount.
 void toggleFlipX()
          Toggle the flipping of the X axis
 void toggleFlipY()
          Toggle the flipping of the Y axis
 void update()
          Process the source image, adding a lookup table and setting appropriate cut levels where needed to improve visibility.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_X_PERIOD

public static final int DEFAULT_X_PERIOD
The default number of X pixels to skip for histograms and statistics

See Also:
Constant Field Values

DEFAULT_Y_PERIOD

public static final int DEFAULT_Y_PERIOD
The default number of Y pixels to skip for histograms and statistics

See Also:
Constant Field Values
Constructor Detail

ImageProcessor

public ImageProcessor()
Default constructor. Call setSourceImage(PlanarImage, Rectangle2D.Double) to set the image to process and the region of interest.


ImageProcessor

public ImageProcessor(javax.media.jai.PlanarImage sourceImage,
                      java.awt.geom.Rectangle2D.Double region)
Constructor.

Parameters:
sourceImage - The source image to process.
region - the region of interest in the image (usually the visible area) in the coordinates of the source image (values will be clipped).
Method Detail

getSourceImage

public javax.media.jai.PlanarImage getSourceImage()
Returns the current source image.


getRescaledSourceImage

public javax.media.jai.PlanarImage getRescaledSourceImage()
Returns the current source image, after applying BZERO and BSCALE, if needed.


setSourceImage

public void setSourceImage(javax.media.jai.PlanarImage sourceImage,
                           ImageProcessor imageProcessor)
Set the source image and copy all of the image processing settings from the given ImageProcessor object. This method may be used, for example, for a pan window that displays a separate, prescaled image, that should have the same image processing settings as the main image.


setSourceImage

public void setSourceImage(javax.media.jai.PlanarImage sourceImage,
                           java.awt.geom.Rectangle2D.Double region)
Set the source image and the region of interest and perform any requested image processing to make the display image.

Parameters:
region - the region of interest in the image (usually the visible area) in the coordinates of the source image.

getDisplayImage

public javax.media.jai.PlanarImage getDisplayImage()
Returns the current display image.


update

public void update()
Process the source image, adding a lookup table and setting appropriate cut levels where needed to improve visibility.


rescaleImage

protected javax.media.jai.PlanarImage rescaleImage(javax.media.jai.PlanarImage im)
Rescale the given image, if needed, using the given factor and offset and return the result. The resulting image is converted to float, to avoid loosing data.


setTrans

protected javax.media.jai.PlanarImage setTrans(javax.media.jai.PlanarImage im)
Perform a transpose operation on the given image using the current rotate, flipX and flipY settings and return the resulting image.


rotate

protected javax.media.jai.PlanarImage rotate(javax.media.jai.PlanarImage im)
Rotate the image about the center by the specified angle (in radians).


setRegionOfInterest

protected void setRegionOfInterest(java.awt.geom.Rectangle2D.Double region)
Set the current region of interest in the image (normally the currently visible area). This is used by operations that need to gather statistics on the image to avoid having to scan the entire image.

Parameters:
region - the region of interest in the image

calculateImageStatistics

protected void calculateImageStatistics(java.awt.geom.Rectangle2D.Double region)
Examine the given region of the source image to determine the min and max pixel values as well as the default cut levels (using median filter). As a result, the minValue, maxValue, lowCut, and highCut member variables are set. This method should be called before calling getMinValue(), getMaxValue(), getLowCut() or getHighCut(). If the same region is specified as in the previous call, nothing is done.

Parameters:
region - the region of interest in the image

copySettings

public void copySettings(ImageProcessor ip)
Copy the settings from the given ImageProcessor to this one.


setCutLevels

public void setCutLevels(double lowCut,
                         double highCut)
Set the image cutoff levels.

Parameters:
lowCut - the low cut value
highCut - the high cut value

setCutLevels

public void setCutLevels(double lowCut,
                         double highCut,
                         boolean userSetCutLevels)
Set the image cutoff levels.

Parameters:
lowCut - the low cut value
highCut - the high cut value
userSetCutLevels - set to true if the cut levels were set by the user (meaning they should not be changed automatically)

setLowCut

public void setLowCut(double lowCut)
Set the low cutoff level


setHighCut

public void setHighCut(double highCut)
Set the high cutoff level


getLowCut

public double getLowCut()
Get the low cutoff level


getHighCut

public double getHighCut()
Get the high cutoff level


autoSetCutLevels

public void autoSetCutLevels(java.awt.geom.Rectangle2D.Double region)
Set the image cut levels automatically using median filtering on the given area of the image.

Parameters:
region - the region of interest in the image

autoSetCutLevels

public void autoSetCutLevels(double percent,
                             java.awt.geom.Rectangle2D.Double region)
Set the cut levels so that the given percent of pixels in the given region of the image are within the low and high cut values.

Parameters:
percent - value between 0. and 100. indicating percent of image pixels within the cut levels.
region - the region of interest in the image

isUserSetCutLevels

public boolean isUserSetCutLevels()
Return true if the user has set the cut levels and they were not automatically set.


setUserSetCutLevels

public void setUserSetCutLevels(boolean b)
Set to true if the user has set the cut levels and they were not automatically set. This has the effect that the cut levels will not be automatically set if a new image is loaded.


addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener l)
register to receive change events from this object whenever the image or cut levels are changed.


removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener l)
Stop receiving change events from this object.


fireChange

protected void fireChange(ImageChangeEvent changeEvent)
Notify any listeners of a change in the image or cut levels.


getMinValue

public double getMinValue()
Return the min pixel value in the region specified in the last call to calculateImageStatistics.


getMaxValue

public double getMaxValue()
Return the max pixel value in the region specified in the last call to calculateImageStatistics.


getBlank

public float getBlank()
Return the value used for bad or blank pixels (taken from "BLANK" image property).


getAngle

public double getAngle()
Return the rotation angle.


setAngle

public void setAngle(double angle)
Set the rotation angle.


getInterpolation

public javax.media.jai.Interpolation getInterpolation()
Return the type of interpolation to use (for rotating).


setInterpolation

public void setInterpolation(javax.media.jai.Interpolation i)
Set the type of interpolation to use (for rotating).


toggleFlipX

public void toggleFlipX()
Toggle the flipping of the X axis


setFlipX

public void setFlipX(boolean flipX)
Set the value of the flipX flag.


getFlipX

public boolean getFlipX()
Return the value of the flipX flag.


toggleFlipY

public void toggleFlipY()
Toggle the flipping of the Y axis


setFlipY

public void setFlipY(boolean flipY)
Set the value of the flipY flag.


getFlipY

public boolean getFlipY()
Return the value of the flipY flag.


setReverseY

public void setReverseY(boolean reverseY)
Set the value of the reverseY flag. If this flag is set to true, the value of flipY is reversed (used for FITS images).


getReverseY

public boolean getReverseY()
Return the value of the reverseY flag. If this flag is true, the value of flipY is reversed (used for FITS images).


setInvertedYAxis

public void setInvertedYAxis(boolean invertedYAxis)
Set to true if the Y axis of the image was inverted while reading.

This means that the image doesn't need to be flipped before displaying, but the image coordinate system still needs to be inverted in the Y axis.


isInvertedYAxis

public boolean isInvertedYAxis()
Return true if the Y axis of the image was inverted while reading.


getHistogram

public javax.media.jai.Histogram getHistogram(int size,
                                              javax.media.jai.ROI roi)
Return a histogram for the image with the given size (number of bins) and region of interest and default settings for the other arguments.


setName

public void setName(java.lang.String name)
Set the name to use for this object (for testing and debugging).


getName

public java.lang.String getName()
Return the name of this object


getScaleLookupTable

public javax.media.jai.LookupTableJAI getScaleLookupTable()
Return the lookup table used to scale the image to byte range


setScaleAlgorithm

public void setScaleAlgorithm(int scaleAlgorithm)
Set the algorithm to use to scale the image to byte range.

Parameters:
scaleAlgorithm - one of the public constants defined in the ImageLookup class (default: ImageLookup.LINEAR_SCALE).

getScaleAlgorithm

public int getScaleAlgorithm()
Return the current image scaling algorithm (one of the constants defined in the ImageLookup class (default: ImageLookup.LINEAR_SCALE).


setColorLookupTable

public void setColorLookupTable(java.lang.String name)
Create a color RGB lookup table that can be added to the image processing chain, so that we can manipulate the image colors.

Parameters:
name - the name of the colormap table to use. This is currently One of: "Background", "Blue", "Heat", "Isophot", "Light", "Pastel", "Ramp", "Real", "Smooth", "Staircase", "Standard". User defined maps will be implemented in a later release.

getColorLookupTable

public javax.media.jai.LookupTableJAI getColorLookupTable()
Return the current lookup table used to add color to a grayscale image.


getColorLookupTableName

public java.lang.String getColorLookupTableName()
Return the name of the current color lookup table


getIntensityLookupTableName

public java.lang.String getIntensityLookupTableName()
Return the name of the current intensity lookup table


setIntensityLookupTable

public void setIntensityLookupTable(java.lang.String name)
Create an intensity lookup table that can be added to the image processing chain to rearrange the order of the colors in the colormap.

Parameters:
name - the name of the intensity lookup table to use. This is currently One of: "Equal", "Exponential", "Gamma", "Jigsaw", "Lasritt", "Logarithmic", "Negative", "Negative Log", "Ramp", "Staircase". User defined intensity lookup tables will be implemented in a later release.

rotateColormap

public void rotateColormap(int amount)
Rotate the colormap by the given amount.


shiftColormap

public void shiftColormap(int amount)
Shift the colormap by the given amount.


scaleColormap

public void scaleColormap(int amount)
Scale the colormap by the given amount.


saveColormap

public void saveColormap()
Save the current colormap state for the next shift, rotate or scale operation.


resetColormap

public void resetColormap()
Reset the colormap to the default.


setDefaultColormap

public void setDefaultColormap()
Reset the colormap to the default.


setUpdatePending

protected void setUpdatePending(boolean b)
Set to true if something was changed and a call to update() is needed.


isUpdatePending

protected boolean isUpdatePending()
Return true if something was changed and a call to update() is needed.