public final class NDImageUtils
extends java.lang.Object
NDImageUtils is an image processing utility to load, reshape, and convert images using
NDArray images.| Modifier and Type | Method and Description |
|---|---|
static NDArray |
centerCrop(NDArray image)
Crops an image to a square of size
min(width, height). |
static NDArray |
centerCrop(NDArray image,
int width,
int height)
Crops an image to a given width and height from the center of the image.
|
static NDArray |
crop(NDArray image,
int x,
int y,
int width,
int height)
Crops an image with a given location and size.
|
static NDArray |
normalize(NDArray input,
float[] mean,
float[] std)
Normalizes an image NDArray of shape CHW or NCHW with mean and standard deviation.
|
static NDArray |
normalize(NDArray input,
float mean,
float std)
Normalizes an image NDArray of shape CHW or NCHW with a single mean and standard deviation to
apply to all channels.
|
static NDArray |
randomBrightness(NDArray image,
float brightness)
Randomly jitters image brightness with a factor chosen from [max(0, 1 - brightness), 1 +
brightness].
|
static NDArray |
randomColorJitter(NDArray image,
float brightness,
float contrast,
float saturation,
float hue)
Randomly jitters the brightness, contrast, saturation, and hue of an image.
|
static NDArray |
randomFlipLeftRight(NDArray image)
Randomly flip the input image left to right with a probability of 0.5.
|
static NDArray |
randomFlipTopBottom(NDArray image)
Randomly flip the input image top to bottom with a probability of 0.5.
|
static NDArray |
randomHue(NDArray image,
float hue)
Randomly jitters image hue with a factor chosen from [max(0, 1 - hue), 1 + hue].
|
static NDArray |
randomResizedCrop(NDArray image,
int width,
int height,
double minAreaScale,
double maxAreaScale,
double minAspectRatio,
double maxAspectRatio)
Crop the input image with random scale and aspect ratio.
|
static NDArray |
resize(NDArray image,
int size)
Resizes an image to the given width and height.
|
static NDArray |
resize(NDArray image,
int width,
int height)
Resizes an image to the given width and height.
|
static NDArray |
resize(NDArray image,
int width,
int height,
Image.Interpolation interpolation)
Resizes an image to the given width and height with given interpolation.
|
static NDArray |
toTensor(NDArray image)
Converts an image NDArray from preprocessing format to Neural Network format.
|
public static NDArray resize(NDArray image, int size)
image - the image to resizesize - the desired sizepublic static NDArray resize(NDArray image, int width, int height)
image - the image to resizewidth - the desired widthheight - the desired heightpublic static NDArray resize(NDArray image, int width, int height, Image.Interpolation interpolation)
image - the image to resizewidth - the desired widthheight - the desired heightinterpolation - the desired interpolationpublic static NDArray normalize(NDArray input, float mean, float std)
input - the image to normalizemean - the mean to normalize with (for all channels)std - the standard deviation to normalize with (for all channels)normalize(NDArray, float[], float[])public static NDArray normalize(NDArray input, float[] mean, float[] std)
Given mean (m1, ..., mn) and standard deviation (s1, ..., sn for n
channels, this transform normalizes each channel of the input tensor with: output[i] =
(input[i] - m1) / (s1).
input - the image to normalizemean - the mean to normalize with for each channelstd - the standard deviation to normalize with for each channelpublic static NDArray toTensor(NDArray image)
Converts an image NDArray of shape HWC in the range [0, 255] to a DataType.FLOAT32 tensor NDArray of shape CHW in the range [0,
1].
image - the image to convertpublic static NDArray centerCrop(NDArray image)
min(width, height).image - the image to cropcenterCrop(NDArray, int, int)public static NDArray centerCrop(NDArray image, int width, int height)
image - the image to cropwidth - the desired width of the cropped imageheight - the desired height of the cropped imagepublic static NDArray crop(NDArray image, int x, int y, int width, int height)
image - the image to cropx - the x coordinate of the top-left corner of the cropy - the y coordinate of the top-left corner of the cropwidth - the width of the cropped imageheight - the height of the cropped imagepublic static NDArray randomFlipLeftRight(NDArray image)
image - the image with HWC formatpublic static NDArray randomFlipTopBottom(NDArray image)
image - the image with HWC formatpublic static NDArray randomResizedCrop(NDArray image, int width, int height, double minAreaScale, double maxAreaScale, double minAspectRatio, double maxAspectRatio)
image - the image with HWC formatwidth - the output width of the imageheight - the output height of the imageminAreaScale - minimum targetArea/srcArea valuemaxAreaScale - maximum targetArea/srcArea valueminAspectRatio - minimum aspect ratiomaxAspectRatio - maximum aspect ratiopublic static NDArray randomBrightness(NDArray image, float brightness)
image - the image with HWC formatbrightness - the brightness factor from 0 to 1public static NDArray randomHue(NDArray image, float hue)
image - the image with HWC formathue - the hue factor from 0 to 1public static NDArray randomColorJitter(NDArray image, float brightness, float contrast, float saturation, float hue)
image - the image with HWC formatbrightness - the brightness factor from 0 to 1contrast - the contrast factor from 0 to 1saturation - the saturation factor from 0 to 1hue - the hue factor from 0 to 1