code: public static GrayU8 extractGrayU8(BufferedImage img) {
  		WritableRaster raster = img.getRaster();
  		DataBuffer buffer = raster.getDataBuffer();
  		if (buffer.getDataType() == DataBuffer.TYPE_BYTE && isKnownByteFormat(img) ) {
  
  			if (raster.getNumBands() != 1)
  				throw new IllegalArgumentException("Input image has more than one channel");
  			GrayU8 ret = new GrayU8();
  
  			ret.width = img.getWidth();
  			ret.height = img.getHeight();
  			ret.startIndex = ConvertRaster.getOffset(img.getRaster());
  			ret.stride = ConvertRaster.stride(img.getRaster());
  			ret.data = ((DataBufferByte)buffer).getData();
  
  			return ret;
  		}
  		throw new IllegalArgumentException("Buffered image does not have a gray scale byte raster");
  	}
docs: For BufferedImage stored as a byte array internally it extracts an
  image.  The input image and the returned image will both
  share the same internal data array.  Using this function allows unnecessary
  memory copying to be avoided.
  
  @param img Image whose internal data is extracted and wrapped.
  @return An image whose internal data is the same as the input image.