org.geotoolkit.image
Class ImageWorker

Object
  extended by ImageInspector
      extended by ImageWorker

Deprecated. This class is a legacy from old days and has never been seriously used in the Geotoolkit.org library. Its work is quite arbitrary, so we are probably better to let users do their work in their own way.

@Deprecated
public class ImageWorker
extends ImageInspector

Helper methods for applying JAI operations on an image. The image is specified at creation time. Successive operations can be applied by invoking the methods defined in this class, and the final image can be obtained by invoking ImageInspector.getRenderedImage() at the end of the process.

This class does not really brings new functionalities, since most of its work is performed by chains of JAI image operations. However it makes the job easier by performing automatically some intermediate steps based on assumptions about what the common usage is. For example some methods like intensity() may convert the image to the RGB color space before to do their work. Color Quantization uses the BYTE_496 color cube, which is specific to the RGB color space. Methods dealing with transparency assume that the alpha channel, if presents, is the last band.

Developers who know exactly the characteristics of their image should probably use JAI operations directly. Developers writing prototypes, or developers who don't know much more about their images than what this ImageWorker assumes, can use this class as a convenience.

If an exception is thrown during a method invocation, then this ImageWorker is left in an undetermined state and should not be used anymore.

Since:
2.3
Version:
3.01
Author:
Martin Desruisseaux (Geomatys), Simone Giannecchini (Geosolutions), Bryce Nordgren
Module:
coverage/geotk-coverage (download)    View source code for this class

Field Summary
static Hints.Key COLOR_QUANTIZATION
          Deprecated. The Color Quantization method to be applied if a an image needs to have its color model converted to an IndexColorModel.
static Hints.Key TILING_ALLOWED
          Deprecated. If FALSE, image operators are not allowed to produce tiled images.
 
Fields inherited from class ImageInspector
IGNORE_FULLY_TRANSPARENT_PIXELS, IHS, image
 
Constructor Summary
ImageWorker(RenderedImage image)
          Deprecated. Creates a new worker for the specified image.
 
Method Summary
 void add(double[] values)
          Deprecated. Adds every pixels in the current image with the given constants.
 void add(RenderedImage toAdd)
          Deprecated. Adds every pixels of the given image to the current image.
 void binarize(boolean dynamic)
          Deprecated. Binarizes the image.
 void binarize(double threshold)
          Deprecated. Binarizes the image.
 void binarize(double value0, double value1)
          Deprecated. Binarizes the image (if not already done) and replaces all 0 values by value0 and all 1 values by value1.
 void divide(RenderedImage toDivide)
          Deprecated. Divides every pixels of the given image to the current image.
 void divideBy(double[] values)
          Deprecated. Divides every pixels in the current image by the given constants.
 void forceBitmaskIndexColorModel(int transparent)
          Deprecated. Reduces the color model to IndexColorModel with bitmask transparency.
 void format(int type, boolean rescale)
          Deprecated. Formats the image to the provided data type.
 void intensity()
          Deprecated. Creates an image which represents approximatively the intensity of image.
 void invert()
          Deprecated. Inverts the sign of pixel values in the image.
 void mask(RenderedImage mask, double[] newValues)
          Deprecated. Applies the specified mask over the current ImageInspector.image.
 void maskBackground(double[][] background, double[] newValues)
          Deprecated. Masks the given background values, to be replaced by the given new values.
 void mergeBands(RenderedImage toAdd, int insertAt)
          Deprecated. Merges the bands of the given image with the bands of the current image.
 void multiply(double[] values)
          Deprecated. Multiplies every pixels in the current image with the given constants.
 void multiply(RenderedImage toMultiply)
          Deprecated. Multiplies every pixels of the given image to the current image.
 void retainBands(int[] bands)
          Deprecated. Retains the given bands of the image.
 void retainBands(int first, int last)
          Deprecated. Retains the bands in the range first to last inclusive.
 void setColorModelType(Class<? extends ColorModel> type)
          Deprecated. Sets the color model to the given target type.
 void setColorSpaceType(PaletteInterpretation type)
          Deprecated. Forces the image color model to the given color space type.
 void subtract(double[] values)
          Deprecated. Subtracts the given constants from every pixels in the current image.
 void subtract(RenderedImage toSubtract)
          Deprecated. Subtracts every pixels of the given image from the current image.
 void tile()
          Deprecated. If the image was not already tiled, tiles it.
 void xor(int[] values)
          Deprecated. Performs a bit-wise logical "xor" between every pixel in the same band of the image and the constant from the corresponding array entry.
 
