Package org.datavec.image.loader
Class ImageLoader
- java.lang.Object
-
- org.datavec.image.loader.BaseImageLoader
-
- org.datavec.image.loader.ImageLoader
-
- All Implemented Interfaces:
Serializable
public class ImageLoader extends BaseImageLoader
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.datavec.image.loader.BaseImageLoader
BaseImageLoader.MultiPageMode
-
-
Field Summary
-
Fields inherited from class org.datavec.image.loader.BaseImageLoader
ALLOWED_FORMATS, centerCropIfNeeded, channels, height, imageTransform, multiPageMode, rng, width
-
-
Constructor Summary
Constructors Constructor Description ImageLoader()ImageLoader(long height, long width)Instantiate an image with the given height and widthImageLoader(long height, long width, long channels)Instantiate an image with the given height and widthImageLoader(long height, long width, long channels, boolean centerCropIfNeeded)Instantiate an image with the given height and width
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ImageasImageMatrix(File f)As perBaseImageLoader.asMatrix(File)but as anImageImageasImageMatrix(File f, boolean nchw)As perBaseImageLoader.asMatrix(File, boolean)but as anImageImageasImageMatrix(InputStream inputStream)As perBaseImageLoader.asMatrix(InputStream)but as anImageImageasImageMatrix(InputStream inputStream, boolean nchw)As perBaseImageLoader.asMatrix(InputStream, boolean)but as anImageINDArrayasImageMiniBatches(File f, int numMiniBatches, int numRowsPerSlice)Slices up an image in to a mini batch.INDArrayasMatrix(BufferedImage image)Convert an BufferedImage to a matrixINDArrayasMatrix(File f)Convert an image file in to a matrixINDArrayasMatrix(File f, boolean nchw)Load an image from a file to an INDArrayINDArrayasMatrix(InputStream inputStream)Convert an input stream to a matrixINDArrayasMatrix(InputStream inputStream, boolean nchw)Load an image file from an input stream to an INDArrayINDArrayasRowVector(BufferedImage image)Convert an image in to a row vectorINDArrayasRowVector(File f)Convert a file to a row vectorINDArrayasRowVector(InputStream inputStream)BufferedImagecenterCropIfNeeded(BufferedImage img)int[]flattenedImageFromFile(File f)int[][]fromFile(File file)Load a rastered image from fileint[][][]fromFileMultipleChannels(File file)Load a rastered image from fileprotected BufferedImagescalingIfNeed(BufferedImage image, boolean needAlpha)protected BufferedImagescalingIfNeed(BufferedImage image, long dstHeight, long dstWidth, long dstImageType, boolean needAlpha)INDArraytoBgr(BufferedImage image)Convert an BufferedImage to an bgr spectrum imageINDArraytoBgr(File file)Convert an input stream to an bgr spectrum imageINDArraytoBgr(InputStream inputStream)Convert an input stream to an bgr spectrum imagestatic BufferedImagetoBufferedImage(Image img, int type)Converts a given Image into a BufferedImagevoidtoBufferedImageRGB(INDArray arr, BufferedImage image)Convert the given image to an rgb imagestatic BufferedImagetoImage(INDArray matrix)Convert a matrix in to a buffereed imageprotected INDArraytoINDArrayBGR(BufferedImage image)protected int[][]toIntArrayArray(BufferedImage image)INDArraytoRaveledTensor(BufferedImage image)Convert an image in to a raveled tensor of the bgr values of the imageINDArraytoRaveledTensor(File file)Changes the input stream in to an bgr based raveled(flattened) vectorINDArraytoRaveledTensor(InputStream is)Changes the input stream in to an bgr based raveled(flattened) vector-
Methods inherited from class org.datavec.image.loader.BaseImageLoader
downloadAndUntar, getAllowedFormats
-
-
-
-
Constructor Detail
-
ImageLoader
public ImageLoader()
-
ImageLoader
public ImageLoader(long height, long width)Instantiate an image with the given height and width- Parameters:
height- the height to load*width- the width to load
-
ImageLoader
public ImageLoader(long height, long width, long channels)Instantiate an image with the given height and width- Parameters:
height- the height to loadwidth- the width to loadchannels- the number of channels for the image*
-
ImageLoader
public ImageLoader(long height, long width, long channels, boolean centerCropIfNeeded)Instantiate an image with the given height and width- Parameters:
height- the height to loadwidth- the width to loadchannels- the number of channels for the image*centerCropIfNeeded- to crop before rescaling and converting
-
-
Method Detail
-
asRowVector
public INDArray asRowVector(File f) throws IOException
Convert a file to a row vector- Specified by:
asRowVectorin classBaseImageLoader- Parameters:
f- the image to convert- Returns:
- the flattened image
- Throws:
IOException
-
asRowVector
public INDArray asRowVector(InputStream inputStream) throws IOException
- Specified by:
asRowVectorin classBaseImageLoader- Throws:
IOException
-
asRowVector
public INDArray asRowVector(BufferedImage image)
Convert an image in to a row vector- Parameters:
image- the image to convert- Returns:
- the row vector based on a rastered representation of the image
-
toRaveledTensor
public INDArray toRaveledTensor(File file)
Changes the input stream in to an bgr based raveled(flattened) vector- Parameters:
file- the input stream to convert- Returns:
- the raveled bgr values for this input stream
-
toRaveledTensor
public INDArray toRaveledTensor(InputStream is)
Changes the input stream in to an bgr based raveled(flattened) vector- Parameters:
is- the input stream to convert- Returns:
- the raveled bgr values for this input stream
-
toRaveledTensor
public INDArray toRaveledTensor(BufferedImage image)
Convert an image in to a raveled tensor of the bgr values of the image- Parameters:
image- the image to parse- Returns:
- the raveled tensor of bgr values
-
toBgr
public INDArray toBgr(File file)
Convert an input stream to an bgr spectrum image- Parameters:
file- the file to convert- Returns:
- the input stream to convert
-
toBgr
public INDArray toBgr(InputStream inputStream)
Convert an input stream to an bgr spectrum image- Parameters:
inputStream- the input stream to convert- Returns:
- the input stream to convert
-
toBgr
public INDArray toBgr(BufferedImage image)
Convert an BufferedImage to an bgr spectrum image- Parameters:
image- the BufferedImage to convert- Returns:
- the input stream to convert
-
asMatrix
public INDArray asMatrix(File f) throws IOException
Convert an image file in to a matrix- Specified by:
asMatrixin classBaseImageLoader- Parameters:
f- the file to convert- Returns:
- a 2d matrix of a rastered version of the image
- Throws:
IOException
-
asMatrix
public INDArray asMatrix(File f, boolean nchw) throws IOException
Description copied from class:BaseImageLoaderLoad an image from a file to an INDArray- Specified by:
asMatrixin classBaseImageLoader- Parameters:
f- File to load the image fromnchw- If true: return image in NCHW/channels_first [1, channels, height width] format; if false, return in NHWC/channels_last [1, height, width, channels] format- Returns:
- Image file as as INDArray
- Throws:
IOException
-
asMatrix
public INDArray asMatrix(InputStream inputStream) throws IOException
Convert an input stream to a matrix- Specified by:
asMatrixin classBaseImageLoader- Parameters:
inputStream- the input stream to convert- Returns:
- the input stream to convert
- Throws:
IOException
-
asMatrix
public INDArray asMatrix(InputStream inputStream, boolean nchw) throws IOException
Description copied from class:BaseImageLoaderLoad an image file from an input stream to an INDArray- Specified by:
asMatrixin classBaseImageLoader- Parameters:
inputStream- Input stream to load the image fromnchw- If true: return image in NCHW/channels_first [1, channels, height width] format; if false, return in NHWC/channels_last [1, height, width, channels] format- Returns:
- Image file stream as as INDArray
- Throws:
IOException
-
asImageMatrix
public Image asImageMatrix(File f) throws IOException
Description copied from class:BaseImageLoaderAs perBaseImageLoader.asMatrix(File)but as anImage- Specified by:
asImageMatrixin classBaseImageLoader- Throws:
IOException
-
asImageMatrix
public Image asImageMatrix(File f, boolean nchw) throws IOException
Description copied from class:BaseImageLoaderAs perBaseImageLoader.asMatrix(File, boolean)but as anImage- Specified by:
asImageMatrixin classBaseImageLoader- Throws:
IOException
-
asImageMatrix
public Image asImageMatrix(InputStream inputStream) throws IOException
Description copied from class:BaseImageLoaderAs perBaseImageLoader.asMatrix(InputStream)but as anImage- Specified by:
asImageMatrixin classBaseImageLoader- Throws:
IOException
-
asImageMatrix
public Image asImageMatrix(InputStream inputStream, boolean nchw) throws IOException
Description copied from class:BaseImageLoaderAs perBaseImageLoader.asMatrix(InputStream, boolean)but as anImage- Specified by:
asImageMatrixin classBaseImageLoader- Throws:
IOException
-
asMatrix
public INDArray asMatrix(BufferedImage image)
Convert an BufferedImage to a matrix- Parameters:
image- the BufferedImage to convert- Returns:
- the input stream to convert
-
asImageMiniBatches
public INDArray asImageMiniBatches(File f, int numMiniBatches, int numRowsPerSlice)
Slices up an image in to a mini batch.- Parameters:
f- the file to load fromnumMiniBatches- the number of images in a mini batchnumRowsPerSlice- the number of rows for each image- Returns:
- a tensor representing one image as a mini batch
-
flattenedImageFromFile
public int[] flattenedImageFromFile(File f) throws IOException
- Throws:
IOException
-
fromFile
public int[][] fromFile(File file) throws IOException
Load a rastered image from file- Parameters:
file- the file to load- Returns:
- the rastered image
- Throws:
IOException
-
fromFileMultipleChannels
public int[][][] fromFileMultipleChannels(File file) throws IOException
Load a rastered image from file- Parameters:
file- the file to load- Returns:
- the rastered image
- Throws:
IOException
-
toImage
public static BufferedImage toImage(INDArray matrix)
Convert a matrix in to a buffereed image- Parameters:
matrix- the- Returns:
BufferedImage
-
toBufferedImageRGB
public void toBufferedImageRGB(INDArray arr, BufferedImage image)
Convert the given image to an rgb image- Parameters:
arr- the array to useimage- the image to set
-
toBufferedImage
public static BufferedImage toBufferedImage(Image img, int type)
Converts a given Image into a BufferedImage- Parameters:
img- The Image to be convertedtype- The color model of BufferedImage- Returns:
- The converted BufferedImage
-
toIntArrayArray
protected int[][] toIntArrayArray(BufferedImage image)
-
toINDArrayBGR
protected INDArray toINDArrayBGR(BufferedImage image)
-
centerCropIfNeeded
public BufferedImage centerCropIfNeeded(BufferedImage img)
-
scalingIfNeed
protected BufferedImage scalingIfNeed(BufferedImage image, boolean needAlpha)
-
scalingIfNeed
protected BufferedImage scalingIfNeed(BufferedImage image, long dstHeight, long dstWidth, long dstImageType, boolean needAlpha)
-
-