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 | Class and Description |
---|---|
static class |
NDImageUtils.Flag
Flag indicates the color channel options for 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 |
resize(NDArray image,
int size)
Resizes an image to the given size.
|
static NDArray |
resize(NDArray image,
int width,
int height)
Resizes an image to the given width and height.
|
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 new size to use for both height and widthpublic static NDArray resize(NDArray image, int width, int height)
image
- the image to resizewidth
- the desired widthheight
- the desired heightpublic 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 image