if you have an RGB image so that you can get the values (red, green, blue, gray):
BufferedImage img;
int rgb = img.getRGB(x, y);
int r = (rgb >> 16) & 0xFF;
int g = (rgb >> 8) & 0xFF;
int b = (rgb & 0xFF);
and gray is the average of (r, g, b), for example:
int gray = (r + g + b) / 3;
but if you convert an RGB image (24 bit) to a gray image (8 bit):
int gray= img.getRGB(x, y)& 0xFF;
source
share