Methods inherited from class ImageInspector
getBufferedImage, getColorSpaceType, getImageAsROI, getMaximums, getMinimums, getNumBands, getPlanarImage, getRenderedImage, getRenderedOperation, getRenderingHint, getRenderingHints, getROI, getTransparentPixel, isBinary, isBytes, isGrayScale, isIndexed, isTiled, isTranslucent, removeRenderingHint, setImage, setRenderingHint, setROI, show
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLOR_QUANTIZATION

public static final Hints.Key COLOR_QUANTIZATION
Deprecated. 
The Color Quantization method to be applied if a an image needs to have its color model converted to an IndexColorModel. The default value is ERROR_DIFFUSION.

See Also:
setColorModelType(java.lang.Class), ImageInspector.setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)

TILING_ALLOWED

public static final Hints.Key TILING_ALLOWED
Deprecated. 
If FALSE, image operators are not allowed to produce tiled images. The default is value TRUE.

See Also:
ImageInspector.setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)
Constructor Detail

ImageWorker

public ImageWorker(RenderedImage image)
Deprecated. 
Creates a new worker for the specified image. The images to be computed (if any) will save their tiles in the default tile cache.

Parameters:
image - The source image.
Method Detail

tile

public void tile()
Deprecated. 
If the image was not already tiled, tiles it. Note that no tiling will be done if getRenderingHints() failed to suggest a tile size. see #isTiled


format

public void format(int type,
                   boolean rescale)
Deprecated. 
Formats the image to the provided data type. If the image already stores its sample values in a data buffer of the given type, then this method does nothing. Otherwise the behavior depends on the value of the rescale argument: This method is often used for rescaling to bytes in the range [0 … 255], which can be done with DataBuffer.TYPE_BYTE as the parameter value.

Parameters:
type - The target type as one of the TYPE_* constant defined in DataBuffer.
rescale - true for rescaling the sample values to the range supported by the given type, or false for just casting them.
See Also:
ImageInspector.isBytes(), RescaleDescriptor

forceBitmaskIndexColorModel

public void forceBitmaskIndexColorModel(int transparent)
Deprecated. 
Reduces the color model to IndexColorModel with bitmask transparency. If the current image already uses a suitable color model, then this method does nothing.

Parameters:
transparent - A pixel value to define as the transparent pixel, or -1 for the default. The default is to reuse the existing transparent pixel if there is one, or to use the one with the smallest alpha value otherwise, or 0 if all colors are opaque.
See Also:
ImageInspector.isIndexed(), ImageInspector.isTranslucent(), COLOR_QUANTIZATION

setColorModelType

public void setColorModelType(Class<? extends ColorModel> type)
Deprecated. 
Sets the color model to the given target type. If the image already uses a color model of the given type, then this method does nothing. Otherwise the operation depends on the target type, enumerated below:

Index Color Model
If the target type is IndexColorModel, then this method performs a color reduction using an Error Diffusion or an Ordered Dither operation depending the value of the COLOR_QUANTIZATION rendering hint. If this hint is not provided, then the selected method is implementation-dependent and may vary in future versions.

Note: The current implementation performs its work on the RGB color space only.

Component Color Model
If the target type is ComponentColorModel, then this method reformats the current image preserving transparency. The result can have any number of bands from 1 to 4 inclusive, depending on the color space (grayscale or RGB) and the presence of alpha channel.

Note: This code is adapted from jai-interests mailing list archive.

