code: public INDArray asMatrix(BufferedImage image) {
          if (channels == 3) {
              return toBgr(image);
          } else {
              image = scalingIfNeed(image, true);
              int w = image.getWidth();
              int h = image.getHeight();
              INDArray ret = Nd4j.create(h, w);
  
              for (int i = 0; i < h; i++) {
                  for (int j = 0; j < w; j++) {
                      ret.putScalar(new int[]{i, j}, image.getRGB(j, i));
                  }
              }
              return ret;
          }
      }
docs: Convert an BufferedImage to a matrix
  
  @param image the BufferedImage to convert
  @return the input stream to convert