Class ImageWorker
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.
- Since:
- 2.3
- Author:
- Simone Giannecchini, Bryce Nordgren, Martin Desruisseaux
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Workaround class for compressing PNG using the default PNGImageEncoder shipped with the JDK. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Hints.Key
Specify whether to set a ROI property when doing a mosaic, even when background is specifiedprotected RenderedImage
The image being built.static final boolean
static final String
static final Hints.Key
Specify whether to preserve chained affines instead of collapsing themstatic final String
static final String
static final String
static final Hints.Key
IfFALSE
, image operators are not allowed to produce tiled images.static final boolean
static final String
static final String
Controls the warp-affine reduction -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new uninitialized builder for an image read or a mosaic operationImageWorker
(RenderedImage image) Creates a new builder for the specified image.ImageWorker
(RenderingHints hints) Creates a new uninitialized worker with RenderingHints for a mosaic operationImageWorker
(File input) Creates a new builder for an image read from the specified file. -
Method Summary
Modifier and TypeMethodDescriptionfinal ImageWorker
addBand
(RenderedImage image, boolean before) Perform a BandMerge operation between the underlying image and the provided one.final ImageWorker
addBand
(RenderedImage image, boolean before, boolean addAlpha, Range nodata2) Perform a BandMerge operation between the underlying image and the provided one.final ImageWorker
addBands
(RenderedImage[] bands, boolean addAlpha, Range[] nodata2) Perform a BandMerge operation between the underlying image and the provided one.final ImageWorker
addBands
(RenderedImage[] bands, boolean addAlpha, Range[] nodata2, List<AffineTransform> transformationList) Perform a BandMerge operation between the underlying image and the provided one.final 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.addTransparencyToIndexColorModel
(RenderedImage alphaChannel, boolean errorDiffusion) Adds transparency to a preexisting image whose color model is index color model.final ImageWorker
addTransparencyToIndexColorModel
(RenderedImage alphaChannel, boolean translucent, int transparent, boolean errorDiffusion) Adds transparency to a preexisting image whose color model is index color model.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 translatesapplyOpacity
(float opacity) Applies the specified opacity to the image by either adding an alpha band, or modifying the existing one by multiplicationfinal ImageWorker
artifactsFilter
(int threshold, int filterSize) bandCombine
(double[][] coeff) Apply a rescale operation on the underlying image.final ImageWorker
bandMerge
(int writeband) Add the bands to the Component Color Modelfinal ImageWorker
binarize()
Binarizes the image.final ImageWorker
binarize
(double threshold) Binarizes the image.final ImageWorker
binarize
(int value0, int value1) Binarizes the image (if not already done) and replace all 0 values byvalue0
and all 1 values byvalue1
.border
(int leftPad, int rightPad, int topPad, int bottomPad, BorderExtender ext) Apply a Raster classification on the underlying image.colorIndex
(ColorIndexer indexer) Warps the underlying using the provided Warp object.crop
(float x, float y, float width, float height) Crops the image to the specified bounds.final void
dispose()
Provides a hint that thisImageWorker
will no longer be accessed from a reference in user space.Range
final ImageWorker
final ImageWorker
forceBitmaskIndexColorModel
(int suggestedTransparent, boolean errorDiffusion) final ImageWorker
Forces the image color model to the GRAYScale color space.final ImageWorker
Forces the image color model to the IHS color space.final ImageWorker
Forces the image color model to the RGB color space.final ImageWorker
Forces the image color model to the YCbCr color space.final ImageWorker
Reformats the color model to a component color model preserving transparency.final ImageWorker
forceComponentColorModel
(boolean checkTransparent) Reformats the color model to a component color model preserving transparency.final ImageWorker
forceComponentColorModel
(boolean checkTransparent, boolean optimizeGray) Reformats the color model to a component color model preserving transparency.final ImageWorker
forceComponentColorModel
(boolean checkTransparent, boolean optimizeGray, boolean omitAlphaOnExpand) Reformats the color model to a component color model preserving transparency.final ImageWorker
forceIndexColorModel
(boolean error) Reduces the color model to index color model.final ImageWorker
forceIndexColorModelForGIF
(boolean errorDiffusion) Converts the image to a GIF-compliant image.final ImageWorker
format
(int dataType) Formats the underlying image to the provided data type.function
(ImageFunction function, int w, int h, float xScale, float yScale, float xTrans, float yTrans) final BufferedImage
Returns the current image as a buffered image.final double[]
Returns the NoData Range currently set, ornull
if none.Histogram
getHistogram
(int[] numBins, double[] lowValues, double[] highValues) Returns the histogram of the image.final ROI
Returns a Region Of Interest built from the current image.final double[]
Returns the maximal values found in every image bands.double[]
getMean()
Returns the minimums and maximums values found in the image.final double[]
Returns the minimal values found in every image bands.final Range
Returns the NoData Range currently set, ornull
if none.final int
Returns the number of bands in the image.protected static OperationDescriptor
getOperationDescriptor
(String name) final PlanarImage
Returns the rendered image as a planar image.final RenderedImage
Returns the current image.final RenderedOp
Returns the rendered image as a rendered operation.final Object
Returns the rendering hint for the specified key, ornull
if none.final RenderingHints
Returns the rendering hints for an image to be computed by this class.final ROI
getROI()
Returns the region of interest currently set, ornull
if none.final int
Returns the transparent pixel value, or -1 if none.int
The x-period used by statistical operations (e.g. extrema, mean, histogram).int
The y-period used by statistical operations (e.g. extrema, mean, histogram).final ImageWorker
Creates an image which represents approximatively the intensity of image.final ImageWorker
invert()
Inverts the pixel values of the image.final boolean
isBinary()
Returnstrue
if the image is binary.final boolean
isBytes()
Returnstrue
if the image stores its pixel values in 8 bits.final boolean
final boolean
final boolean
final boolean
final boolean
static boolean
boolean
Returns true if destination NoData values must be set and they must be used in computationfinal boolean
final void
Loads an image using the provided file name and the current hints, which are used to control caching and layout.lookup
(LookupTable table) Performs Lookup on the underlying imagestatic void
Loads the image from the specified file, and display it in a window.final ImageWorker
makeColorTransparent
(Color transparentColor) Replaces all occurences of the given color (usually opaque) by a fully transparent color.final ImageWorker
mask
(RenderedImage mask, boolean maskValue, int newValue) Applies the specified mask over the current image.max
(RenderedImage[] sources) Copmputes a pixel-by-pixel maximum value from all the provided sources.min
(RenderedImage[] sources) Copmputes a pixel-by-pixel minimum value from all the provided sources.mosaic
(RenderedImage[] images, MosaicType type, PlanarImage[] alphas, ROI[] rois, double[][] thresholds, Range[] nodata) final 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.final 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.nullOp()
Returns the rendered image after null operation.final 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.Apply a Generic Piecewise operation on the underlying image.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).rangeLookup
(Object rangeLookup) Apply a rangeLookup operation on the underlying image.final ImageWorker
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.final ImageWorker
Removes a rendering hint.final ImageWorker
rescale
(double[] scale, double[] offset) Apply a rescale operation on the underlying image.final ImageWorker
Rescales the image such that it uses 8 bits.final ImageWorker
retainBands
(int numBands) Retains inconditionnaly the firstnumBands
of image.final ImageWorker
retainBands
(int[] bands) Retains inconditionnaly certain bands of image.final ImageWorker
Retains inconditionnaly the first band of image.final ImageWorker
Retains unconditionally the last band of image.scale
(double xScale, double yScale, double xTrans, double yTrans, Interpolation interp) Scales the underlying raster using the provided parameters.final ImageWorker
setBackground
(double[] background) Set the image background valuefinal ImageWorker
setImage
(RenderedImage image) Prepare this builder for the specified image.final ImageWorker
setNoData
(Range nodata) Set the NoData Range for checking NoData during computation.final ImageWorker
setRenderingHint
(RenderingHints.Key key, Object value) Sets a rendering hint tile to use for all images to be computed by this class.final ImageWorker
setRenderingHints
(RenderingHints hints) Set a map of rendering hints to use for all images to be computed by this class.final ImageWorker
setROI
(ROI roi) Set the region of interest (ROI).setXPeriod
(int xPeriod) Sets the x-period used by statistical operations (e.g. extrema, mean, histogram).setYPeriod
(int yPeriod) Sets the x-period used by statistical operations (e.g. extrema, mean, histogram).final ImageWorker
show()
final 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.final ImageWorker
tile()
If the was not already tiled, tile it.final ImageWorker
tileCacheEnabled
(boolean status) Iffalse
, disables the tile cache.translate
(float xTrans, float yTrans, Interpolation interp) warp
(Warp warp, Interpolation interp) Warps the underlying raster using the provided Warp object.final ImageWorker
Writes the image to the specified file.final ImageWorker
Writes outs the image contained into thisImageWorker
as a GIF using the provided destination, compression and compression rate.final void
Writes outs the image contained into thisImageWorker
as a JPEG using the provided destination , compression and compression rate.final void
writePNG
(Object destination, String compression, float compressionRate, boolean nativeAcc, boolean paletted) Writes outs the image contained into thisImageWorker
as a PNG using the provided destination, compression and compression rate.final void
writeTIFF
(Object destination, String compression, float compressionRate, int tileSizeX, int tileSizeY) Writes outs the image contained into thisImageWorker
as a TIFF using the provided destination, compression and compression rate and basic tiling informationfinal 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.
-
Field Details
-
SCALE_NAME
- See Also:
-
SCALE2_NAME
- See Also:
-
SCALE_OP_NAME
-
JAIEXT_ENABLED_KEY
- See Also:
-
USE_JAI_SCALE2_KEY
- See Also:
-
JAIEXT_ENABLED
public static final boolean JAIEXT_ENABLED -
USE_JAI_SCALE2
public static final boolean USE_JAI_SCALE2 -
WARP_REDUCTION_ENABLED_KEY
Controls the warp-affine reduction- See Also:
-
TILING_ALLOWED
-
FORCE_MOSAIC_ROI_PROPERTY
Specify whether to set a ROI property when doing a mosaic, even when background is specified -
PRESERVE_CHAINED_AFFINES
Specify whether to preserve chained affines instead of collapsing them -
image
The image being built.
-
-
Constructor Details
-
ImageWorker
public ImageWorker()Creates a new uninitialized builder for an image read or a mosaic operation -
ImageWorker
Creates a new uninitialized worker with RenderingHints for a mosaic operation -
ImageWorker
Creates a new builder for an image read from the specified file.- Parameters:
input
- The file to read.- Throws:
IOException
- if the file can't be read.
-
ImageWorker
Creates a new builder 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 Details
-
isJaiExtEnabled
public static boolean isJaiExtEnabled() -
getOperationDescriptor
protected static OperationDescriptor getOperationDescriptor(String name) throws OperationNotFoundException - Throws:
OperationNotFoundException
-
getXPeriod
public int getXPeriod()The x-period used by statistical operations (e.g. extrema, mean, histogram). Defaults to 1. -
setXPeriod
Sets the x-period used by statistical operations (e.g. extrema, mean, histogram). E.g., setting it to 2 wil make the statistical operations read one pixel and skip one pixel, and so on. -
getYPeriod
public int getYPeriod()The y-period used by statistical operations (e.g. extrema, mean, histogram). Defaults to 1. -
setYPeriod
Sets the x-period used by statistical operations (e.g. extrema, mean, histogram). E.g., setting it to 2 wil make the statistical operations read one pixel and skip one pixel, and so on. -
extractNoDataProperty
-
setImage
Prepare this builder 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.
-
load
Loads an image using the provided file name and the current hints, which are used to control caching and layout.- Parameters:
source
- Filename of the source image to read.imageChoice
- Image index in multipage images.readMetadata
- Iftrue
, metadata will be read.
-
getRenderedImage
Returns the current image.- Returns:
- The rendered image.
- See Also:
-
getBufferedImage
Returns the current image as a buffered image.- Returns:
- The buffered image.
- Since:
- 2.5
- See Also:
-
getPlanarImage
public final PlanarImage getPlanarImage()Returns the rendered image as a planar image.- Returns:
- The planar image.
- See Also:
-
getRenderedOperation
public final RenderedOp getRenderedOperation()Returns the rendered image as a rendered operation.- Returns:
- The rendered operation.
- See Also:
-
nullOp
Returns the rendered image after null operation. This operation may be used for setting new ImageProperties or for applying new RenderingHints.- Returns:
- The rendered operation.
- See Also:
-
getImageAsROI
public final ROI getImageAsROI()Returns a Region Of Interest built from the current image. If the image is multi-bands, then this method first computes an estimation of its intensity. Next, this method binarize the image and constructs aROI
from the result.- Returns:
- The image as a region of interest.
- See Also:
-
getROI
public final ROI getROI()Returns the region of interest currently set, ornull
if none. The default value isnull
.- Returns:
- The current region of interest.
- See Also:
-
getNoData
public final Range getNoData()Returns the NoData Range currently set, ornull
if none. The default value isnull
.- Returns:
- The current NoData Range.
-
getDestinationNoData
public final double[] getDestinationNoData()Returns the NoData Range currently set, ornull
if none. The default value isnull
.- Returns:
- The current NoData Range.
-
isNoDataNeeded
public boolean isNoDataNeeded()Returns true if destination NoData values must be set and they must be used in computation -
setROI
Set the region of interest (ROI). Anull
set the ROI to the whole image. The ROI is used by statistical methods likegetMinimums()
andgetMaximums()
.- Parameters:
roi
- The new region of interest.- Returns:
- This ImageWorker
- See Also:
-
setNoData
Set the NoData Range for checking NoData during computation.- Parameters:
nodata
- The new NoData Range.- Returns:
- This ImageWorker
-
setBackground
Set the image background value- Parameters:
background
- The image background.- Returns:
- This ImageWorker
-
getRenderingHint
Returns the rendering hint for the specified key, ornull
if none. -
setRenderingHint
Sets a rendering hint tile to use for all images to be computed by this class. This method applies only to the next images to be computed; images already computed before this method call (if any) will not be affected.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.
- Returns:
- This ImageWorker
-
setRenderingHints
Set a map of rendering hints to use for all images to be computed by this class. This method applies only to the next images to be computed; images already computed before this method call (if any) will not be affected.If
hints
is null we won't modify this list.- Returns:
- This ImageWorker
- See Also:
-
#setRenderingHint(RenderingHint)
-
removeRenderingHints
-
removeRenderingHint
Removes a rendering hint. Note that invoking this method is not the same than invokingsetRenderingHint(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.
- Returns:
- This ImageWorker
-
getRenderingHints
Returns the rendering hints for an image to be computed by this class. The default implementation returns the following hints:- An image layout with tiles size computed automatically from the current image size.
- Any additional hints specified through the
setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)
method. If the user provided explicitly aJAI.KEY_IMAGE_LAYOUT
, then the user layout has precedence over the automatic layout computed in previous step.
- Returns:
- The rendering hints to use for image computation (never
null
).
-
tileCacheEnabled
Iffalse
, disables the tile cache. Invoking this method with valuetrue
cancel the last invocation with valuefalse
. If this method was invoking many time with valuefalse
, then this method must be invoked the same amount of time with the valuetrue
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.- Returns:
- This ImageWorker
-
getNumBands
public final int getNumBands()Returns the number of bands in the image. -
getTransparentPixel
public final int getTransparentPixel()Returns the transparent pixel value, or -1 if none. -
getHistogram
public Histogram getHistogram(int[] numBins, double[] lowValues, double[] highValues) Returns the histogram of the image. -
getMean
public double[] getMean()Returns the minimums and maximums values found in the image. Those extremas are returned as an array of the formdouble[2][#bands]
. -
getMinimums
public final double[] getMinimums()Returns the minimal values found in every image bands. If a region of interest is defined, then the statistics will be computed only over that region.- See Also:
-
getMaximums
public final double[] getMaximums()Returns the maximal values found in every image bands. If a region of interest is defined, then the statistics will be computed only over that region.- See Also:
-
isBytes
public final boolean isBytes()Returnstrue
if the image stores its pixel values in 8 bits.- See Also:
-
isBinary
public final boolean isBinary()Returnstrue
if the image is binary. Such image usually contains only two values: 0 and 1.- See Also:
-
isIndexed
public final boolean isIndexed() -
isColorSpaceRGB
public final boolean isColorSpaceRGB()Returnstrue
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.- See Also:
-
isColorSpaceYCbCr
public final boolean isColorSpaceYCbCr()- See Also:
-
isColorSpaceIHS
public final boolean isColorSpaceIHS()- See Also:
-
isColorSpaceGRAYScale
public final boolean isColorSpaceGRAYScale()Returnstrue
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.- See Also:
-
isTranslucent
public final boolean isTranslucent()- See Also:
-
rescaleToBytes
Rescales the image such that it uses 8 bits. If the image already uses 8 bits, then this method does nothing. Otherwise this method computes the minimum and maximum values for each band, rescale them in the range[0 .. 255]
and force the resulting image toTYPE_BYTE
.- Returns:
- This ImageWorker
- See Also:
-
isBytes()
RescaleDescriptor
-
forceIndexColorModel
Reduces the color model to index color model. If the current image already uses an index color model, then this method do nothing. Otherwise, the current implementation performs a ditering on the original color model. Note that this operation loose the alpha channel.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 anIndexColorModel
.If an
IndexColorModel
with a single transparency index is enough for you, we advise you to take a look atforceIndexColorModelForGIF(boolean)
methdo.- See Also:
-
isIndexed()
forceBitmaskIndexColorModel()
forceIndexColorModelForGIF(boolean)
OrderedDitherDescriptor
-
forceBitmaskIndexColorModel
Reduces the color model to index color model with opaque or bitmask transparency. If the current image already uses a suitable color model, then this method do nothing.- Returns:
- this
ImageWorker
. - See Also:
-
forceBitmaskIndexColorModel
public final ImageWorker forceBitmaskIndexColorModel(int suggestedTransparent, boolean errorDiffusion) Reduces the color model to index color model with opaque or bitmask transparency. If the current image already uses a suitable color model, then this method do nothing.- Parameters:
suggestedTransparent
- A suggested pixel index to define as the transparent pixel. *errorDiffusion
- Tells if I should useErrorDiffusionDescriptor
orOrderedDitherDescriptor
JAi operations. errorDiffusion- Returns:
- this
ImageWorker
. - See Also:
-
forceIndexColorModelForGIF
Converts the image to a GIF-compliant image. This method has been created in order to convert the input image to a form that is compatible with the GIF model. It first remove the information about transparency since the error diffusion and the error dither operations are unable to process images with more than 3 bands. Afterwards the image is processed with an error diffusion operator in order to reduce the number of bands from 3 to 1 and the number of color to 216. A suitable layout is used for the final image via the rendering hints in order to take into account the different layout model for the final image.Tip: For optimizing writing GIF, we need to create the image untiled. This can be done by invoking
setRenderingHint(TILING_ALLOWED, Boolean.FALSE)
first.- Parameters:
errorDiffusion
- Tells if I should useErrorDiffusionDescriptor
orOrderedDitherDescriptor
JAi operations.- Returns:
- this
ImageWorker
. - See Also:
-
forceComponentColorModel
Reformats the color model to a component color model preserving transparency. This is used especially in order to go fromPackedColorModel
toComponentColorModel
, which seems to be well accepted fromPNGEncoder
andTIFFEncoder
.This code is adapted from jai-interests mailing list archive.
- Returns:
- this
ImageWorker
. - See Also:
-
FormatDescriptor
-
forceComponentColorModel
public final ImageWorker forceComponentColorModel(boolean checkTransparent, boolean optimizeGray, boolean omitAlphaOnExpand) Reformats the color model to a component color model preserving transparency. This is used especially in order to go fromPackedColorModel
toComponentColorModel
, which seems to be well accepted fromPNGEncoder
andTIFFEncoder
. The omitAlphaOnExpand param allows to explicity avoid producing an alpha band when expanding anIndexColorModel
toComponentColorModel
. 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 fromIndexColorModel
so alpha is preserved if input colorModel is already a ComponentColorModel.This code is adapted from jai-interests mailing list archive.
- Returns:
- this
ImageWorker
. - See Also:
-
FormatDescriptor
-
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. -
forceComponentColorModel
Reformats the color model to a component color model preserving transparency. This is used especially in order to go fromPackedColorModel
toComponentColorModel
, which seems to be well accepted fromPNGEncoder
andTIFFEncoder
.This code is adapted from jai-interests mailing list archive.
- Parameters:
checkTransparent
- tells this method to not consider fully transparent pixels when optimizing grayscale palettes.- Returns:
- this
ImageWorker
. - See Also:
-
FormatDescriptor
-
forceComponentColorModel
Reformats the color model to a component color model preserving transparency. This is used especially in order to go fromPackedColorModel
toComponentColorModel
, which seems to be well accepted fromPNGEncoder
andTIFFEncoder
.This code is adapted from jai-interests mailing list archive.
- Parameters:
checkTransparent
- tells this method to not consider fully transparent pixels when optimizing grayscale palettes.- Returns:
- this
ImageWorker
. - See Also:
-
FormatDescriptor
-
forceColorSpaceRGB
Forces the image color model to the RGB color space. If the current color space is already of RGB type, then this method does nothing. This operation may loose the alpha channel.- Returns:
- this
ImageWorker
. - See Also:
-
isColorSpaceRGB()
ColorConvertDescriptor
-
forceColorSpaceYCbCr
Forces the image color model to the YCbCr color space. If the current color space is already of YCbCr, then this method does nothing.- Returns:
- this
ImageWorker
. - See Also:
-
isColorSpaceRGB()
ColorConvertDescriptor
-
forceColorSpaceIHS
Forces the image color model to the IHS color space. If the current color space is already of IHS type, then this method does nothing. This operation may loose the alpha channel.- Returns:
- this
ImageWorker
. - See Also:
-
ColorConvertDescriptor
-
bandMerge
Add the bands to the Component Color Model- Parameters:
writeband
- number of bands after the bandmerge.- Returns:
- this
ImageWorker
.
-
addBand
Perform a BandMerge operation between the underlying image and the provided one.- Parameters:
image
- to merge with the underlying one.before
-true
if we want to use first the provided image,false
otherwise.- Returns:
- this
ImageWorker
.
-
addBand
public final ImageWorker addBand(RenderedImage image, boolean before, boolean addAlpha, Range nodata2) Perform a BandMerge operation between the underlying image and the provided one.- Parameters:
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.- Returns:
- this
ImageWorker
.
-
addBands
Perform a BandMerge operation between the underlying image and the provided one.- Parameters:
bands
- to merge with the underlying one.addAlpha
-true
if we want to set the last image as alpha,false
otherwise.- Returns:
- this
ImageWorker
.
-
addBands
public final ImageWorker addBands(RenderedImage[] bands, boolean addAlpha, Range[] nodata2, List<AffineTransform> transformationList) Perform a BandMerge operation between the underlying image and the provided one.- Parameters:
bands
- images to merge with the underlying one.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.- Returns:
- this
ImageWorker
.
-
forceColorSpaceGRAYScale
Forces the image color model to the GRAYScale color space. If the current color space is already of type, then this method does nothing.- Returns:
- this
ImageWorker
. - See Also:
-
isColorSpaceGRAYScale()
ColorConvertDescriptor
-
intensity
Creates an image which represents approximatively the intensity of image. The result is always a single-banded image. If the image uses an IHS color space, then this method just retain 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 the image based on the average value of the color components. It is worthwhile to note that the alpha band is stripped from the image.- Returns:
- this
ImageWorker
. - See Also:
-
BandCombineDescriptor
-
retainFirstBand
Retains inconditionnaly the first band of image. All other bands (if any) are discarted without any further processing.- Returns:
- this
ImageWorker
. - See Also:
-
getNumBands()
retainBands(int)
BandSelectDescriptor
-
retainLastBand
Retains unconditionally the last band of image. All other bands (if any) are discarded without any further processing.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.
- Returns:
- this
ImageWorker
. - See Also:
-
getNumBands()
retainBands(int)
BandSelectDescriptor
-
retainBands
Retains inconditionnaly the firstnumBands
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 thannumBands
.- Parameters:
numBands
- the number of bands to retain.- Returns:
- this
ImageWorker
. - See Also:
-
getNumBands()
retainFirstBand()
BandSelectDescriptor
-
retainBands
Retains inconditionnaly certain bands of image. All other bands (if any) are discarded without any further processing.- Parameters:
bands
- the bands to retain.- Returns:
- this
ImageWorker
. - See Also:
-
getNumBands()
retainFirstBand()
BandSelectDescriptor
-
format
Formats the underlying image to the provided data type.- Parameters:
dataType
- to be used for thisFormatDescriptor
operation.- Returns:
- this
ImageWorker
-
binarize
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.- Returns:
- this
ImageWorker
. - See Also:
-
isBinary()
binarize(double)
binarize(int,int)
BinarizeDescriptor
-
binarize
Binarizes the image. If the image is already binarized, then this method does nothing.- Parameters:
threshold
- The threshold value.- Returns:
- this
ImageWorker
. - See Also:
-
isBinary()
binarize()
binarize(int,int)
BinarizeDescriptor
-
binarize
Binarizes the image (if not already done) and replace all 0 values byvalue0
and all 1 values byvalue1
. If the image should be binarized using a custom threshold value (instead of the automatic one), invokebinarize(double)
explicitly before this method.- Returns:
- this
ImageWorker
. - See Also:
-
isBinary()
binarize()
binarize(double)
BinarizeDescriptor
LookupDescriptor
-
makeColorTransparent
Replaces all occurences of the given color (usually opaque) by a fully transparent color. Currents implementation supports image backed by anyIndexColorModel
, or byComponentColorModel
withTYPE_BYTE
. More types may be added in future GeoTools versions.- Parameters:
transparentColor
- The color to make transparent.- Returns:
- this image worker.
- Throws:
IllegalStateException
- if the current image has an unsupported color model.
-
invert
Inverts the pixel values of the image.- See Also:
-
InvertDescriptor
-
mask
Applies the specified mask over the current image. The mask should be binarized - if it is not, this method will do it itself. Then, for every pixels in the mask with value equals tomaskValue
, the corresponding pixel in the image will be set to the specifiednewValue
.Note: current implementation force the color model to an indexed one. Future versions may avoid this change.
- Parameters:
mask
- The mask to apply, as a binarized image.maskValue
- The mask value to search for (false
for 0 ortrue
for 1).newValue
- The new value for every pixels in image corresponding tomaskValue
in the mask.- Returns:
- this
ImageWorker
.
-
max
Copmputes a pixel-by-pixel maximum value from all the provided sources. The images must share the same raster space. -
min
Copmputes a pixel-by-pixel minimum value from all the provided sources. The images must share the same raster space. -
addImage
Takes two rendered or renderable source images, and adds every pair of pixels, one from each source image of the corresponding position and band. See JAIAddDescriptor
for details.- Parameters:
renderedImage
- theRenderedImage
to be added to thisImageWorker
.- Returns:
- this
ImageWorker
. - See Also:
-
AddDescriptor
-
multiplyConst
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. See JAIMultiplyConstDescriptor
for details.- Parameters:
inValues
- The constants to be multiplied.- Returns:
- this
ImageWorker
. - See Also:
-
MultiplyConstDescriptor
-
multiply
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. See JAIMultiplyDescriptor
for details.- Parameters:
renderedImage
- theRenderedImage
to be multiplied to thisImageWorker
.- Returns:
- this
ImageWorker
. - See Also:
-
MultiplyDescriptor
-
xorConst
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. See JAIXorConstDescriptor
for details.- See Also:
-
XorConstDescriptor
-
subtract
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. See JAIAddDescriptor
for details.- Parameters:
renderedImage
- theRenderedImage
to be subtracted to thisImageWorker
.- Returns:
- this
ImageWorker
. - See Also:
-
SubtractDescriptor
-
or
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. See JAIAddDescriptor
for details.- Parameters:
renderedImage
- theRenderedImage
to be subtracted to thisImageWorker
.- Returns:
- this
ImageWorker
. - See Also:
-
SubtractDescriptor
-
artifactsFilter
-
addTransparencyToIndexColorModel
public ImageWorker addTransparencyToIndexColorModel(RenderedImage alphaChannel, boolean errorDiffusion) Adds transparency to a preexisting image whose color model is index color model. For all pixels with the valuefalse
in the specified transparency mask, the corresponding pixel in the image is set to the transparent pixel value. All other pixels are left unchanged.- Parameters:
alphaChannel
- The mask to apply as a binarized image.errorDiffusion
- Tells if I should useErrorDiffusionDescriptor
orOrderedDitherDescriptor
JAi operations.- Returns:
- this
ImageWorker
. - See Also:
-
addTransparencyToIndexColorModel
public final ImageWorker addTransparencyToIndexColorModel(RenderedImage alphaChannel, boolean translucent, int transparent, boolean errorDiffusion) Adds transparency to a preexisting image whose color model is index color model. First, this method creates a new index color model with the specifiedtransparent
pixel, if needed (this method may skip this step if the specified pixel is already transparent. Then for all pixels with the valuefalse
in the specified transparency mask, the corresponding pixel in the image is set to that transparent value. All other pixels are left unchanged.- Parameters:
alphaChannel
- The mask to apply as a binarized image.translucent
-true
if translucent images are allowed, orfalse
if the resulting images must be a bitmask.transparent
- The value for transparent pixels, to be given to every pixels in the image corresponding tofalse
in the mask. The special value-1
maps to the last pixel value allowed for the indexed color model.errorDiffusion
- Tells if I should useErrorDiffusionDescriptor
orOrderedDitherDescriptor
JAi operations.- Returns:
- this
ImageWorker
.
-
tile
If the was not already tiled, tile it. Note that no tiling will be done if 'getRenderingHints()' failed to suggest a tile size. This method is for internal use bywrite(java.io.File)
methods only.- Returns:
- this
ImageWorker
.
-
applyOpacity
Applies the specified opacity to the image by either adding an alpha band, or modifying the existing one by multiplication- Parameters:
opacity
- The opacity to be applied, between 0 and 1- Returns:
- this
ImageWorker
.
-
write
Writes the image to the specified file. This method differs fromImageIO#write(String,File)
in a number of ways:- The image writer to use is inferred from the file extension.
- If the image writer accepts
File
objects as input, then thefile
argument is given directly without creating anImageOutputStream
object. This is important for some formats like HDF, which work only with files. - If the image is not tiled, then it is tiled prior to be written.
- If some special processing is needed for a given format, then the corresponding method is invoked. Example:
forceIndexColorModelForGIF(boolean)
.
- Returns:
- this
ImageWorker
. - Throws:
IOException
-
writePNG
public final void writePNG(Object destination, String compression, float compressionRate, boolean nativeAcc, boolean paletted) throws IOException Writes outs the image contained into thisImageWorker
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.- Parameters:
destination
- where to write the internalimage
as a PNG.compression
- algorithm.compressionRate
- percentage of compression.nativeAcc
- should we use native acceleration.paletted
- should we write the png as 8 bits?- Throws:
IOException
- In case an error occurs during the search for anImageOutputStream
or during the eoncding process.
-
writeGIF
public final ImageWorker writeGIF(Object destination, String compression, float compressionRate) throws IOException Writes outs the image contained into thisImageWorker
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.- Parameters:
destination
- where to write the internalimage
as a gif.compression
- The name of compression algorithm.compressionRate
- percentage of compression, as a number between 0 and 1.- Returns:
- this
ImageWorker
. - Throws:
IOException
- In case an error occurs during the search for anImageOutputStream
or during the eoncding process.- See Also:
-
writeJPEG
public final void writeJPEG(Object destination, String compression, float compressionRate, boolean nativeAcc) throws IOException Writes outs the image contained into thisImageWorker
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.- Parameters:
destination
- where to write the internalimage
as a JPEG.compression
- algorithm.compressionRate
- percentage of compression.nativeAcc
- should we use native acceleration.- Throws:
IOException
- In case an error occurs during the search for anImageOutputStream
or during the eoncding process.
-
writeTIFF
public final void writeTIFF(Object destination, String compression, float compressionRate, int tileSizeX, int tileSizeY) throws IOException Writes outs the image contained into thisImageWorker
as a TIFF using the provided destination, compression and compression rate and basic tiling informationThe destination object can be anything providing that we have an
ImageOutputStreamSpi
that recognizes it.- Parameters:
destination
- where to write the internalimage
as a TIFF.compression
- algorithm.compressionRate
- percentage of compression.tileSizeX
- tile size x direction (or -1 if tiling is not desired)tileSizeY
- tile size y direction (or -1 if tiling is not desired)- Throws:
IOException
- In case an error occurs during the search for anImageOutputStream
or during the eoncding process.
-
affine
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 -
crop
Crops the image to the specified bounds. Will use an internal operation that ensures the tile cache and tile scheduler hints are used, and will perform operation elimination in case the crop is doing nothing, or in case the crop is performed over another crop -
function
public ImageWorker function(ImageFunction function, int w, int h, float xScale, float yScale, float xTrans, float yTrans) -
mosaic
public ImageWorker mosaic(RenderedImage[] images, MosaicType type, PlanarImage[] alphas, ROI[] rois, double[][] thresholds, Range[] nodata) -
border
-
translate
-
warp
Warps the underlying raster using the provided Warp object. -
scale
public ImageWorker scale(double xScale, double yScale, double xTrans, double yTrans, Interpolation interp) Scales the underlying raster using the provided parameters. -
lookup
Performs Lookup on the underlying image -
colorIndex
Warps the underlying using the provided Warp object. -
classify
Apply a Raster classification on the underlying image. -
piecewise
Apply a Generic Piecewise operation on the underlying image. -
rescale
Apply a rescale operation on the underlying image. -
bandCombine
Apply a rescale operation on the underlying image. -
rangeLookup
Apply a rangeLookup operation on the underlying image. -
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). In case the image has no ROI or no nodata, the method won't perform any change -
show
Shows the current image in a window together with the operation chain as a tree. This method is provided mostly for debugging purpose. This method requires thegt2-widgets-swing.jar
file in the classpath.- Returns:
- this
ImageWorker
. - Throws:
HeadlessException
- ifgt2-widgets-swing.jar
is not on the classpath, or if AWT can't create the window components.- See Also:
-
org.geotools.gui.swing.image.OperationTreeBrowser#show(RenderedImage)
-
dispose
public final void dispose()Provides a hint that thisImageWorker
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 anImageWorker
after a call to dispose() are undefined. -
main
Loads the image from the specified file, and display it in a window. This method is mostly as a convenient way to test operation chains. This method can be invoked from the command line. If an optional-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>
-