Package org.datavec.image.loader
Class NativeImageLoader
- java.lang.Object
-
- org.datavec.image.loader.BaseImageLoader
-
- org.datavec.image.loader.NativeImageLoader
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AndroidNativeImageLoader,CifarLoader,Java2DNativeImageLoader
public class NativeImageLoader 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 Modifier and Type Field Description static String[]ALLOWED_FORMATSprotected org.bytedeco.javacv.OpenCVFrameConverter.ToMatconverter-
Fields inherited from class org.datavec.image.loader.BaseImageLoader
centerCropIfNeeded, channels, height, imageTransform, multiPageMode, rng, width
-
-
Constructor Summary
Constructors Modifier Constructor Description NativeImageLoader()Loads images with no scaling or conversion.NativeImageLoader(long height, long width)Instantiate an image with the given height and widthNativeImageLoader(long height, long width, long channels)Instantiate an image with the given height and widthNativeImageLoader(long height, long width, long channels, boolean centerCropIfNeeded)Instantiate an image with the given height and widthNativeImageLoader(long height, long width, long channels, BaseImageLoader.MultiPageMode mode)Instantiate an image with the given height and widthNativeImageLoader(long height, long width, long channels, ImageTransform imageTransform)Instantiate an image with the given height and widthprotectedNativeImageLoader(NativeImageLoader other)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.bytedeco.javacv.FrameasFrame(INDArray array)ReturnsasFrame(array, -1).org.bytedeco.javacv.FrameasFrame(INDArray array, int dataType)Converts an INDArray to a JavaCV Frame.ImageasImageMatrix(File f)As perBaseImageLoader.asMatrix(File)but as anImageImageasImageMatrix(File f, boolean nchw)As perBaseImageLoader.asMatrix(File, boolean)but as anImageImageasImageMatrix(InputStream is)As perBaseImageLoader.asMatrix(InputStream)but as anImageImageasImageMatrix(InputStream inputStream, boolean nchw)As perBaseImageLoader.asMatrix(InputStream, boolean)but as anImageImageasImageMatrix(String filename)org.bytedeco.opencv.opencv_core.MatasMat(INDArray array)ReturnsasMat(array, -1).org.bytedeco.opencv.opencv_core.MatasMat(INDArray array, int dataType)Converts an INDArray to an OpenCV Mat.INDArrayasMatrix(File f)As perBaseImageLoader.asMatrix(File, boolean)but NCHW/channels_first formatINDArrayasMatrix(File f, boolean nchw)Load an image from a file to an INDArrayINDArrayasMatrix(InputStream is)INDArrayasMatrix(InputStream inputStream, boolean nchw)Load an image file from an input stream to an INDArrayINDArrayasMatrix(Object image)INDArrayasMatrix(String filename)INDArrayasMatrix(org.bytedeco.javacv.Frame image)INDArrayasMatrix(org.bytedeco.opencv.opencv_core.Mat image)INDArrayasMatrix(ImageWritable writable)Convert ImageWritable to INDArrayINDArrayasMatrix(org.opencv.core.Mat image)voidasMatrixView(File f, INDArray view)voidasMatrixView(InputStream is, INDArray view)voidasMatrixView(String filename, INDArray view)voidasMatrixView(org.bytedeco.opencv.opencv_core.Mat image, INDArray view)voidasMatrixView(org.opencv.core.Mat image, INDArray view)INDArrayasRowVector(File f)Convert a file to a row vectorINDArrayasRowVector(InputStream is)INDArrayasRowVector(Object image)ReturnsasMatrix(image).ravel().INDArrayasRowVector(String filename)INDArrayasRowVector(org.bytedeco.javacv.Frame image)INDArrayasRowVector(org.bytedeco.opencv.opencv_core.Mat image)INDArrayasRowVector(org.opencv.core.Mat image)ImageWritableasWritable(File f)Convert a file to a INDArrayImageWritableasWritable(String filename)protected org.bytedeco.opencv.opencv_core.MatcenterCropIfNeeded(org.bytedeco.opencv.opencv_core.Mat img)protected voidfillNDArray(org.bytedeco.opencv.opencv_core.Mat image, INDArray ret)String[]getAllowedFormats()protected org.bytedeco.opencv.opencv_core.MatscalingIfNeed(org.bytedeco.opencv.opencv_core.Mat image)protected org.bytedeco.opencv.opencv_core.MatscalingIfNeed(org.bytedeco.opencv.opencv_core.Mat image, long dstHeight, long dstWidth)protected INDArraytransformImage(org.bytedeco.opencv.opencv_core.Mat image, INDArray ret)protected INDArraytransformImage(org.opencv.core.Mat image, INDArray ret)-
Methods inherited from class org.datavec.image.loader.BaseImageLoader
downloadAndUntar
-
-
-
-
Field Detail
-
ALLOWED_FORMATS
public static final String[] ALLOWED_FORMATS
-
converter
protected org.bytedeco.javacv.OpenCVFrameConverter.ToMat converter
-
-
Constructor Detail
-
NativeImageLoader
public NativeImageLoader()
Loads images with no scaling or conversion.
-
NativeImageLoader
public NativeImageLoader(long height, long width)Instantiate an image with the given height and width- Parameters:
height- the height to loadwidth- the width to load
-
NativeImageLoader
public NativeImageLoader(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*
-
NativeImageLoader
public NativeImageLoader(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
-
NativeImageLoader
public NativeImageLoader(long height, long width, long channels, ImageTransform imageTransform)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*imageTransform- to use before rescaling and converting
-
NativeImageLoader
public NativeImageLoader(long height, long width, long channels, BaseImageLoader.MultiPageMode mode)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*mode- how to load multipage image
-
NativeImageLoader
protected NativeImageLoader(NativeImageLoader other)
-
-
Method Detail
-
getAllowedFormats
public String[] getAllowedFormats()
- Overrides:
getAllowedFormatsin classBaseImageLoader
-
asRowVector
public INDArray asRowVector(String filename) throws IOException
- Throws:
IOException
-
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 is) throws IOException
- Specified by:
asRowVectorin classBaseImageLoader- Throws:
IOException
-
asRowVector
public INDArray asRowVector(Object image) throws IOException
ReturnsasMatrix(image).ravel().- Throws:
IOException- See Also:
asMatrix(Object)
-
asRowVector
public INDArray asRowVector(org.bytedeco.javacv.Frame image) throws IOException
- Throws:
IOException
-
asRowVector
public INDArray asRowVector(org.bytedeco.opencv.opencv_core.Mat image) throws IOException
- Throws:
IOException
-
asRowVector
public INDArray asRowVector(org.opencv.core.Mat image) throws IOException
- Throws:
IOException
-
asMatrix
public INDArray asMatrix(String filename) throws IOException
- Throws:
IOException
-
asMatrix
public INDArray asMatrix(File f) throws IOException
Description copied from class:BaseImageLoaderAs perBaseImageLoader.asMatrix(File, boolean)but NCHW/channels_first format- Specified by:
asMatrixin classBaseImageLoader- 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 is) throws IOException
- Specified by:
asMatrixin classBaseImageLoader- 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(String filename) throws IOException
- 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 is) 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(Object image) throws IOException
CallsAndroidNativeImageLoader.asMatrix(android.graphics.Bitmap)orJava2DNativeImageLoader.asMatrix(java.awt.image.BufferedImage).- Parameters:
image- as aBitmaporBufferedImage- Returns:
- the matrix or null for unsupported object classes
- Throws:
IOException
-
fillNDArray
protected void fillNDArray(org.bytedeco.opencv.opencv_core.Mat image, INDArray ret)
-
asMatrixView
public void asMatrixView(InputStream is, INDArray view) throws IOException
- Throws:
IOException
-
asMatrixView
public void asMatrixView(String filename, INDArray view) throws IOException
- Throws:
IOException
-
asMatrixView
public void asMatrixView(File f, INDArray view) throws IOException
- Throws:
IOException
-
asMatrixView
public void asMatrixView(org.bytedeco.opencv.opencv_core.Mat image, INDArray view) throws IOException- Throws:
IOException
-
asMatrixView
public void asMatrixView(org.opencv.core.Mat image, INDArray view) throws IOException- Throws:
IOException
-
asMatrix
public INDArray asMatrix(org.bytedeco.javacv.Frame image) throws IOException
- Throws:
IOException
-
asMatrix
public INDArray asMatrix(org.opencv.core.Mat image) throws IOException
- Throws:
IOException
-
asMatrix
public INDArray asMatrix(org.bytedeco.opencv.opencv_core.Mat image) throws IOException
- Throws:
IOException
-
transformImage
protected INDArray transformImage(org.opencv.core.Mat image, INDArray ret) throws IOException
- Throws:
IOException
-
transformImage
protected INDArray transformImage(org.bytedeco.opencv.opencv_core.Mat image, INDArray ret) throws IOException
- Throws:
IOException
-
centerCropIfNeeded
protected org.bytedeco.opencv.opencv_core.Mat centerCropIfNeeded(org.bytedeco.opencv.opencv_core.Mat img)
-
scalingIfNeed
protected org.bytedeco.opencv.opencv_core.Mat scalingIfNeed(org.bytedeco.opencv.opencv_core.Mat image)
-
scalingIfNeed
protected org.bytedeco.opencv.opencv_core.Mat scalingIfNeed(org.bytedeco.opencv.opencv_core.Mat image, long dstHeight, long dstWidth)
-
asWritable
public ImageWritable asWritable(String filename) throws IOException
- Throws:
IOException
-
asWritable
public ImageWritable asWritable(File f) throws IOException
Convert a file to a INDArray- Parameters:
f- the image to convert- Returns:
- INDArray
- Throws:
IOException
-
asMatrix
public INDArray asMatrix(ImageWritable writable) throws IOException
Convert ImageWritable to INDArray- Parameters:
writable- ImageWritable to convert- Returns:
- INDArray
- Throws:
IOException
-
asFrame
public org.bytedeco.javacv.Frame asFrame(INDArray array)
ReturnsasFrame(array, -1).
-
asFrame
public org.bytedeco.javacv.Frame asFrame(INDArray array, int dataType)
Converts an INDArray to a JavaCV Frame. Only intended for images with rank 3.- Parameters:
array- to convertdataType- from JavaCV (DEPTH_FLOAT, DEPTH_UBYTE, etc), or -1 to use same type as the INDArray- Returns:
- data copied to a Frame
-
asMat
public org.bytedeco.opencv.opencv_core.Mat asMat(INDArray array)
ReturnsasMat(array, -1).
-
asMat
public org.bytedeco.opencv.opencv_core.Mat asMat(INDArray array, int dataType)
Converts an INDArray to an OpenCV Mat. Only intended for images with rank 3.- Parameters:
array- to convertdataType- from OpenCV (CV_32F, CV_8U, etc), or -1 to use same type as the INDArray- Returns:
- data copied to a Mat
-
-