Parameters:
type - The target color model type. Currently supported types are IndexColorModel and ComponentColorModel. More may be added in the future.
See Also:
ImageInspector.isIndexed(), COLOR_QUANTIZATION, ImageInspector.IGNORE_FULLY_TRANSPARENT_PIXELS, ErrorDiffusionDescriptor, OrderedDitherDescriptor, FormatDescriptor, IndexColorModel.convertToIntDiscrete(java.awt.image.Raster, boolean)

setColorSpaceType

public void setColorSpaceType(PaletteInterpretation type)
Deprecated. 
Forces the image color model to the given color space type. If the current color space is already of the given type, then this method does nothing.

If a color space change is performed, then this operation creates an opaque ColorModel because the "ColorConvert" operation treats data as having no alpha channel. Consequently the alpha channel may be lost as a result of a call to this method.

Integral data are assumed to occupy the full range of the respective data type; floating point data are assumed to be normalized to the range [0.0 … 1.0].

Parameters:
type - The desired Color Space type.
Since:
3.00
See Also:
ImageInspector.getColorSpaceType(), ColorConvertDescriptor

intensity

public void intensity()
Deprecated. 
Creates an image which represents approximatively the intensity of image. The result is always a single-banded image. If the image uses a gray scale or an IHS color space, then this method just retains the first band without any further processing. Otherwise, this method performs a simple band combine operation on the image in order to come up with a simple estimation of the intensity of based on the average value of the color components. Note that the alpha band is stripped from the image.
Note: The result is a usually a gray scale image. Nevertheless it is not the same than invoking setColorSpaceType(PaletteInterpretation.GRAY) because this intensity() method gives equal weight to all RGB bands, while conversion to gray color space involve a more complex combination of bands.

See Also:
BandCombineDescriptor

mergeBands

public void mergeBands(RenderedImage toAdd,
                       int insertAt)
Deprecated. 
Merges the bands of the given image with the bands of the current image. The new bands can be merged before or after the bands of the current image. They can also be merged in the middle, but this is less efficient.

Parameters:
toAdd - Image having the bands to merge with the bands of the current image.
insertAt - Where to insert the new bands: 0 for inserting the new bands before the current ones, or getNumBands() for inserting the new bands after the current ones. Value -1 can be used as a shortcut for getNumBands(). Intermediate values are also allowed, but they are less common and less efficient.

retainBands

public void retainBands(int first,
                        int last)
Deprecated. 
Retains the bands in the range first to last inclusive. All other bands (if any) are discarded without any further processing. This method does nothing if the given range include all bands.

For convenience, negative parameter values are relative to the number of bands (i.e. the number of bands is added to negative parameter values). So -1 stands for the last band, -2 for the band before the last one, etc.

Examples:

Parameters:
first - The first band to retain, inclusive.
last - The last band to retain, inclusive.
See Also:
ImageInspector.getNumBands(), BandSelectDescriptor

retainBands

public void retainBands(int[] bands)
Deprecated. 
Retains the given bands of the image. All other bands (if any) are discarded without any further processing.

Parameters:
bands - The bands to retain.
See Also:
ImageInspector.getNumBands(), BandSelectDescriptor

binarize

public void binarize(boolean dynamic)
Deprecated. 
Binarizes the image. If the image is multi-bands, then this method first computes an estimation of its intensity. Then, the threshold value is set halfway between the minimal and maximal values found in the image and binarize(double) is invoked with that threshold

Parameters:
dynamic - If true, the minimum and maximum values are computed dynamically from the sample values found in the image. If false, minimum and maximum values are determined only from the data type (for example they are always 0 and 255 for DataBuffer.TYPE_BYTE).
See Also:
ImageInspector.isBinary(), binarize(double), binarize(double,double), BinarizeDescriptor

binarize

public void binarize(double threshold)
Deprecated. 
Binarizes the image. If the image is multi-bands, then this method first computes an estimation of its intensity. If the image is already binarized, then this method does nothing.

Parameters:
threshold - The threshold value.
See Also:
ImageInspector.isBinary(), binarize(boolean), binarize(double,double), BinarizeDescriptor

binarize

public void binarize(double value0,
                     double value1)
