public class ImageUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ImageUtil.AlignedImage |
Modifier and Type | Field and Description |
---|---|
static int |
BILINEAR_INTERPOLATION |
static int |
IMAGE_TILE_SIZE |
static int |
NEAREST_NEIGHBOR_INTERPOLATION |
static java.awt.Color |
TRANSPARENT |
Constructor and Description |
---|
ImageUtil() |
Modifier and Type | Method and Description |
---|---|
static ImageUtil.AlignedImage |
alignImage(java.awt.image.BufferedImage sourceImage,
float[] latitudes,
float[] longitudes)
Reprojects an image into an aligned image, one with edges of constant latitude and longitude.
|
static ImageUtil.AlignedImage |
alignImage(java.awt.image.BufferedImage sourceImage,
float[] latitudes,
float[] longitudes,
Sector sector,
java.awt.Dimension dimension)
Reprojects an image into an aligned image, one with edges of constant latitude and longitude.
|
static void |
alignImageDump(java.awt.image.BufferedImage sourceImage,
float[] latitudes,
float[] longitudes) |
static java.nio.ByteBuffer |
asJPEG(DataRaster raster) |
static java.nio.ByteBuffer |
asPNG(DataRaster raster) |
static java.awt.image.BufferedImage[] |
buildMipmaps(java.awt.image.BufferedImage image)
Builds a sequence of mipmaps for the specified image.
|
static java.awt.image.BufferedImage[] |
buildMipmaps(java.awt.image.BufferedImage image,
int mipmapImageType,
int maxLevel)
Builds a sequence of mipmaps for the specified image.
|
static Sector |
calcBoundingBoxForUTM(AVList params) |
protected static void |
close(javax.imageio.stream.ImageOutputStream ios) |
static void |
computeBestFittingControlPoints4(java.awt.geom.Point2D[] imagePoints,
LatLon[] geoPoints,
java.awt.geom.Point2D[] outImagePoints,
LatLon[] outGeoPoints)
Computes which three control points out of four provide the best estimate an image's geographic location.
|
static java.util.List<LatLon> |
computeImageCorners(int imageWidth,
int imageHeight,
Matrix imageToGeographic)
Returns the geographic corners of an image with the specified dimensions, and a transform that maps image
coordinates to geographic coordinates.
|
static long |
computeSizeInBytes(java.awt.image.BufferedImage image)
Returns the size in bytes of the specified image.
|
static java.awt.image.BufferedImage |
convertToPowerOfTwoImage(java.awt.image.BufferedImage image,
boolean scaleToFit)
Returns a copy of the specified image such that the new dimensions are powers of two.
|
static java.awt.image.BufferedImage |
createCompatibleImage(int width,
int height,
int transparency) |
protected static java.awt.GraphicsConfiguration |
getDefaultGraphicsConfiguration() |
static int |
getMaxMipmapLevel(int width,
int height)
Returns the maximum desired mip level for an image with dimensions
width and height . |
static int |
getMipmapType(int imageType)
Returns an image type appropriate for generating mipmaps.
|
static void |
getScaledCopy(java.awt.image.BufferedImage image,
java.awt.image.BufferedImage canvas)
Draws the specified
image onto the canvas , scaling or stretching the image to fit the
canvas. |
static int |
interpolateColor(double x,
double y,
int c0,
int c1,
int c2,
int c3)
Performs bilinear interpolation of 32-bit colors over a convex quadrilateral.
|
protected static boolean |
isCompatibleImage(java.awt.image.BufferedImage image) |
static java.awt.image.BufferedImage |
mapColors(java.awt.image.BufferedImage sourceImage,
int[] originalColors,
int[] newColors) |
static java.awt.image.BufferedImage |
mapColors(java.nio.ByteBuffer imageBuffer,
int originalColor,
int newColor) |
static java.awt.image.BufferedImage |
mapTransparencyColors(java.awt.image.BufferedImage sourceImage,
int[] originalColors) |
static java.awt.image.BufferedImage |
mapTransparencyColors(java.nio.ByteBuffer imageBuffer,
int[] originalColors) |
static void |
mergeImage(Sector canvasSector,
Sector imageSector,
double aspectRatio,
java.awt.image.BufferedImage image,
java.awt.image.BufferedImage canvas)
Merge an image into another image.
|
static AVList |
openSpatialImage(java.io.File imageFile)
Opens a spatial image.
|
static AVList |
openSpatialImage(java.io.File imageFile,
int interpolation_mode)
Opens a spatial image.
|
static Sector |
positionImage(java.awt.image.BufferedImage sourceImage,
java.awt.Point[] imagePoints,
LatLon[] geoPoints,
java.awt.image.BufferedImage destImage) |
static Sector |
positionImage3(java.awt.image.BufferedImage sourceImage,
java.awt.Point[] imagePoints,
LatLon[] geoPoints,
java.awt.image.BufferedImage destImage) |
static Sector |
positionImage4(java.awt.image.BufferedImage sourceImage,
java.awt.Point[] imagePoints,
LatLon[] geoPoints,
java.awt.image.BufferedImage destImage) |
static AVList |
readGeoKeys(gov.nasa.worldwind.formats.tiff.GeotiffReader reader,
int imageIndex,
AVList values)
Reads Geo-referenced metadata from Geo-TIFF file
|
static void |
reprojectUtmToGeographic(AVList values,
int mode)
Reprojects an imge in UTM projection to Geo/WGS84.
|
static java.awt.image.BufferedImage |
toCompatibleImage(java.awt.image.BufferedImage image) |
static java.awt.image.BufferedImage |
trimImage(java.awt.image.BufferedImage image)
Returns a copy of the specified image with any fully-transparent borders removed.
|
static java.awt.image.BufferedImage |
visualize(BufferWrapperRaster raster)
Converts a non-imagery data raster (elevations) to visually representable image raster.
|
static Sector |
warpImageWithControlPoints(java.awt.image.BufferedImage sourceImage,
java.awt.geom.Point2D[] imagePoints,
LatLon[] geoPoints,
java.awt.image.BufferedImage destImage)
Convenience method for transforming a georeferenced source image into a geographically aligned destination image.
|
static Sector |
warpImageWithControlPoints3(java.awt.image.BufferedImage sourceImage,
java.awt.geom.Point2D[] imagePoints,
LatLon[] geoPoints,
java.awt.image.BufferedImage destImage)
Transforms a georeferenced source image into a geographically aligned destination image.
|
static Sector |
warpImageWithControlPoints4(java.awt.image.BufferedImage sourceImage,
java.awt.geom.Point2D[] imagePoints,
LatLon[] geoPoints,
java.awt.image.BufferedImage destImage)
Transforms a georeferenced source image into a geographically aligned destination image.
|
static void |
warpImageWithTransform(java.awt.image.BufferedImage image,
java.awt.image.BufferedImage canvas,
Matrix canvasToImageTransform)
Rasterizes the image into the canvas, given a transform that maps canvas coordinates to image coordinates.
|
static Sector |
warpImageWithWorldFile(java.awt.image.BufferedImage sourceImage,
AVList worldFileParams,
java.awt.image.BufferedImage destImage)
Transforms a georeferenced source image into a geographically aligned destination image.
|
public static int BILINEAR_INTERPOLATION
public static int IMAGE_TILE_SIZE
public static int NEAREST_NEIGHBOR_INTERPOLATION
public static java.awt.Color TRANSPARENT
public static ImageUtil.AlignedImage alignImage(java.awt.image.BufferedImage sourceImage, float[] latitudes, float[] longitudes) throws java.lang.InterruptedException
sourceImage
- the image to reproject, typically a non-aligned imagelatitudes
- an array identifying the latitude of each pixels if the source image. There must be an entry
in the array for all pixels. The values are taken to be in row-major order relative to the
image -- the horizontal component varies fastest.longitudes
- an array identifying the longitude of each pixels if the source image. There must be an entry
in the array for all pixels. The values are taken to be in row-major order relative to the
image -- the horizontal component varies fastest.java.lang.InterruptedException
- if any thread has interrupted the current thread while alignImage is running. The
interrupted status of the current thread is cleared when this exception is
thrown.public static ImageUtil.AlignedImage alignImage(java.awt.image.BufferedImage sourceImage, float[] latitudes, float[] longitudes, Sector sector, java.awt.Dimension dimension) throws java.lang.InterruptedException
sourceImage
- the image to reproject, typically a non-aligned imagelatitudes
- an array identifying the latitude of each pixels if the source image. There must be an entry
in the array for all pixels. The values are taken to be in row-major order relative to the
image -- the horizontal component varies fastest.longitudes
- an array identifying the longitude of each pixels if the source image. There must be an entry
in the array for all pixels. The values are taken to be in row-major order relative to the
image -- the horizontal component varies fastest.sector
- the sector to align the image to. If null, this computes the aligned image's sector.dimension
- the the aligned image's dimensions. If null, this computes the aligned image's dimension.java.lang.InterruptedException
- if any thread has interrupted the current thread while alignImage is running. The
interrupted status of the current thread is cleared when this exception is
thrown.public static void alignImageDump(java.awt.image.BufferedImage sourceImage, float[] latitudes, float[] longitudes)
public static java.nio.ByteBuffer asJPEG(DataRaster raster)
public static java.nio.ByteBuffer asPNG(DataRaster raster)
public static java.awt.image.BufferedImage[] buildMipmaps(java.awt.image.BufferedImage image)
buildMipmaps(BufferedImage, int, int)
, with mipmapImageType
equal to
getMipmapType(image.getType())
, and maxLevel
equal to
getMaxMipmapLevel(image.getWidth(), image.getHeight())
.image
- the BufferedImage to build mipmaps for.java.lang.IllegalArgumentException
- if image
is null.public static java.awt.image.BufferedImage[] buildMipmaps(java.awt.image.BufferedImage image, int mipmapImageType, int maxLevel)
maxLevel + 1
, including level 0. The level 0 image will be a reference to the original image, not a
copy. Each mipmap level will be created with the specified BufferedImage type mipmapImageType
. Each
level will have dimensions equal to 1/2 the previous level's dimensions, rounding down, to a minimum width or
height of 1.image
- the BufferedImage to build mipmaps for.mipmapImageType
- the BufferedImage type to use when creating each mipmap image.maxLevel
- the maximum mip level to create. Specifying zero will return an array containing the
original image.java.lang.IllegalArgumentException
- if image
is null, or if maxLevel
is less than zero.getMaxMipmapLevel(int, int)
public static Sector calcBoundingBoxForUTM(AVList params) throws java.io.IOException
java.io.IOException
protected static void close(javax.imageio.stream.ImageOutputStream ios)
public static void computeBestFittingControlPoints4(java.awt.geom.Point2D[] imagePoints, LatLon[] geoPoints, java.awt.geom.Point2D[] outImagePoints, LatLon[] outGeoPoints)
outImagePoints
and outGeoPoints
, both of
which must be non-null and at least length 3.imagePoints
- four control points in the image.geoPoints
- four geographic locations corresponding to the four imagePoints
.outImagePoints
- three control points that best estimate the image's location.outGeoPoints
- three geographic locations corresponding to the three outImagePoints
.java.lang.IllegalArgumentException
- if any of imagePoints
, geoPoints
,
outImagePoints
or outGeoPoints
is null, or if
imagePoints
or geoPoints
have length less than 4, or
if outImagePoints
or outGeoPoints
have length less
than 3.public static java.util.List<LatLon> computeImageCorners(int imageWidth, int imageHeight, Matrix imageToGeographic)
imageWidth
- width of the image grid.imageHeight
- height of the image grid.imageToGeographic
- Matrix that maps image coordinates to geographic coordinates.java.lang.IllegalArgumentException
- if either imageWidth
or imageHeight
are less than 1,
or if imageToGeographic
is null.public static long computeSizeInBytes(java.awt.image.BufferedImage image)
image
- the BufferedImage to compute the size of.java.lang.IllegalArgumentException
- if image
is null.public static java.awt.image.BufferedImage convertToPowerOfTwoImage(java.awt.image.BufferedImage image, boolean scaleToFit)
scaleToFit
determines whether the
original image should be drawn into the new image with no special scaling, or whether the original image should
be scaled to fit exactly in the new image. If the original image dimensions are already powers of two, this
method will simply return the original image.image
- the BufferedImage to convert to a power of two image.scaleToFit
- true if image
should be scaled to fit the new image dimensions; false otherwise.simage
with power of two dimensions.java.lang.IllegalArgumentException
- if image
is null.public static java.awt.image.BufferedImage createCompatibleImage(int width, int height, int transparency)
protected static java.awt.GraphicsConfiguration getDefaultGraphicsConfiguration()
public static int getMaxMipmapLevel(int width, int height)
width
and height
.
The maximum desired level is the number of levels required to reduce the original image dimensions to a 1x1
image.width
- the level 0 image width.height
- the level 0 image height.width
and height
.java.lang.IllegalArgumentException
- if either width
or height
are less than 1.public static int getMipmapType(int imageType)
imageType
- the original BufferedImage type.public static void getScaledCopy(java.awt.image.BufferedImage image, java.awt.image.BufferedImage canvas)
image
onto the canvas
, scaling or stretching the image to fit the
canvas. This will apply a bilinear filter to the image if any scaling or stretching is necessary.image
- the BufferedImage to draw, potentially scaling or stretching to fit the canvas
.canvas
- the BufferedImage to receive the scaled or stretched image
.java.lang.IllegalArgumentException
- if either image
or canvas
is null.public static int interpolateColor(double x, double y, int c0, int c1, int c2, int c3)
x
- horizontal coordinate of the interpolation point relative to the lower left corner of the
quadrilateral. The value should generally be in the range [0, 1].y
- vertical coordinate of the interpolation point relative to the lower left corner of the quadrilateral.
The value should generally be in the range [0, 1].c0
- color at the lower left corner of the quadrilateral.c1
- color at the lower right corner of the quadrilateral.c2
- color at the pixel upper left corner of the quadrilateral.c3
- color at the pixel upper right corner of the quadrilateral.protected static boolean isCompatibleImage(java.awt.image.BufferedImage image)
public static java.awt.image.BufferedImage mapColors(java.awt.image.BufferedImage sourceImage, int[] originalColors, int[] newColors)
public static java.awt.image.BufferedImage mapColors(java.nio.ByteBuffer imageBuffer, int originalColor, int newColor)
public static java.awt.image.BufferedImage mapTransparencyColors(java.awt.image.BufferedImage sourceImage, int[] originalColors)
public static java.awt.image.BufferedImage mapTransparencyColors(java.nio.ByteBuffer imageBuffer, int[] originalColors)
public static void mergeImage(Sector canvasSector, Sector imageSector, double aspectRatio, java.awt.image.BufferedImage image, java.awt.image.BufferedImage canvas)
canvasSector
- the sector defining the canvas' location and range.imageSector
- the sector defining the image's locaion and range.aspectRatio
- the aspect ratio, width/height, of the assembled image. If the aspect ratio is greater than
or equal to one, the assembled image uses the full width of the canvas; the height used is
proportional to the inverse of the aspect ratio. If the aspect ratio is less than one, the
full height of the canvas is used; the width used is proportional to the aspect ratio.
The aspect ratio is typically used to maintain consistent width and height units while
assembling multiple images into a canvas of a different aspect ratio than the canvas sector,
such as drawing a non-square region into a 1024x1024 canvas. An aspect ratio of 1 causes the
incoming images to be stretched as necessary in one dimension to match the aspect ratio of
the canvas sector.image
- the image to merge into the canvas.canvas
- the canvas into which the images are merged. The canvas is not changed if the specified image
and canvas sectors are disjoint.java.lang.IllegalArgumentException
- if the any of the reference arguments are null or the aspect ratio is less than
or equal to zero.public static AVList openSpatialImage(java.io.File imageFile) throws java.io.IOException
imageFile
- source imagejava.io.IOException
- if there is a problem opening the file.public static AVList openSpatialImage(java.io.File imageFile, int interpolation_mode) throws java.io.IOException
imageFile
- source imageinterpolation_mode
- the interpolation mode if the image is reprojected.java.io.IOException
- if there is a problem opening the file.WWRuntimeException
- if the image type is unsupported.public static Sector positionImage(java.awt.image.BufferedImage sourceImage, java.awt.Point[] imagePoints, LatLon[] geoPoints, java.awt.image.BufferedImage destImage)
public static Sector positionImage3(java.awt.image.BufferedImage sourceImage, java.awt.Point[] imagePoints, LatLon[] geoPoints, java.awt.image.BufferedImage destImage)
public static Sector positionImage4(java.awt.image.BufferedImage sourceImage, java.awt.Point[] imagePoints, LatLon[] geoPoints, java.awt.image.BufferedImage destImage)
public static AVList readGeoKeys(gov.nasa.worldwind.formats.tiff.GeotiffReader reader, int imageIndex, AVList values) throws java.io.IOException
reader
- GeotiffReaderimageIndex
- image index (could be a band; GeoTiff file could contain overview images, bands, etc)values
- AVListjava.io.IOException
- if there is a problem opening the file.public static void reprojectUtmToGeographic(AVList values, int mode)
values
- AVList: contains the bufferedimage and the values from the world file. Stores resulting image in
valuesmode
- the interpolation mode if the image is reprojected.public static java.awt.image.BufferedImage toCompatibleImage(java.awt.image.BufferedImage image)
public static java.awt.image.BufferedImage trimImage(java.awt.image.BufferedImage image)
image
- the BufferedImage to trim.image
with its transparent borders trimmedjava.lang.IllegalArgumentException
- if image
is null.public static java.awt.image.BufferedImage visualize(BufferWrapperRaster raster)
raster
- non-imagery data raster (elevations) instance of data raster derived from BufferWrapperRasterpublic static Sector warpImageWithControlPoints(java.awt.image.BufferedImage sourceImage, java.awt.geom.Point2D[] imagePoints, LatLon[] geoPoints, java.awt.image.BufferedImage destImage)
sourceImage
- the source image to transform.imagePoints
- three or four control points in the source image.geoPoints
- three or four geographic locations corresponding to each source control point.destImage
- the destination image to receive the transformed source imnage.java.lang.IllegalArgumentException
- if any of sourceImage
, destImage
,
imagePoints
or geoPoints
is null, or if either
imagePoints
or geoPoints
have length less than 3.public static Sector warpImageWithControlPoints3(java.awt.image.BufferedImage sourceImage, java.awt.geom.Point2D[] imagePoints, LatLon[] geoPoints, java.awt.image.BufferedImage destImage)
sourceImage
- the source image to transform.imagePoints
- three control points in the source image.geoPoints
- three geographic locations corresponding to each source control point.destImage
- the destination image to receive the transformed source imnage.java.lang.IllegalArgumentException
- if any of sourceImage
, destImage
,
imagePoints
or geoPoints
is null, or if either
imagePoints
or geoPoints
have length less than 3.public static Sector warpImageWithControlPoints4(java.awt.image.BufferedImage sourceImage, java.awt.geom.Point2D[] imagePoints, LatLon[] geoPoints, java.awt.image.BufferedImage destImage)
sourceImage
- the source image to transform.imagePoints
- four control points in the source image.geoPoints
- four geographic locations corresponding to each source control point.destImage
- the destination image to receive the transformed source imnage.java.lang.IllegalArgumentException
- if any of sourceImage
, destImage
,
imagePoints
or geoPoints
is null, or if either
imagePoints
or geoPoints
have length less than 4.public static void warpImageWithTransform(java.awt.image.BufferedImage image, java.awt.image.BufferedImage canvas, Matrix canvasToImageTransform)
image
- the source image.canvas
- the image to receive the transformed source image.canvasToImageTransform
- Matrix
that maps a canvas coordinates to image coordinates.java.lang.IllegalArgumentException
- if any of image
, canvas
, or canvasToImageTransform
are null.public static Sector warpImageWithWorldFile(java.awt.image.BufferedImage sourceImage, AVList worldFileParams, java.awt.image.BufferedImage destImage)
sourceImage
- the source image to transform.worldFileParams
- world file parameters which define an affine transform.destImage
- the destination image to receive the transformed source imnage.java.lang.IllegalArgumentException
- if any of sourceImage
, destImage
or
worldFileParams
is null.