@Test public void testAsMatrix() throws Exception { BufferedImage img1 = makeRandomBufferedImage(0, 0, 3); Mat img2 = makeRandomImage(0, 0, 4); int w1 = 33, h1 = 77, ch1 = 1; NativeImageLoader loader1 = new NativeImageLoader(h1, w1, ch1); INDArray array1 = loader1.asMatrix(img1); assertEquals(4, array1.rank()); assertEquals(1, array1.size(0)); assertEquals(1, array1.size(1)); assertEquals(h1, array1.size(2)); assertEquals(w1, array1.size(3)); assertNotEquals(0.0, array1.sum().getDouble(0), 0.0); INDArray array2 = loader1.asMatrix(img2); assertEquals(4, array2.rank()); assertEquals(1, array2.size(0)); assertEquals(1, array2.size(1)); assertEquals(h1, array2.size(2)); assertEquals(w1, array2.size(3)); assertNotEquals(0.0, array2.sum().getDouble(0), 0.0); int w2 = 111, h2 = 66, ch2 = 3; NativeImageLoader loader2 = new NativeImageLoader(h2, w2, ch2); loader2.direct = false; INDArray array3 = loader2.asMatrix(img1); assertEquals(4, array3.rank()); assertEquals(1, array3.size(0)); assertEquals(3, array3.size(1)); assertEquals(h2, array3.size(2)); assertEquals(w2, array3.size(3)); assertNotEquals(0.0, array3.sum().getDouble(0), 0.0); INDArray array4 = loader2.asMatrix(img2); assertEquals(4, array4.rank()); assertEquals(1, array4.size(0)); assertEquals(3, array4.size(1)); assertEquals(h2, array4.size(2)); assertEquals(w2, array4.size(3)); assertNotEquals(0.0, array4.sum().getDouble(0), 0.0); int w3 = 123, h3 = 77, ch3 = 3; NativeImageLoader loader3 = new NativeImageLoader(h3, w3, ch3); File f3 = new ClassPathResource("datavec-data-image/testimages/class0/2.jpg").getFile(); ImageWritable iw3 = loader3.asWritable(f3); INDArray array5 = loader3.asMatrix(iw3); assertEquals(4, array5.rank()); assertEquals(1, array5.size(0)); assertEquals(3, array5.size(1)); assertEquals(h3, array5.size(2)); assertEquals(w3, array5.size(3)); assertNotEquals(0.0, array5.sum().getDouble(0), 0.0); Mat mat = loader3.asMat(array5); assertEquals(w3, mat.cols()); assertEquals(h3, mat.rows()); assertEquals(ch3, mat.channels()); assertTrue(mat.type() == CV_32FC(ch3) || mat.type() == CV_64FC(ch3)); assertNotEquals(0.0, sumElems(mat).get(), 0.0); Frame frame = loader3.asFrame(array5, Frame.DEPTH_UBYTE); assertEquals(w3, frame.imageWidth); assertEquals(h3, frame.imageHeight); assertEquals(ch3, frame.imageChannels); assertEquals(Frame.DEPTH_UBYTE, frame.imageDepth); Java2DNativeImageLoader loader4 = new Java2DNativeImageLoader(); BufferedImage img12 = loader4.asBufferedImage(array1); assertEquals(array1, loader4.asMatrix(img12)); NativeImageLoader loader5 = new NativeImageLoader(0, 0, 0); loader5.direct = false; INDArray array7 = loader5.asMatrix(f3); assertEquals(4, array7.rank()); assertEquals(1, array7.size(0)); assertEquals(3, array7.size(1)); assertEquals(32, array7.size(2)); assertEquals(32, array7.size(3)); assertNotEquals(0.0, array7.sum().getDouble(0), 0.0); }
public INDArray asMatrix(String filename) throws IOException { return asMatrix(new File(filename)); }
NativeImageLoader extends BaseImageLoader { public INDArray asMatrix(String filename) throws IOException { return asMatrix(new File(filename)); } }
NativeImageLoader extends BaseImageLoader { public INDArray asMatrix(String filename) throws IOException { return asMatrix(new File(filename)); } NativeImageLoader();  NativeImageLoader(long height, long width);  NativeImageLoader(long height, long width, long channels);  NativeImageLoader(long height, long width, long channels, boolean centerCropIfNeeded);  NativeImageLoader(long height, long width, long channels, ImageTransform imageTransform);  NativeImageLoader(long height, long width, long channels, MultiPageMode mode); protected  NativeImageLoader(NativeImageLoader other); }
NativeImageLoader extends BaseImageLoader { public INDArray asMatrix(String filename) throws IOException { return asMatrix(new File(filename)); } NativeImageLoader();  NativeImageLoader(long height, long width);  NativeImageLoader(long height, long width, long channels);  NativeImageLoader(long height, long width, long channels, boolean centerCropIfNeeded);  NativeImageLoader(long height, long width, long channels, ImageTransform imageTransform);  NativeImageLoader(long height, long width, long channels, MultiPageMode mode); protected  NativeImageLoader(NativeImageLoader other); @Override String[] getAllowedFormats(); INDArray asRowVector(String filename); @Override INDArray asRowVector(File f); @Override INDArray asRowVector(InputStream is); INDArray asRowVector(Object image); INDArray asRowVector(Frame image); INDArray asRowVector(Mat image); INDArray asRowVector(org.opencv.core.Mat image); INDArray asMatrix(String filename); @Override INDArray asMatrix(File f); @Override INDArray asMatrix(File f, boolean nchw); @Override INDArray asMatrix(InputStream is); @Override INDArray asMatrix(InputStream inputStream, boolean nchw); Image asImageMatrix(String filename); @Override Image asImageMatrix(File f); @Override Image asImageMatrix(File f, boolean nchw); @Override Image asImageMatrix(InputStream is); @Override Image asImageMatrix(InputStream inputStream, boolean nchw); INDArray asMatrix(Object image); void asMatrixView(InputStream is, INDArray view); void asMatrixView(String filename, INDArray view); void asMatrixView(File f, INDArray view); void asMatrixView(Mat image, INDArray view); void asMatrixView(org.opencv.core.Mat image, INDArray view); INDArray asMatrix(Frame image); INDArray asMatrix(org.opencv.core.Mat image); INDArray asMatrix(Mat image); ImageWritable asWritable(String filename); ImageWritable asWritable(File f); INDArray asMatrix(ImageWritable writable); Frame asFrame(INDArray array); Frame asFrame(INDArray array, int dataType); Mat asMat(INDArray array); Mat asMat(INDArray array, int dataType); }
NativeImageLoader extends BaseImageLoader { public INDArray asMatrix(String filename) throws IOException { return asMatrix(new File(filename)); } NativeImageLoader();  NativeImageLoader(long height, long width);  NativeImageLoader(long height, long width, long channels);  NativeImageLoader(long height, long width, long channels, boolean centerCropIfNeeded);  NativeImageLoader(long height, long width, long channels, ImageTransform imageTransform);  NativeImageLoader(long height, long width, long channels, MultiPageMode mode); protected  NativeImageLoader(NativeImageLoader other); @Override String[] getAllowedFormats(); INDArray asRowVector(String filename); @Override INDArray asRowVector(File f); @Override INDArray asRowVector(InputStream is); INDArray asRowVector(Object image); INDArray asRowVector(Frame image); INDArray asRowVector(Mat image); INDArray asRowVector(org.opencv.core.Mat image); INDArray asMatrix(String filename); @Override INDArray asMatrix(File f); @Override INDArray asMatrix(File f, boolean nchw); @Override INDArray asMatrix(InputStream is); @Override INDArray asMatrix(InputStream inputStream, boolean nchw); Image asImageMatrix(String filename); @Override Image asImageMatrix(File f); @Override Image asImageMatrix(File f, boolean nchw); @Override Image asImageMatrix(InputStream is); @Override Image asImageMatrix(InputStream inputStream, boolean nchw); INDArray asMatrix(Object image); void asMatrixView(InputStream is, INDArray view); void asMatrixView(String filename, INDArray view); void asMatrixView(File f, INDArray view); void asMatrixView(Mat image, INDArray view); void asMatrixView(org.opencv.core.Mat image, INDArray view); INDArray asMatrix(Frame image); INDArray asMatrix(org.opencv.core.Mat image); INDArray asMatrix(Mat image); ImageWritable asWritable(String filename); ImageWritable asWritable(File f); INDArray asMatrix(ImageWritable writable); Frame asFrame(INDArray array); Frame asFrame(INDArray array, int dataType); Mat asMat(INDArray array); Mat asMat(INDArray array, int dataType); static final String[] ALLOWED_FORMATS; }