@Test public void testToINDArrayBGR() throws Exception { BufferedImage img = makeRandomBufferedImage(false); int w = img.getWidth(); int h = img.getHeight(); int ch = 3; ImageLoader loader = new ImageLoader(0, 0, ch); INDArray arr = loader.toINDArrayBGR(img); long[] shape = arr.shape(); assertEquals(3, shape.length); assertEquals(ch, shape[0]); assertEquals(h, shape[1]); assertEquals(w, shape[2]); for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { int srcColor = img.getRGB(j, i); int a = 0xff << 24; int r = arr.getInt(2, i, j) << 16; int g = arr.getInt(1, i, j) << 8; int b = arr.getInt(0, i, j) & 0xff; int dstColor = a | r | g | b; assertEquals(srcColor, dstColor); } } }
protected INDArray toINDArrayBGR(BufferedImage image) { int height = image.getHeight(); int width = image.getWidth(); int bands = image.getSampleModel().getNumBands(); byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); int[] shape = new int[]{height, width, bands}; INDArray ret2 = Nd4j.create(1, pixels.length); for (int i = 0; i < ret2.length(); i++) { ret2.putScalar(i, ((int) pixels[i]) & 0xFF); } return ret2.reshape(shape).permute(2, 0, 1); }
ImageLoader extends BaseImageLoader { protected INDArray toINDArrayBGR(BufferedImage image) { int height = image.getHeight(); int width = image.getWidth(); int bands = image.getSampleModel().getNumBands(); byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); int[] shape = new int[]{height, width, bands}; INDArray ret2 = Nd4j.create(1, pixels.length); for (int i = 0; i < ret2.length(); i++) { ret2.putScalar(i, ((int) pixels[i]) & 0xFF); } return ret2.reshape(shape).permute(2, 0, 1); } }
ImageLoader extends BaseImageLoader { protected INDArray toINDArrayBGR(BufferedImage image) { int height = image.getHeight(); int width = image.getWidth(); int bands = image.getSampleModel().getNumBands(); byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); int[] shape = new int[]{height, width, bands}; INDArray ret2 = Nd4j.create(1, pixels.length); for (int i = 0; i < ret2.length(); i++) { ret2.putScalar(i, ((int) pixels[i]) & 0xFF); } return ret2.reshape(shape).permute(2, 0, 1); } ImageLoader();  ImageLoader(long height, long width);  ImageLoader(long height, long width, long channels);  ImageLoader(long height, long width, long channels, boolean centerCropIfNeeded); }
ImageLoader extends BaseImageLoader { protected INDArray toINDArrayBGR(BufferedImage image) { int height = image.getHeight(); int width = image.getWidth(); int bands = image.getSampleModel().getNumBands(); byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); int[] shape = new int[]{height, width, bands}; INDArray ret2 = Nd4j.create(1, pixels.length); for (int i = 0; i < ret2.length(); i++) { ret2.putScalar(i, ((int) pixels[i]) & 0xFF); } return ret2.reshape(shape).permute(2, 0, 1); } ImageLoader();  ImageLoader(long height, long width);  ImageLoader(long height, long width, long channels);  ImageLoader(long height, long width, long channels, boolean centerCropIfNeeded); INDArray asRowVector(File f); INDArray asRowVector(InputStream inputStream); INDArray asRowVector(BufferedImage image); INDArray toRaveledTensor(File file); INDArray toRaveledTensor(InputStream is); INDArray toRaveledTensor(BufferedImage image); INDArray toBgr(File file); INDArray toBgr(InputStream inputStream); INDArray toBgr(BufferedImage image); INDArray asMatrix(File f); @Override INDArray asMatrix(File f, boolean nchw); INDArray asMatrix(InputStream inputStream); @Override INDArray asMatrix(InputStream inputStream, boolean nchw); @Override org.datavec.image.data.Image asImageMatrix(File f); @Override org.datavec.image.data.Image asImageMatrix(File f, boolean nchw); @Override org.datavec.image.data.Image asImageMatrix(InputStream inputStream); @Override org.datavec.image.data.Image asImageMatrix(InputStream inputStream, boolean nchw); INDArray asMatrix(BufferedImage image); INDArray asImageMiniBatches(File f, int numMiniBatches, int numRowsPerSlice); int[] flattenedImageFromFile(File f); int[][] fromFile(File file); int[][][] fromFileMultipleChannels(File file); static BufferedImage toImage(INDArray matrix); void toBufferedImageRGB(INDArray arr, BufferedImage image); static BufferedImage toBufferedImage(Image img, int type); BufferedImage centerCropIfNeeded(BufferedImage img); }
ImageLoader extends BaseImageLoader { protected INDArray toINDArrayBGR(BufferedImage image) { int height = image.getHeight(); int width = image.getWidth(); int bands = image.getSampleModel().getNumBands(); byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); int[] shape = new int[]{height, width, bands}; INDArray ret2 = Nd4j.create(1, pixels.length); for (int i = 0; i < ret2.length(); i++) { ret2.putScalar(i, ((int) pixels[i]) & 0xFF); } return ret2.reshape(shape).permute(2, 0, 1); } ImageLoader();  ImageLoader(long height, long width);  ImageLoader(long height, long width, long channels);  ImageLoader(long height, long width, long channels, boolean centerCropIfNeeded); INDArray asRowVector(File f); INDArray asRowVector(InputStream inputStream); INDArray asRowVector(BufferedImage image); INDArray toRaveledTensor(File file); INDArray toRaveledTensor(InputStream is); INDArray toRaveledTensor(BufferedImage image); INDArray toBgr(File file); INDArray toBgr(InputStream inputStream); INDArray toBgr(BufferedImage image); INDArray asMatrix(File f); @Override INDArray asMatrix(File f, boolean nchw); INDArray asMatrix(InputStream inputStream); @Override INDArray asMatrix(InputStream inputStream, boolean nchw); @Override org.datavec.image.data.Image asImageMatrix(File f); @Override org.datavec.image.data.Image asImageMatrix(File f, boolean nchw); @Override org.datavec.image.data.Image asImageMatrix(InputStream inputStream); @Override org.datavec.image.data.Image asImageMatrix(InputStream inputStream, boolean nchw); INDArray asMatrix(BufferedImage image); INDArray asImageMiniBatches(File f, int numMiniBatches, int numRowsPerSlice); int[] flattenedImageFromFile(File f); int[][] fromFile(File file); int[][][] fromFileMultipleChannels(File file); static BufferedImage toImage(INDArray matrix); void toBufferedImageRGB(INDArray arr, BufferedImage image); static BufferedImage toBufferedImage(Image img, int type); BufferedImage centerCropIfNeeded(BufferedImage img);  }