public class ImageUtil extends 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 Color |
TRANSPARENT |
Constructor and Description |
---|
ImageUtil() |
Modifier and Type | Method and Description |
---|---|
static ImageUtil.AlignedImage |
alignImage(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(BufferedImage sourceImage,
float[] latitudes,
float[] longitudes,
Sector sector,
Dimension dimension)
Reprojects an image into an aligned image, one with edges of constant latitude and longitude.
|
static void |
alignImageDump(BufferedImage sourceImage,
float[] latitudes,
float[] longitudes) |
static ByteBuffer |
asJPEG(DataRaster raster) |
static ByteBuffer |
asPNG(DataRaster raster) |
static BufferedImage[] |
buildMipmaps(BufferedImage image)
Builds a sequence of mipmaps for the specified image.
|
static BufferedImage[] |
buildMipmaps(BufferedImage image,
int mipmapImageType,
int maxLevel)
Builds a sequence of mipmaps for the specified image.
|
static Sector |
calcBoundingBoxForUTM(AVList params) |
protected static void |
close(ImageOutputStream ios) |
static void |
computeBestFittingControlPoints4(Point2D[] imagePoints,
LatLon[] geoPoints,
Point2D[] outImagePoints,
LatLon[] outGeoPoints)
Computes which three control points out of four provide the best estimate an image's geographic location.
|
static 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(BufferedImage image)
Returns the size in bytes of the specified image.
|
static BufferedImage |
convertToPowerOfTwoImage(BufferedImage image,
boolean scaleToFit)
Returns a copy of the specified image such that the new dimensions are powers of two.
|
static BufferedImage |
createCompatibleImage(int width,
int height,
int transparency) |
protected static 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(BufferedImage 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(BufferedImage image) |
static BufferedImage |
mapColors(BufferedImage sourceImage,
int[] originalColors,
int[] newColors) |
static BufferedImage |
mapColors(ByteBuffer imageBuffer,
int originalColor,
int newColor) |
static BufferedImage |
mapTransparencyColors(BufferedImage sourceImage,
int[] originalColors) |
static BufferedImage |
mapTransparencyColors(ByteBuffer imageBuffer,
int[] originalColors) |
static void |
mergeImage(Sector canvasSector,
Sector imageSector,
double aspectRatio,
BufferedImage image,
BufferedImage canvas)
Merge an image into another image.
|
static AVList |
openSpatialImage(File imageFile)
Opens a spatial image.
|
static AVList |
openSpatialImage(File imageFile,
int interpolation_mode)
Opens a spatial image.
|
static Sector |
positionImage(BufferedImage sourceImage,
Point[] imagePoints,
LatLon[] geoPoints,
BufferedImage destImage) |
static Sector |
positionImage3(BufferedImage sourceImage,
Point[] imagePoints,
LatLon[] geoPoints,
BufferedImage destImage) |
static Sector |
positionImage4(BufferedImage sourceImage,
Point[] imagePoints,
LatLon[] geoPoints,
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 BufferedImage |
toCompatibleImage(BufferedImage image) |
static BufferedImage |
visualize(BufferWrapperRaster raster)
Converts a non-imagery data raster (elevations) to visually representable image raster.
|
static Sector |
warpImageWithControlPoints(BufferedImage sourceImage,
Point2D[] imagePoints,
LatLon[] geoPoints,
BufferedImage destImage)
Convenience method for transforming a georeferenced source image into a geographically aligned destination image.
|
static Sector |
warpImageWithControlPoints3(BufferedImage sourceImage,
Point2D[] imagePoints,
LatLon[] geoPoints,
BufferedImage destImage)
Transforms a georeferenced source image into a geographically aligned destination image.
|
static Sector |
warpImageWithControlPoints4(BufferedImage sourceImage,
Point2D[] imagePoints,
LatLon[] geoPoints,
BufferedImage destImage)
Transforms a georeferenced source image into a geographically aligned destination image.
|
static void |
warpImageWithTransform(BufferedImage image,
BufferedImage canvas,
Matrix canvasToImageTransform)
Rasterizes the image into the canvas, given a transform that maps canvas coordinates to image coordinates.
|
static Sector |
warpImageWithWorldFile(BufferedImage sourceImage,
AVList worldFileParams,
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 Color TRANSPARENT
public static ImageUtil.AlignedImage alignImage(BufferedImage sourceImage, float[] latitudes, float[] longitudes) throws 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.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(BufferedImage sourceImage, float[] latitudes, float[] longitudes, Sector sector, Dimension dimension) throws 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.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(BufferedImage sourceImage, float[] latitudes, float[] longitudes)
public static ByteBuffer asJPEG(DataRaster raster)
public static ByteBuffer asPNG(DataRaster raster)
public static BufferedImage[] buildMipmaps(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.IllegalArgumentException
- if image
is null.public static BufferedImage[] buildMipmaps(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.IllegalArgumentException
- if image
is null, or if maxLevel
is less than zero.getMaxMipmapLevel(int, int)
public static Sector calcBoundingBoxForUTM(AVList params) throws IOException
IOException
protected static void close(ImageOutputStream ios)
public static void computeBestFittingControlPoints4(Point2D[] imagePoints, LatLon[] geoPoints, 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
.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 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.IllegalArgumentException
- if either imageWidth
or imageHeight
are less than 1,
or if imageToGeographic
is null.public static long computeSizeInBytes(BufferedImage image)
image
- the BufferedImage to compute the size of.IllegalArgumentException
- if image
is null.public static BufferedImage convertToPowerOfTwoImage(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.IllegalArgumentException
- if image
is null.public static BufferedImage createCompatibleImage(int width, int height, int transparency)
protected static 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
.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(BufferedImage 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
.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(BufferedImage image)
public static BufferedImage mapColors(BufferedImage sourceImage, int[] originalColors, int[] newColors)
public static BufferedImage mapColors(ByteBuffer imageBuffer, int originalColor, int newColor)
public static BufferedImage mapTransparencyColors(BufferedImage sourceImage, int[] originalColors)
public static BufferedImage mapTransparencyColors(ByteBuffer imageBuffer, int[] originalColors)
public static void mergeImage(Sector canvasSector, Sector imageSector, double aspectRatio, BufferedImage 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.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(File imageFile) throws IOException
imageFile
- source imageIOException
- if there is a problem opening the file.public static AVList openSpatialImage(File imageFile, int interpolation_mode) throws IOException
imageFile
- source imageinterpolation_mode
- the interpolation mode if the image is reprojected.IOException
- if there is a problem opening the file.WWRuntimeException
- if the image type is unsupported.public static Sector positionImage(BufferedImage sourceImage, Point[] imagePoints, LatLon[] geoPoints, BufferedImage destImage)
public static Sector positionImage3(BufferedImage sourceImage, Point[] imagePoints, LatLon[] geoPoints, BufferedImage destImage)
public static Sector positionImage4(BufferedImage sourceImage, Point[] imagePoints, LatLon[] geoPoints, BufferedImage destImage)
public static AVList readGeoKeys(gov.nasa.worldwind.formats.tiff.GeotiffReader reader, int imageIndex, AVList values) throws IOException
reader
- GeotiffReaderimageIndex
- image index (could be a band; GeoTiff file could contain overview images, bands, etc)values
- AVListIOException
- 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 BufferedImage toCompatibleImage(BufferedImage image)
public static BufferedImage visualize(BufferWrapperRaster raster)
raster
- non-imagery data raster (elevations) instance of data raster derived from BufferWrapperRasterpublic static Sector warpImageWithControlPoints(BufferedImage sourceImage, Point2D[] imagePoints, LatLon[] geoPoints, 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.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(BufferedImage sourceImage, Point2D[] imagePoints, LatLon[] geoPoints, 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.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(BufferedImage sourceImage, Point2D[] imagePoints, LatLon[] geoPoints, 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.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(BufferedImage 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.IllegalArgumentException
- if any of image
, canvas
, or canvasToImageTransform
are null.public static Sector warpImageWithWorldFile(BufferedImage sourceImage, AVList worldFileParams, 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.IllegalArgumentException
- if any of sourceImage
, destImage
or
worldFileParams
is null.