Class ImageUtilities
Do not rely on this API!
It may change in incompatible way in any future version.
- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD), Simone Giannecchini, GeoSolutions
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RenderingHintsstatic final BorderExtenderstatic final Stringstatic final RenderingHintsstatic final RenderingHintsCached instance of aRenderingHintsfor controlling border extension onJAIoperations.static final RenderingHintsCached instance of aRenderingHintsfor controlling border extension onJAIoperations.static final String[]List of valid names.static final int[]Interpolation types (provided by Java Advanced Imaging) forINTERPOLATION_NAMES.static final RenderingHintsRenderingHintsfor requesting Nearest Neighbor intepolation.static final RenderingHintsstatic final floatstatic final RenderingHintsstatic final double[][]static final double[][] -
Method Summary
Modifier and TypeMethodDescriptionstatic RenderedImageapplyRescaling(Double[] scales, Double[] offsets, RenderedImage image, Hints hints) Applies values rescaling if either the scales or the offsets array is non null, or has any value that is not a default (1 for scales, 0 for offsets)static final booleancheckEmptySourceRegion(ImageReadParam readParameters, Rectangle dimensions) Checks that the provideddimensionswhen intersected with the source region used by the providedImageReadParaminstance does not result in an emptyRectangle.static ImageReadParamstatic ImageLayoutcreateIntersection(ImageLayout layout, List<RenderedImage> sources) Computes a newImageLayoutwhich is the intersection of the specifiedImageLayoutand allRenderedImages in the supplied list.static voiddisposeImage(RenderedImage inputImage) Allow to dispose this image, as well as the related image sources, readers, stream, ROI.static voiddisposePlanarImageChain(PlanarImage pi) Dispose an image with all its ancestors.static voiddisposeSinglePlanarImage(PlanarImage planarImage) Disposes the specified image, without recursing back in the sourcesstatic voidfill(WritableRenderedImage image, Number value) Sets every samples in the given image to the given value.static Number[]getBackgroundValues(SampleModel sampleModel, double[] backgroundValues) Build a background values array using the same dataType of the inputSampleModel(if available) and the values provided in the input array.static StringgetDatabufferTypeName(int dataType) Transform a data type into a representativeString.static RectanglegetDimension(int imageIndex, ImageInputStream inStream, ImageReader reader) Retrieves the dimensions of theRenderedImageat indeximageIndexfor the providedImageReaderandImageInputStream.static ImageLayoutgetImageLayout(RenderedImage image) Suggests anImageLayoutfor the specified image.static StringgetInterpolationName(Interpolation interp) Returns the interpolation name for the specified interpolation object.static ReferencedEnvelopegetReferencedEnvelopeFromGeographicBoundingBox(GeographicBoundingBox geographicBBox) Builds aReferencedEnvelopefrom aGeographicBoundingBox.static RenderingHintsgetRenderingHints(RenderedImage image) Suggests a set ofRenderingHintsfor the specified image.static ReferencedEnvelopegetWGS84ReferencedEnvelope(GeneralBounds coverageEnvelope) Builds aReferencedEnvelopein WGS84 from aGeneralBounds.static booleanTells me whether or not the native libraries for ImageN are active or not.static Rectangle2DlayoutHelper(RenderedImage source, float scaleX, float scaleY, float transX, float transY, Interpolation interp) static RenderedImagemaskColor(Color transparentColor, RenderedImage image) Relies on theImageWorkerto mask a certain color from an image.static voidsetSubsamplingFactors(ImageReadParam readParameters, double[] requestedRes, double[] selectedRes, int rasterWidth, int rasterHeight) Computes and applies suitable subsampling factors on the givenImageReadParam.static RenderedOptileImage(RenderedOp image) Tiles the specified image.static InterpolationtoInterpolation(Object type) Casts the specified object to anobject.static DimensiontoTileSize(Dimension size) Suggests a tile size for the specified image size.
-
Field Details
-
RGB_TO_GRAY_MATRIX
public static final double[][] RGB_TO_GRAY_MATRIX -
RGBA_TO_GRAY_MATRIX
public static final double[][] RGBA_TO_GRAY_MATRIX -
DONT_REPLACE_INDEX_COLOR_MODEL
-
REPLACE_INDEX_COLOR_MODEL
-
NN_INTERPOLATION_HINT
RenderingHintsfor requesting Nearest Neighbor intepolation. -
NOCACHE_HINT
-
EXTEND_BORDER_BY_COPYING
Cached instance of aRenderingHintsfor controlling border extension onJAIoperations. It contains an instance of aBorderExtenderCopy. -
EXTEND_BORDER_BY_REFLECT
Cached instance of aRenderingHintsfor controlling border extension onJAIoperations. It contains an instance of aBorderExtenderReflect. -
INTERPOLATION_NAMES
List of valid names. Note: the "Optimal" type is not implemented because currently not provided by ImageN. -
INTERPOLATION_TYPES
public static final int[] INTERPOLATION_TYPESInterpolation types (provided by Java Advanced Imaging) forINTERPOLATION_NAMES. -
DEFAULT_BORDER_EXTENDER
public static final BorderExtender DEFAULT_BORDER_EXTENDER -
BORDER_EXTENDER_HINTS
-
DIRECT_KAKADU_PLUGIN
- See Also:
-
RATIONAL_TOLERANCE
public static final float RATIONAL_TOLERANCE- See Also:
-
-
Method Details
-
getImageLayout
Suggests anImageLayoutfor the specified image. All parameters are initially set equal to those of the givenRenderedImage, and then the tile size is updated according the image size. This method never returnsnull. -
getRenderingHints
Suggests a set ofRenderingHintsfor the specified image. The rendering hints may include the following parameters:JAI#KEY_IMAGE_LAYOUTwith a proposed tile size.
nullif no rendering hints is proposed. -
toTileSize
Suggests a tile size for the specified image size. On input,sizeis the image's size. On output, it is the tile size. This method write the result directly in the supplied object and returnssizefor convenience.This method it aimed to computing a tile size such that the tile grid would have overlapped the image bound in order to avoid having tiles crossing the image bounds and being therefore partially empty. This method will never returns a tile size smaller than 256. If this method can't suggest a size, then it left the corresponding
sizefield (widthorheight) unchanged.The
widthandheightfields are processed independently in the same way. The following discussion use thewidthfield as an example.This method inspects different tile sizes close to the default tile size. Lets
widthbe the default tile width. Values are tried in the following order:width,width+1,width-1,width+2,width-2,width+3,width-3, etc. until one of the following happen:- A suitable tile size is found. More specifically, a size is found which is a dividor of the specified image
size, and is the closest one of the default tile size. The
Dimensionfield (widthorheight) is set to this value. - An arbitrary limit (both a minimum and a maximum tile size) is reached. In this case, this method
may set the
Dimensionfield to a value that maximize the remainder of image size / tile size (in other words, the size that left as few empty pixels as possible).
- A suitable tile size is found. More specifically, a size is found which is a dividor of the specified image
size, and is the closest one of the default tile size. The
-
createIntersection
Computes a newImageLayoutwhich is the intersection of the specifiedImageLayoutand allRenderedImages in the supplied list. If theminX,minY,widthandheightproperties are not defined in thelayout, then they will be inherited from the first source for consistency withOpImageconstructor.- Parameters:
layout- The original layout. This object will not be modified.sources- The list of sourcesRenderedImage.- Returns:
- A new
ImageLayout, or the originallayoutif no change was needed.
-
toInterpolation
Casts the specified object to anobject.- Parameters:
type- The interpolation type as anInterpolationor aCharSequenceobject.- Returns:
- The interpolation object for the specified type.
- Throws:
IllegalArgumentException- if the specified interpolation type is not a know one.
-
getInterpolationName
Returns the interpolation name for the specified interpolation object. This method tries to infer the name from the object's class name.- Parameters:
interp- The interpolation object, ornullfor "nearest" (which is an other way to say "no interpolation").
-
tileImage
Tiles the specified image.- Throws:
IOException- If an I/O operation were required (in order to check if the image were tiled on disk) and failed.- Since:
- 2.3
-
fill
Sets every samples in the given image to the given value. This method is typically used for clearing an image content.- Parameters:
image- The image to fill.value- The value to to given to every samples.
-
isMediaLibAvailable
public static boolean isMediaLibAvailable()Tells me whether or not the native libraries for ImageN are active or not.- Returns:
falsein case the ImageN native libs are not in the path,trueotherwise.
-
disposePlanarImageChain
public static void disposePlanarImageChain(PlanarImage pi) Dispose an image with all its ancestors.- Parameters:
pi- thePlanarImageto dispose.
-
maskColor
public static RenderedImage maskColor(Color transparentColor, RenderedImage image) throws IllegalStateException Relies on theImageWorkerto mask a certain color from an image.- Parameters:
transparentColor- theColorto make transparentimage- theRenderedImageto work on- Returns:
- a new
RenderedImagewhere the providedColorhas turned into transparent. - Throws:
IllegalStateException
-
cloneImageReadParam
-
layoutHelper
public static Rectangle2D layoutHelper(RenderedImage source, float scaleX, float scaleY, float transX, float transY, Interpolation interp) -
getReferencedEnvelopeFromGeographicBoundingBox
public static ReferencedEnvelope getReferencedEnvelopeFromGeographicBoundingBox(GeographicBoundingBox geographicBBox) Builds aReferencedEnvelopefrom aGeographicBoundingBox. This is useful in order to have an implementation ofBoundingBoxfrom aGeographicBoundingBoxwhich strangely does implementGeographicBoundingBox.- Parameters:
geographicBBox- theGeographicBoundingBoxto convert.- Returns:
- an instance of
ReferencedEnvelope.
-
getWGS84ReferencedEnvelope
Builds aReferencedEnvelopein WGS84 from aGeneralBounds.- Parameters:
coverageEnvelope- theGeneralBoundsto convert.- Returns:
- an instance of
ReferencedEnvelopein WGS84 ornullin case a problem during the conversion occurs.
-
getDimension
public static Rectangle getDimension(int imageIndex, ImageInputStream inStream, ImageReader reader) throws IOException Retrieves the dimensions of theRenderedImageat indeximageIndexfor the providedImageReaderandImageInputStream.Notice that none of the input parameters can be
nullor aNullPointerExceptionwill be thrown. Morevoer theimageIndexcannot be negative or anIllegalArgumentExceptionwill be thrown.- Parameters:
imageIndex- the index of the image to get the dimensions for.inStream- theImageInputStreamto use as an inputreader- theImageReaderto decode the image dimensions.- Returns:
- a
Rectanglethat contains the dimensions for the image at indeximageIndex - Throws:
IOException- in case theImageReaderor theImageInputStreamfail.
-
checkEmptySourceRegion
public static final boolean checkEmptySourceRegion(ImageReadParam readParameters, Rectangle dimensions) Checks that the provideddimensionswhen intersected with the source region used by the providedImageReadParaminstance does not result in an emptyRectangle.Input parameters cannot be null.
- Parameters:
readParameters- an instance ofImageReadParamfor which we want to check the source region element.dimensions- an instance ofRectangleto use for the check.- Returns:
trueif the intersection is not empty,falseotherwise.
-
getBackgroundValues
Build a background values array using the same dataType of the inputSampleModel(if available) and the values provided in the input array. -
disposeImage
Allow to dispose this image, as well as the related image sources, readers, stream, ROI.- Parameters:
inputImage- the image to be disposed.
-
disposeSinglePlanarImage
public static void disposeSinglePlanarImage(PlanarImage planarImage) Disposes the specified image, without recursing back in the sources -
getDatabufferTypeName
Transform a data type into a representativeString.- Returns:
- a representative
String.
-
applyRescaling
public static RenderedImage applyRescaling(Double[] scales, Double[] offsets, RenderedImage image, Hints hints) Applies values rescaling if either the scales or the offsets array is non null, or has any value that is not a default (1 for scales, 0 for offsets)- Parameters:
scales- The scales arrayoffsets- The offsets arrayimage- The image to be rescaledhints- The image processing hints, if any (can be null)- Returns:
- The original image, or a rescaled image
-
setSubsamplingFactors
public static void setSubsamplingFactors(ImageReadParam readParameters, double[] requestedRes, double[] selectedRes, int rasterWidth, int rasterHeight) Computes and applies suitable subsampling factors on the givenImageReadParam.The method determines integer subsampling factors based on the ratio between the requested resolution and the selected overview resolution, and applies several adjustments to ensure both quality and seamless rendering:
- Uses
floor(ratio + epsilon)to derive the base subsampling factor, avoiding oversampling and rounding errors. - Optionally increases the factor by +1 if this provides a closer match to the requested resolution and the relative error remains within a configurable tolerance (default 3%). This reduces the number of pixels read, improving performance with negligible quality loss.
- Clamps the factors so they are never less than 1 or greater than the raster width/height.
- If a source region is defined, aligns its x/y/width/height to multiples of the subsampling factors. This
prevents “whiteline” artifacts (seams) by ensuring no partial rows/columns are skipped during read.
Negative x/y are not expected at this stage (they would be rejected by
ImageReadParam), but clipping to ≥0 is performed defensively.
- Parameters:
readParameters- the read parameters on which to set the source region and subsamplingrequestedRes- the resolution requested by the client (x,y)selectedRes- the resolution of the selected overview (x,y)rasterWidth- full width of the rasterrasterHeight- full height of the raster
- Uses
-