|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectImageInspector
ImageWorker
@Deprecated public class ImageWorker
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.
| 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 Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Hints.Key COLOR_QUANTIZATION
IndexColorModel. The default value
is ERROR_DIFFUSION.
setColorModelType(java.lang.Class extends java.awt.image.ColorModel>),
ImageInspector.setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)public static final Hints.Key TILING_ALLOWED
FALSE, image operators are not allowed to produce tiled images.
The default is value TRUE.
ImageInspector.setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)| Constructor Detail |
|---|
public ImageWorker(RenderedImage image)
image - The source image.| Method Detail |
|---|
public void tile()
getRenderingHints() failed to suggest a tile size.
see #isTiled
public void format(int type,
boolean rescale)
rescale argument:
If false, then this method casts the sample values to the given
type - values are not changed except as a result of the cast.
If true, then this method rescales the sample values in order to make
them fit in the range supported by the given data type. It does so by computing
the minimum and maximum values
for each band, rescale them to the range of the
given type and format the resulting image to of that type.
DataBuffer.TYPE_BYTE as the parameter value.
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.ImageInspector.isBytes(),
RescaleDescriptorpublic void forceBitmaskIndexColorModel(int transparent)
IndexColorModel with bitmask transparency. If the current image already uses a suitable
color model, then this method does nothing.
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.ImageInspector.isIndexed(),
ImageInspector.isTranslucent(),
COLOR_QUANTIZATIONpublic void setColorModelType(Class<? extends ColorModel> type)
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.
type - The target color model type. Currently supported types are
IndexColorModel and ComponentColorModel. More
may be added in the future.ImageInspector.isIndexed(),
COLOR_QUANTIZATION,
ImageInspector.IGNORE_FULLY_TRANSPARENT_PIXELS,
ErrorDiffusionDescriptor,
OrderedDitherDescriptor,
FormatDescriptor,
IndexColorModel.convertToIntDiscrete(java.awt.image.Raster, boolean)public void setColorSpaceType(PaletteInterpretation type)
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].
type - The desired Color Space type.ImageInspector.getColorSpaceType(),
ColorConvertDescriptorpublic void intensity()
Note: The result is a usually a gray scale image. Nevertheless it is not the same than invokingsetColorSpaceType(PaletteInterpretation.GRAY)because thisintensity()method gives equal weight to all RGB bands, while conversion to gray color space involve a more complex combination of bands.
BandCombineDescriptor
public void mergeBands(RenderedImage toAdd,
int insertAt)
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.
public void retainBands(int first,
int last)
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:
retainBands( 0, 0) retains the first band.retainBands(-1, -1) retains the last band.retainBands( 1, -1) retains all bands except the first one.retainBands( 0, -2) retains all bands except the last one.
first - The first band to retain, inclusive.last - The last band to retain, inclusive.ImageInspector.getNumBands(),
BandSelectDescriptorpublic void retainBands(int[] bands)
bands - The bands to retain.ImageInspector.getNumBands(),
BandSelectDescriptorpublic void binarize(boolean dynamic)
binarize(double) is invoked with that
threshold
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).ImageInspector.isBinary(),
binarize(double),
binarize(double,double),
BinarizeDescriptorpublic void binarize(double threshold)
threshold - The threshold value.ImageInspector.isBinary(),
binarize(boolean),
binarize(double,double),
BinarizeDescriptor
public void binarize(double value0,
double value1)
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.
value0 - The value to be substituted to 0 in the binarized image.value1 - The value to be substituted to 1 in the binarized image.ImageInspector.isBinary(),
binarize(double)
public void maskBackground(double[][] background,
double[] newValues)
mask method below.
This method is appropriate for replacing the background color surrounding a rotated
rectangular area, as illustrated in the Mask javadoc.
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.SilhouetteMask
public void mask(RenderedImage mask,
double[] newValues)
newValues.
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.Maskpublic void add(RenderedImage toAdd)
AddDescriptor for details.
toAdd - The image to be added to the one in this worker.AddDescriptorpublic void add(double[] values)
AddConstDescriptor for details.
values - The constants to be added.AddConstDescriptorpublic void subtract(RenderedImage toSubtract)
SubtractDescriptor for details.
toSubtract - The image to be subtracted from the one in this worker.SubtractDescriptorpublic void subtract(double[] values)
SubtractConstDescriptor for details.
values - The constants to be subtracted.SubtractConstDescriptorpublic void multiply(RenderedImage toMultiply)
MultiplyDescriptor for details.
toMultiply - The image to be added to the one in this worker.MultiplyDescriptorpublic void multiply(double[] values)
MultiplyConstDescriptor for details.
values - The constants to be multiplied.MultiplyConstDescriptorpublic void divide(RenderedImage toDivide)
DivideDescriptor for details.
toDivide - The image to divide the one in this worker.DivideDescriptorpublic void divideBy(double[] values)
DivideByConstDescriptor for details.
values - The divisor constants.DivideByConstDescriptorpublic void invert()
InvertDescriptorpublic void xor(int[] values)
XorConstDescriptor for details.
values - The constants to be xored.XorConstDescriptor
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||