Deprecated. 
Binarizes the image (if not already done) and replaces all 0 values by value0 and all 1 values by value1. If the image should be binarized using a custom threshold value (instead of the automatic one), invoke binarize(double) explicitly before this method.

Parameters:
value0 - The value to be substituted to 0 in the binarized image.
value1 - The value to be substituted to 1 in the binarized image.
See Also:
ImageInspector.isBinary(), binarize(double)

maskBackground

public void maskBackground(double[][] background,
                           double[] newValues)
Deprecated. 
Masks the given background values, to be replaced by the given new values. This method computes a silhouette mask of the current image using the given background values, then applies this mask on the image using the mask method below.

This method is appropriate for replacing the background color surrounding a rotated rectangular area, as illustrated in the Mask javadoc.

Parameters:
background - The background color, as an array of sample values, to be replaced by the new sampel values. The length of this array should be equals to the number of bands of the image.
newValues - The new sample values to be given to the background pixels, or null for assigning the transparent color to the background.
See Also:
SilhouetteMask

mask

public void mask(RenderedImage mask,
                 double[] newValues)
Deprecated. 
Applies the specified mask over the current ImageInspector.image. The mask is typically binarized, but this is not mandatory. For every pixels in the mask having a value different than zero, the corresponding pixel in the ImageInspector.image will be set to the specified newValues.

Parameters:
mask - The mask to apply.
newValues - The new sample values for every pixels in the image corresponding to a non-zero value in the mask. If this parameter is null, then the non-zero value in the mask itself will be used. If non-null, then the array length should be equals to the number of bands in the destination image.
See Also:
Mask

add

public void add(RenderedImage toAdd)
Deprecated. 
Adds every pixels of the given image to the current image. See JAI AddDescriptor for details.

Parameters:
toAdd - The image to be added to the one in this worker.
See Also:
AddDescriptor

add

public void add(double[] values)
Deprecated. 
Adds every pixels in the current image with the given constants. The length of the given array must be equals to the number of bands. See JAI AddConstDescriptor for details.

Parameters:
values - The constants to be added.
See Also:
AddConstDescriptor

subtract

public void subtract(RenderedImage toSubtract)
Deprecated. 
Subtracts every pixels of the given image from the current image. See JAI SubtractDescriptor for details.

Parameters:
toSubtract - The image to be subtracted from the one in this worker.
See Also:
SubtractDescriptor

subtract

public void subtract(double[] values)
Deprecated. 
Subtracts the given constants from every pixels in the current image. The length of the given array must be equals to the number of bands. See JAI SubtractConstDescriptor for details.

Parameters:
values - The constants to be subtracted.
See Also:
SubtractConstDescriptor

multiply

public void multiply(RenderedImage toMultiply)
Deprecated. 
Multiplies every pixels of the given image to the current image. See JAI MultiplyDescriptor for details.

Parameters:
toMultiply - The image to be added to the one in this worker.
See Also:
MultiplyDescriptor

multiply

public void multiply(double[] values)
Deprecated. 
Multiplies every pixels in the current image with the given constants. The length of the given array must be equals to the number of bands. See JAI MultiplyConstDescriptor for details.

Parameters:
values - The constants to be multiplied.
See Also:
MultiplyConstDescriptor

divide

public void divide(RenderedImage toDivide)
Deprecated. 
Divides every pixels of the given image to the current image. See JAI DivideDescriptor for details.

Parameters:
toDivide - The image to divide the one in this worker.
See Also:
DivideDescriptor

divideBy

public void divideBy(double[] values)
Deprecated. 
Divides every pixels in the current image by the given constants. The length of the given array must be equals to the number of bands. See JAI DivideByConstDescriptor for details.

Parameters:
values - The divisor constants.
See Also:
DivideByConstDescriptor

invert

public void invert()
Deprecated. 
Inverts the sign of pixel values in the image.

See Also:
InvertDescriptor

xor

public void xor(int[] values)
Deprecated. 
Performs a bit-wise logical "xor" between every pixel in the same band of the image and the constant from the corresponding array entry. See JAI XorConstDescriptor for details.

Parameters:
values - The constants to be xored.
See Also:
XorConstDescriptor


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.