-2
public void setGraphicalDefaults(MouseEvent e)
{
    x = e.getX();
    y = e.getY();

    Color c = new Color(img.getRGB(x,y));

    int red = (c.getRed());
    int green =(c.getGreen());
    int blue = (c.getBlue());
    System.out.println(red + " "+ green + " "+ blue);

}

From the above code I can get the RGB values but how to get 'Grey Scale' value?

Laxminarayan
  • 188
  • 2
  • 16
  • You might want to check out this question: http://stackoverflow.com/questions/687261/converting-rgb-to-grayscale-intensity – mmdeas Jan 19 '15 at 12:05

1 Answers1

3

There are various algorithms to convert a color image to grayscale. One very simple solution is to average the three channels to get the gray value:

int gray = (red  + green + blue) / 3

Have a look at this article for more information:

http://www.johndcook.com/blog/2009/08/24/algorithms-convert-color-grayscale/

Thomas
  • 17,016
  • 4
  • 46
  • 70