public class ImageWorker extends Object
getRenderedImage()
at the end of the process.
If an exception is thrown during a method invocation, then this ImageWorker
is left in
an undetermined state and should not be used anymore.
Modifier and Type | Class and Description |
---|---|
static class |
ImageWorker.PNGImageWriteParam
Workaround class for compressing PNG using the default PNGImageEncoder shipped with the JDK.
|
Modifier and Type | Field and Description |
---|---|
static Hints.Key |
FORCE_MOSAIC_ROI_PROPERTY
Specify whether to set a ROI property when doing a mosaic, even when background is specified
|
protected RenderedImage |
image
The image being built.
|
static boolean |
JAIEXT_ENABLED |
static String |
JAIEXT_ENABLED_KEY |
static String |
SCALE_NAME |
static String |
SCALE_OP_NAME |
static String |
SCALE2_NAME |
static Hints.Key |
TILING_ALLOWED
If
FALSE , image operators are not allowed to produce tiled images. |
static boolean |
USE_JAI_SCALE2 |
static String |
USE_JAI_SCALE2_KEY |
static String |
WARP_REDUCTION_ENABLED_KEY
Controls the warp-affine reduction
|
Constructor and Description |
---|
ImageWorker()
Creates a new uninitialized builder for an image read or a mosaic operation
|
ImageWorker(File input)
Creates a new builder for an image read from the specified file.
|
ImageWorker(RenderedImage image)
Creates a new builder for the specified image.
|
ImageWorker(RenderingHints hints)
Creates a new uninitialized worker with RenderingHints for a mosaic
operation
|
Modifier and Type | Method and Description |
---|---|
ImageWorker |
addBand(RenderedImage image,
boolean before)
Perform a BandMerge operation between the underlying image and the provided one.
|
ImageWorker |
addBand(RenderedImage image,
boolean before,
boolean addAlpha,
Range nodata2)
Perform a BandMerge operation between the underlying image and the provided one.
|
ImageWorker |
addBands(RenderedImage[] bands,
boolean addAlpha,
Range[] nodata2)
Perform a BandMerge operation between the underlying image and the provided one.
|
ImageWorker |
addBands(RenderedImage[] bands,
boolean addAlpha,
Range[] nodata2,
List<AffineTransform> transformationList)
Perform a BandMerge operation between the underlying image and the provided one.
|
ImageWorker |
addImage(RenderedImage renderedImage)
Takes two rendered or renderable source images, and adds every pair of pixels, one from each
source image of the corresponding position and band.
|
ImageWorker |
addTransparencyToIndexColorModel(RenderedImage alphaChannel,
boolean errorDiffusion)
Adds transparency to a preexisting image whose color model is index color model.
|
ImageWorker |
addTransparencyToIndexColorModel(RenderedImage alphaChannel,
boolean translucent,
int transparent,
boolean errorDiffusion)
Adds transparency to a preexisting image whose color model is index color model.
|
ImageWorker |
affine(AffineTransform tx,
Interpolation interpolation,
double[] bgValues)
Performs an affine transform on the image, applying optimization such as affine removal in
case the affine is an identity, affine merging if the affine is applied on top of another
affine, and using optimized operations for integer translates
|
ImageWorker |
applyOpacity(float opacity)
Applies the specified opacity to the image by either adding an alpha band, or modifying the
existing one by multiplication
|
ImageWorker |
artifactsFilter(int threshold,
int filterSize) |
ImageWorker |
bandCombine(double[][] coeff)
Apply a rescale operation on the underlying image.
|
ImageWorker |
bandMerge(int writeband)
Add the bands to the Component Color Model
|
ImageWorker |
binarize()
Binarizes the image.
|
ImageWorker |
binarize(double threshold)
Binarizes the image.
|
ImageWorker |
binarize(int value0,
int value1)
Binarizes the image (if not already done) and replace all 0 values by
value0 and all 1 values by value1 . |
ImageWorker |
border(int leftPad,
int rightPad,
int topPad,
int bottomPad,
BorderExtender ext) |
ImageWorker |
classify(ColorMapTransform domain1D,
Integer bandIndex)
Apply a Raster classification on the underlying image.
|
ImageWorker |
colorIndex(ColorIndexer indexer)
Warps the underlying using the provided Warp object.
|
ImageWorker |
crop(float x,
float y,
float width,
float height)
Crops the image to the specified bounds.
|
void |
dispose()
Provides a hint that this
ImageWorker will no longer be accessed from a reference in
user space. |
Range |
extractNoDataProperty(RenderedImage image) |
ImageWorker |
forceBitmaskIndexColorModel()
|
ImageWorker |
forceBitmaskIndexColorModel(int suggestedTransparent,
boolean errorDiffusion)
|
ImageWorker |
forceColorSpaceGRAYScale()
Forces the image color model to the GRAYScale
color space.
|
ImageWorker |
forceColorSpaceIHS()
Forces the image color model to the IHS color space.
|
ImageWorker |
forceColorSpaceRGB()
Forces the image color model to the RGB color
space.
|
ImageWorker |
forceColorSpaceYCbCr()
Forces the image color model to the YCbCr color
space.
|
ImageWorker |
forceComponentColorModel()
Reformats the color model to a component color model preserving transparency.
|
ImageWorker |
forceComponentColorModel(boolean checkTransparent)
Reformats the color model to a component color model preserving transparency.
|
ImageWorker |
forceComponentColorModel(boolean checkTransparent,
boolean optimizeGray)
Reformats the color model to a component color model preserving transparency.
|
ImageWorker |
forceComponentColorModel(boolean checkTransparent,
boolean optimizeGray,
boolean omitAlphaOnExpand)
Reformats the color model to a component color model preserving transparency.
|
ImageWorker |
forceIndexColorModel(boolean error)
Reduces the color model to index color model.
|
ImageWorker |
forceIndexColorModelForGIF(boolean errorDiffusion)
Converts the image to a GIF-compliant image.
|
ImageWorker |
format(int dataType)
Formats the underlying image to the provided data type.
|
ImageWorker |
function(ImageFunction function,
int w,
int h,
float xScale,
float yScale,
float xTrans,
float yTrans) |
BufferedImage |
getBufferedImage()
Returns the current image as a buffered image.
|
double[] |
getDestinationNoData()
Returns the NoData Range currently set, or
null if none. |
Histogram |
getHistogram(int[] numBins,
double[] lowValues,
double[] highValues)
Returns the histogram of the image.
|
ROI |
getImageAsROI()
Returns a Region Of Interest built from the current image.
|
double[] |
getMaximums()
Returns the maximal values found in every image bands.
|
double[] |
getMean()
Returns the minimums and maximums values found in the image.
|
double[] |
getMinimums()
Returns the minimal values found in every image bands.
|
Range |
getNoData()
Returns the NoData Range currently set, or
null if none. |
int |
getNumBands()
Returns the number of bands in the image.
|
protected static OperationDescriptor |
getOperationDescriptor(String name) |
PlanarImage |
getPlanarImage()
Returns the rendered image as a planar image.
|
RenderedImage |
getRenderedImage()
Returns the current image.
|
RenderedOp |
getRenderedOperation()
Returns the rendered image as a rendered operation.
|
Object |
getRenderingHint(RenderingHints.Key key)
Returns the rendering hint for the specified key, or
null if none. |
RenderingHints |
getRenderingHints()
Returns the rendering hints for an image to be computed by this class.
|
ROI |
getROI()
Returns the region of interest currently set, or
null if none. |
int |
getTransparentPixel()
Returns the transparent pixel value, or -1 if none.
|
int |
getXPeriod()
The x-period used by statistical operations (e.g. extrema, mean, histogram).
|
int |
getYPeriod()
The y-period used by statistical operations (e.g. extrema, mean, histogram).
|
ImageWorker |
intensity()
Creates an image which represents approximatively the intensity of image.
|
ImageWorker |
invert()
Inverts the pixel values of the image.
|
boolean |
isBinary()
Returns
true if the image is binary. |
boolean |
isBytes()
Returns
true if the image stores its pixel values in 8 bits. |
boolean |
isColorSpaceGRAYScale()
|
boolean |
isColorSpaceIHS()
|
boolean |
isColorSpaceRGB()
|
boolean |
isColorSpaceYCbCr()
|
boolean |
isIndexed()
|
static boolean |
isJaiExtEnabled() |
boolean |
isNoDataNeeded()
Returns true if destination NoData values must be set and they must be used in computation
|
boolean |
isTranslucent()
|
void |
load(String source,
int imageChoice,
boolean readMetadata)
Loads an image using the provided file name and the current
hints, which are used to control caching and layout.
|
ImageWorker |
lookup(LookupTable table)
Performs Lookup on the underlying image
|
static void |
main(String[] args)
Loads the image from the specified file, and display it in a window.
|
ImageWorker |
makeColorTransparent(Color transparentColor)
Replaces all occurences of the given color (usually opaque) by a fully transparent color.
|
ImageWorker |
mask(RenderedImage mask,
boolean maskValue,
int newValue)
Applies the specified mask over the current image.
|
ImageWorker |
mosaic(RenderedImage[] images,
MosaicType type,
PlanarImage[] alphas,
ROI[] rois,
double[][] thresholds,
Range[] nodata) |
ImageWorker |
multiply(RenderedImage renderedImage)
Takes two rendered or renderable source images, and myltiply form each pixel the related
value of the second image, each one from each source image of the corresponding position and
band.
|
ImageWorker |
multiplyConst(double[] inValues)
Takes one rendered or renderable image and an array of double constants, and multiplies every
pixel of the same band of the source by the constant from the corresponding array entry.
|
ImageWorker |
nullOp()
Returns the rendered image after null operation.
|
ImageWorker |
or(RenderedImage renderedImage)
Takes two rendered or renderable source images, and do an OR for each pixel images, each one
from each source image of the corresponding position and band.
|
ImageWorker |
piecewise(PiecewiseTransform1D transform,
Integer bandIndex)
Apply a Generic Piecewise operation on the underlying image.
|
ImageWorker |
prepareForRendering()
Forces all NODATA pixels, as well as those outside of the ROI, to be transparent (expanding
the color model as needed in order to make it so).
|
ImageWorker |
rangeLookup(Object rangeLookup)
Apply a rangeLookup operation on the underlying image.
|
ImageWorker |
removeIndexColorModel()
If the image has an indexed color model, removes it, and replaces it with a component color
model. can be useful before a band-merge if the image in question is not meant to be color
expanded.
|
ImageWorker |
removeRenderingHint(RenderingHints.Key key)
Removes a rendering hint.
|
ImageWorker |
removeRenderingHints() |
ImageWorker |
rescale(double[] scale,
double[] offset)
Apply a rescale operation on the underlying image.
|
ImageWorker |
rescaleToBytes()
Rescales the image such that it uses 8 bits.
|
ImageWorker |
retainBands(int numBands)
Retains inconditionnaly the first
numBands of image. |
ImageWorker |
retainBands(int[] bands)
Retains inconditionnaly certain bands of image.
|
ImageWorker |
retainFirstBand()
Retains inconditionnaly the first band of image.
|
ImageWorker |
retainLastBand()
Retains unconditionally the last band of image.
|
ImageWorker |
scale(double xScale,
double yScale,
double xTrans,
double yTrans,
Interpolation interp)
Scales the underlying raster using the provided parameters.
|
ImageWorker |
setBackground(double[] background)
Set the image background value
|
ImageWorker |
setImage(RenderedImage image)
Prepare this builder for the specified image.
|
ImageWorker |
setNoData(Range nodata)
Set the NoData Range for checking NoData during computation.
|
ImageWorker |
setRenderingHint(RenderingHints.Key key,
Object value)
Sets a rendering hint tile to use for all images to be computed by this class.
|
ImageWorker |
setRenderingHints(RenderingHints hints)
Set a map of rendering hints to use for all images to be computed by this class.
|
ImageWorker |
setROI(ROI roi)
Set the region of interest (ROI).
|
ImageWorker |
setXPeriod(int xPeriod)
Sets the x-period used by statistical operations (e.g. extrema, mean, histogram).
|
ImageWorker |
setYPeriod(int yPeriod)
Sets the x-period used by statistical operations (e.g. extrema, mean, histogram).
|
ImageWorker |
show()
|
ImageWorker |
subtract(RenderedImage renderedImage)
Takes two rendered or renderable source images, and subtract form each pixel the related
value of the second image, each one from each source image of the corresponding position and
band.
|
ImageWorker |
tile()
If the was not already tiled, tile it.
|
ImageWorker |
tileCacheEnabled(boolean status)
If
false , disables the tile cache. |
ImageWorker |
translate(float xTrans,
float yTrans,
Interpolation interp) |
ImageWorker |
warp(Warp warp,
Interpolation interp)
Warps the underlying raster using the provided Warp object.
|
ImageWorker |
write(File output)
Writes the image to the specified file.
|
ImageWorker |
writeGIF(Object destination,
String compression,
float compressionRate)
Writes outs the image contained into this
ImageWorker as a GIF using the provided
destination, compression and compression rate. |
void |
writeJPEG(Object destination,
String compression,
float compressionRate,
boolean nativeAcc)
Writes outs the image contained into this
ImageWorker as a JPEG using the provided
destination , compression and compression rate. |
void |
writePNG(Object destination,
String compression,
float compressionRate,
boolean nativeAcc,
boolean paletted)
Writes outs the image contained into this
ImageWorker as a PNG using the provided
destination, compression and compression rate. |
void |
writeTIFF(Object destination,
String compression,
float compressionRate,
int tileSizeX,
int tileSizeY)
Writes outs the image contained into this
ImageWorker as a TIFF using the provided
destination, compression and compression rate and basic tiling information
The destination object can be anything providing that we have an ImageOutputStreamSpi that recognizes it. |
ImageWorker |
xorConst(int[] values)
Takes one rendered or renderable image and an array of integer constants, and performs a
bit-wise logical "xor" between every pixel in the same band of the source and the constant
from the corresponding array entry.
|
public static final String SCALE_NAME
public static final String SCALE2_NAME
public static final String SCALE_OP_NAME
public static final String JAIEXT_ENABLED_KEY
public static final String USE_JAI_SCALE2_KEY
public static final boolean JAIEXT_ENABLED
public static final boolean USE_JAI_SCALE2
public static final String WARP_REDUCTION_ENABLED_KEY
public static final Hints.Key TILING_ALLOWED
public static final Hints.Key FORCE_MOSAIC_ROI_PROPERTY
protected RenderedImage image
public ImageWorker()
public ImageWorker(RenderingHints hints)
public ImageWorker(File input) throws IOException
input
- The file to read.IOException
- if the file can't be read.public ImageWorker(RenderedImage image)
image
- The source image.public static boolean isJaiExtEnabled()
protected static OperationDescriptor getOperationDescriptor(String name) throws OperationNotFoundException
OperationNotFoundException
public int getXPeriod()
public ImageWorker setXPeriod(int xPeriod)
public int getYPeriod()
public ImageWorker setYPeriod(int yPeriod)
public Range extractNoDataProperty(RenderedImage image)
public final ImageWorker setImage(RenderedImage image)
image
- The source image.public final void load(String source, int imageChoice, boolean readMetadata)
source
- Filename of the source image to read.imageChoice
- Image index in multipage images.readMatadata
- If true
, metadata will be read.public final RenderedImage getRenderedImage()
getBufferedImage()
,
getPlanarImage()
,
getRenderedOperation()
,
getImageAsROI()
public final BufferedImage getBufferedImage()
getRenderedImage()
,
getPlanarImage()
,
getRenderedOperation()
,
getImageAsROI()
public final PlanarImage getPlanarImage()
getRenderedImage()
,
getRenderedOperation()
,
getImageAsROI()
public final RenderedOp getRenderedOperation()
getRenderedImage()
,
getPlanarImage()
,
getImageAsROI()
public ImageWorker nullOp()
getRenderedImage()
,
getPlanarImage()
,
getImageAsROI()
public final ROI getImageAsROI()
ROI
from the result.getRenderedImage()
,
getPlanarImage()
,
getRenderedOperation()
public final ROI getROI()
null
if none. The
default value is null
.getMinimums()
,
getMaximums()
public final Range getNoData()
null
if none. The default
value is null
.public final double[] getDestinationNoData()
null
if none. The default
value is null
.public boolean isNoDataNeeded()
public final ImageWorker setROI(ROI roi)
null
set the ROI to the whole
image. The ROI is used by statistical methods like getMinimums()
and
getMaximums()
.roi
- The new region of interest.getMinimums()
,
getMaximums()
public final ImageWorker setNoData(Range nodata)
nodata
- The new NoData Range.public final ImageWorker setBackground(double[] background)
background
- The image background.public final Object getRenderingHint(RenderingHints.Key key)
null
if none.public final ImageWorker setRenderingHint(RenderingHints.Key key, Object value)
Some common examples:
setRenderingHint(JAI.KEY_TILE_CACHE, null)
disables completly
the tile cache.
setRenderingHint(TILING_ALLOWED, Boolean.FALSE)
forces all
operators to produce untiled images.
public final ImageWorker setRenderingHints(RenderingHints hints)
If hints
is null we won't modify this list.
#setRenderingHint(RenderingHint)
public final ImageWorker removeRenderingHints()
public final ImageWorker removeRenderingHint(RenderingHints.Key key)
setRenderingHint(key, null)
. This
is especially true for the tile cache hint:
setRenderingHint(JAI.KEY_TILE_CACHE,
null)
disables the use of any tile cache. In other words, this method call do
request a tile cache, which happen to be the "null" cache.
removeRenderingHint(JAI.KEY_TILE_CACHE)
unsets any tile cache
specified by a previous rendering hint. All images to be computed after this method
call will save their tiles in the JAI default tile cache.
public final RenderingHints getRenderingHints()
setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)
method. If the
user provided explicitly a JAI.KEY_IMAGE_LAYOUT
, then the user layout has
precedence over the automatic layout computed in previous step.
null
).public final ImageWorker tileCacheEnabled(boolean status)
false
, disables the tile cache. Invoking this method with value true
cancel the last invocation with value false
. If this method was invoking many time
with value false
, then this method must be invoked the same amount of time with the
value true
for reenabling the cache.
Note: This method name doesn't contain the usual set
prefix
because it doesn't really set a flag. Instead it increments or decrements a counter.
public final int getNumBands()
public final int getTransparentPixel()
public Histogram getHistogram(int[] numBins, double[] lowValues, double[] highValues)
public double[] getMean()
double[2][#bands]
.public final double[] getMinimums()
getMaximums()
,
setROI(javax.media.jai.ROI)
public final double[] getMaximums()
getMinimums()
,
setROI(javax.media.jai.ROI)
public final boolean isBytes()
true
if the image stores its pixel values in 8 bits.rescaleToBytes()
public final boolean isBinary()
true
if the image is binary. Such image usually contains only
two values: 0 and 1.binarize()
,
binarize(double)
,
binarize(int,int)
public final boolean isIndexed()
public final boolean isColorSpaceRGB()
true
if the image uses a RGB color
space. Note that a RGB color space doesn't mean that pixel values are directly stored as RGB
components. The image may be indexed as well.forceColorSpaceRGB()
public final boolean isColorSpaceYCbCr()
forceColorSpaceYCbCr()
public final boolean isColorSpaceIHS()
forceColorSpaceIHS()
public final boolean isColorSpaceGRAYScale()
true
if the image uses a GrayScale color
space. Note that a GrayScale color space doesn't mean that pixel values are directly stored
as GrayScale component. The image may be indexed as well.forceColorSpaceGRAYScale()
public final boolean isTranslucent()
forceBitmaskIndexColorModel()
public final ImageWorker rescaleToBytes()
[0 .. 255]
and force the resulting image to TYPE_BYTE
.isBytes()
,
RescaleDescriptor
public final ImageWorker forceIndexColorModel(boolean error)
This for the moment should work only with opaque images, with non opaque images we just
remove the alpha band in order to build an IndexColorModel
. This is one because in
general it could be very difficult to decide the final transparency for each pixel given the
complexity if the algorithms for obtaining an IndexColorModel
.
If an IndexColorModel
with a single transparency index is enough for you, we
advise you to take a look at forceIndexColorModelForGIF(boolean)
methdo.
isIndexed()
,
forceBitmaskIndexColorModel()
,
forceIndexColorModelForGIF(boolean)
,
OrderedDitherDescriptor
public final ImageWorker forceBitmaskIndexColorModel()
ImageWorker
.isIndexed()
,
isTranslucent()
,
forceIndexColorModel(boolean)
,
forceIndexColorModelForGIF(boolean)
public final ImageWorker forceBitmaskIndexColorModel(int suggestedTransparent, boolean errorDiffusion)
suggestedTransparent
- A suggested pixel index to define as the transparent pixel. *errorDiffusion
- Tells if I should use ErrorDiffusionDescriptor
or OrderedDitherDescriptor
JAi operations. errorDiffusionImageWorker
.isIndexed()
,
isTranslucent()
,
forceIndexColorModel(boolean)
,
forceIndexColorModelForGIF(boolean)
public final ImageWorker forceIndexColorModelForGIF(boolean errorDiffusion)
Tip: For optimizing writing GIF, we need to create the image untiled.
This can be done by invoking
setRenderingHint(TILING_ALLOWED, Boolean.FALSE)
first.
errorDiffusion
- Tells if I should use ErrorDiffusionDescriptor
or OrderedDitherDescriptor
JAi operations.ImageWorker
.isIndexed()
,
forceIndexColorModel(boolean)
,
forceBitmaskIndexColorModel()
public final ImageWorker forceComponentColorModel()
PackedColorModel
to ComponentColorModel
, which seems to be well accepted from
PNGEncoder
and TIFFEncoder
.
This code is adapted from jai-interests mailing list archive.
ImageWorker
.FormatDescriptor
public final ImageWorker forceComponentColorModel(boolean checkTransparent, boolean optimizeGray, boolean omitAlphaOnExpand)
PackedColorModel
to ComponentColorModel
, which seems to be well accepted from
PNGEncoder
and TIFFEncoder
. The omitAlphaOnExpand param allows to explicity
avoid producing an alpha band when expanding an IndexColorModel
to ComponentColorModel
. This may be useful when preparing an Image for JPEG encoding which do
not support alpha band, avoiding the need of a BandSelect right after the color expansion.
Note that this flag has only effect when expanding from IndexColorModel
so alpha is
preserved if input colorModel is already a ComponentColorModel.
This code is adapted from jai-interests mailing list archive.
checkTransparent
- optimizeGray
- omitAlphaOnExpand
- ImageWorker
.FormatDescriptor
public final ImageWorker removeIndexColorModel()
public final ImageWorker forceComponentColorModel(boolean checkTransparent)
PackedColorModel
to ComponentColorModel
, which seems to be well accepted from
PNGEncoder
and TIFFEncoder
.
This code is adapted from jai-interests mailing list archive.
checkTransparent
- tells this method to not consider fully transparent pixels when
optimizing grayscale palettes.ImageWorker
.FormatDescriptor
public final ImageWorker forceComponentColorModel(boolean checkTransparent, boolean optimizeGray)
PackedColorModel
to ComponentColorModel
, which seems to be well accepted from
PNGEncoder
and TIFFEncoder
.
This code is adapted from jai-interests mailing list archive.
checkTransparent
- tells this method to not consider fully transparent pixels when
optimizing grayscale palettes.ImageWorker
.FormatDescriptor
public final ImageWorker forceColorSpaceRGB()
ImageWorker
.isColorSpaceRGB()
,
ColorConvertDescriptor
public final ImageWorker forceColorSpaceYCbCr()
ImageWorker
.isColorSpaceRGB()
,
ColorConvertDescriptor
public final ImageWorker forceColorSpaceIHS()
ImageWorker
.ColorConvertDescriptor
public final ImageWorker bandMerge(int writeband)
writeband
- number of bands after the bandmerge.ImageWorker
.public final ImageWorker addBand(RenderedImage image, boolean before)
image
- to merge with the underlying one.before
- true
if we want to use first the provided image, false
otherwise.ImageWorker
.public final ImageWorker addBand(RenderedImage image, boolean before, boolean addAlpha, Range nodata2)
image
- to merge with the underlying one.before
- true
if we want to use first the provided image, false
otherwise.addAlpha
- true
if we want to set the last image as alpha, false
otherwise.ImageWorker
.public final ImageWorker addBands(RenderedImage[] bands, boolean addAlpha, Range[] nodata2)
image
- to merge with the underlying one.before
- true
if we want to use first the provided image, false
otherwise.addAlpha
- true
if we want to set the last image as alpha, false
otherwise.ImageWorker
.public final ImageWorker addBands(RenderedImage[] bands, boolean addAlpha, Range[] nodata2, List<AffineTransform> transformationList)
image
- to merge with the underlying one.before
- true
if we want to use first the provided image, false
otherwise.addAlpha
- true
if we want to set the last image as alpha, false
otherwise.transformationList
- List of AffineTransformation that can be applied to the input
rasters in order to repoject them to the same CRS.ImageWorker
.public final ImageWorker forceColorSpaceGRAYScale()
ImageWorker
.isColorSpaceGRAYScale()
,
ColorConvertDescriptor
public final ImageWorker intensity()
ImageWorker
.BandCombineDescriptor
public final ImageWorker retainFirstBand()
ImageWorker
.getNumBands()
,
retainBands(int)
,
BandSelectDescriptor
public final ImageWorker retainLastBand()
It is worth to point out that we use the true number of bands rather than the number of color components. This means that if we apply this method on a colormapped image we get back the image itself untouched since it originally contains 1 band although the color components are 3 or 4 as per the attached colormap.
ImageWorker
.getNumBands()
,
retainBands(int)
,
BandSelectDescriptor
public final ImageWorker retainBands(int numBands)
numBands
of image. All other bands
(if any) are discarted without any further processing. This method does nothing if the
current image does not have a greater amount of bands than numBands
.numBands
- the number of bands to retain.ImageWorker
.getNumBands()
,
retainFirstBand()
,
BandSelectDescriptor
public final ImageWorker retainBands(int[] bands)
bands
- the bands to retain.ImageWorker
.getNumBands()
,
retainFirstBand()
,
BandSelectDescriptor
public final ImageWorker format(int dataType)
dataType
- to be used for this FormatDescriptor
operation.ImageWorker
public final ImageWorker binarize()
ImageWorker
.isBinary()
,
binarize(double)
,
binarize(int,int)
,
BinarizeDescriptor
public final ImageWorker binarize(double threshold)
threshold
- The threshold value.ImageWorker
.isBinary()
,
binarize()
,
binarize(int,int)
,
BinarizeDescriptor
public final ImageWorker binarize(int value0, int 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.ImageWorker
.isBinary()
,
binarize()
,
binarize(double)
,
BinarizeDescriptor
,
LookupDescriptor
public final ImageWorker makeColorTransparent(Color transparentColor) throws IllegalStateException
IndexColorModel
, or by ComponentColorModel
with TYPE_BYTE
. More types may be added in
future GeoTools versions.transparentColor
- The color to make transparent.IllegalStateException
- if the current image has an unsupported color
model.public final ImageWorker invert()
InvertDescriptor
public final ImageWorker mask(RenderedImage mask, boolean maskValue, int newValue)
maskValue
, the corresponding pixel in
the image will be set to the specified newValue
.
Note: current implementation force the color model to an indexed one. Future versions may avoid this change.
mask
- The mask to apply, as a binarized image.maskValue
- The mask value to search for (false
for 0 or true
for 1).newValue
- The new value for every pixels in image corresponding to maskValue
in the mask.ImageWorker
.public final ImageWorker addImage(RenderedImage renderedImage)
AddDescriptor
for
details.renderedImage
- the RenderedImage
to be added to this ImageWorker
.ImageWorker
.AddDescriptor
public final ImageWorker multiplyConst(double[] inValues)
MultiplyConstDescriptor
for details.inValues
- The constants to be multiplied.ImageWorker
.MultiplyConstDescriptor
public final ImageWorker multiply(RenderedImage renderedImage)
MultiplyDescriptor
for details.renderedImage
- the RenderedImage
to be multiplied to this ImageWorker
.ImageWorker
.MultiplyDescriptor
public final ImageWorker xorConst(int[] values)
XorConstDescriptor
for details.XorConstDescriptor
public final ImageWorker subtract(RenderedImage renderedImage)
AddDescriptor
for details.renderedImage
- the RenderedImage
to be subtracted to this ImageWorker
.ImageWorker
.SubtractDescriptor
public final ImageWorker or(RenderedImage renderedImage)
AddDescriptor
for details.renderedImage
- the RenderedImage
to be subtracted to this ImageWorker
.ImageWorker
.SubtractDescriptor
public final ImageWorker artifactsFilter(int threshold, int filterSize)
public ImageWorker addTransparencyToIndexColorModel(RenderedImage alphaChannel, boolean errorDiffusion)
false
in the specified transparency
mask, the corresponding pixel in the image is set to the transparent pixel
value. All other pixels are left unchanged.alphaChannel
- The mask to apply as a binarized image.errorDiffusion
- Tells if I should use ErrorDiffusionDescriptor
or OrderedDitherDescriptor
JAi operations.ImageWorker
.isTranslucent()
,
forceBitmaskIndexColorModel()
public final ImageWorker addTransparencyToIndexColorModel(RenderedImage alphaChannel, boolean translucent, int transparent, boolean errorDiffusion)
transparent
pixel, if needed (this method may skip this step if the specified pixel
is already transparent. Then for all pixels with the value false
in the specified
transparency mask, the corresponding pixel in the image is set to that
transparent value. All other pixels are left unchanged.alphaChannel
- The mask to apply as a binarized image.translucent
- true
if translucent images
are allowed, or false
if the resulting images must be a bitmask.transparent
- The value for transparent pixels, to be given to every pixels in the
image corresponding to false
in the mask. The special value -1
maps to the last pixel value allowed for the indexed
color model.errorDiffusion
- Tells if I should use ErrorDiffusionDescriptor
or OrderedDitherDescriptor
JAi operations.ImageWorker
.public final ImageWorker tile()
write(java.io.File)
methods only.ImageWorker
.public ImageWorker applyOpacity(float opacity)
opacity
- The opacity to be applied, between 0 and 1ImageWorker
.public final ImageWorker write(File output) throws IOException
ImageIO#write(String,File)
in a number of ways:
File
objects as input, then the file
argument is given directly without creating an ImageOutputStream
object. This
is important for some formats like HDF, which work only with files.
forceIndexColorModelForGIF(boolean)
.
ImageWorker
.IOException
public final void writePNG(Object destination, String compression, float compressionRate, boolean nativeAcc, boolean paletted) throws IOException
ImageWorker
as a PNG using the provided
destination, compression and compression rate.
The destination object can be anything providing that we have an ImageOutputStreamSpi
that recognizes it.
destination
- where to write the internal image
as a PNG.compression
- algorithm.compressionRate
- percentage of compression.nativeAcc
- should we use native acceleration.paletted
- should we write the png as 8 bits?IOException
- In case an error occurs during the search for an ImageOutputStream
or during the eoncding process.public final ImageWorker writeGIF(Object destination, String compression, float compressionRate) throws IOException
ImageWorker
as a GIF using the provided
destination, compression and compression rate.
It is worth to point out that the only compressions algorithm available with the jdk
GIFImageWriter
is "LZW" while the compression rates have to be confined between 0 and
1. AN acceptable values is usally 0.75f.
The destination object can be anything providing that we have an ImageOutputStreamSpi
that recognizes it.
destination
- where to write the internal image
as a gif.compression
- The name of compression algorithm.compressionRate
- percentage of compression, as a number between 0 and 1.ImageWorker
.IOException
- In case an error occurs during the search for an ImageOutputStream
or during the eoncding process.forceIndexColorModelForGIF(boolean)
public final void writeJPEG(Object destination, String compression, float compressionRate, boolean nativeAcc) throws IOException
ImageWorker
as a JPEG using the provided
destination , compression and compression rate.
The destination object can be anything providing that we have an ImageOutputStreamSpi
that recognizes it.
destination
- where to write the internal image
as a JPEG.compression
- algorithm.compressionRate
- percentage of compression.nativeAcc
- should we use native acceleration.IOException
- In case an error occurs during the search for an ImageOutputStream
or during the eoncding process.public final void writeTIFF(Object destination, String compression, float compressionRate, int tileSizeX, int tileSizeY) throws IOException
ImageWorker
as a TIFF using the provided
destination, compression and compression rate and basic tiling information
The destination object can be anything providing that we have an ImageOutputStreamSpi
that recognizes it.
destination
- where to write the internal image
as a TIFF.compression
- algorithm.compressionRate
- percentage of compression.nativeAcc
- should we use native acceleration.tileSizeX
- tile size x direction (or -1 if tiling is not desired)tileSizeY
- tile size y direction (or -1 if tiling is not desired)IOException
- In case an error occurs during the search for an ImageOutputStream
or during the eoncding process.public ImageWorker affine(AffineTransform tx, Interpolation interpolation, double[] bgValues)
tx
- interpolation
- bgValues
- public ImageWorker crop(float x, float y, float width, float height)
x
- y
- width
- height
- public ImageWorker function(ImageFunction function, int w, int h, float xScale, float yScale, float xTrans, float yTrans)
public ImageWorker mosaic(RenderedImage[] images, MosaicType type, PlanarImage[] alphas, ROI[] rois, double[][] thresholds, Range[] nodata)
public ImageWorker border(int leftPad, int rightPad, int topPad, int bottomPad, BorderExtender ext)
public ImageWorker translate(float xTrans, float yTrans, Interpolation interp)
public ImageWorker warp(Warp warp, Interpolation interp)
public ImageWorker scale(double xScale, double yScale, double xTrans, double yTrans, Interpolation interp)
public ImageWorker lookup(LookupTable table)
public ImageWorker colorIndex(ColorIndexer indexer)
public ImageWorker classify(ColorMapTransform domain1D, Integer bandIndex)
public ImageWorker piecewise(PiecewiseTransform1D transform, Integer bandIndex)
public ImageWorker rescale(double[] scale, double[] offset)
public ImageWorker bandCombine(double[][] coeff)
public ImageWorker rangeLookup(Object rangeLookup)
public ImageWorker prepareForRendering()
public final ImageWorker show() throws HeadlessException
gt2-widgets-swing.jar
file in the classpath.ImageWorker
.HeadlessException
- if gt2-widgets-swing.jar
is not on the classpath, or if AWT
can't create the window components.org.geotools.gui.swing.image.OperationTreeBrowser#show(RenderedImage)
public final void dispose()
ImageWorker
will no longer be accessed from a reference in
user space. The results are equivalent to those that occur when the program loses its last
reference to this image, the garbage collector discovers this, and finalize is called. This
can be used as a hint in situations where waiting for garbage collection would be overly
conservative.
Mind, this also results in disposing the JAI Image chain attached to the image the worker is applied to, so don't call this method on image changes (full/partial) that you want to use.
ImageWorker
defines this method to remove the image being disposed from the list
of sinks in all of its source images. The results of referencing an ImageWorker
after
a call to dispose() are undefined.
public static void main(String[] args)
-operation
argument is provided, the Java
method (one of the image operations provided in this class) immediately following it is
executed. Example:
java org.geotools.image.ImageWorker -operation binarize <var><filename></var>
Copyright © 1996–2019 Geotools. All rights reserved.