0

So I've got a project to convert an image to black and white manually by altering the argb values with an algorithm. I've tried averaging the RGB values and I come out with an almost completely grayscale image but there's still hints of color in it. Anyone have any algorithm examples to convert a pixel in aRGB to greyscale manually?

This is what I've been doing so far:

            //Apply the filter
            reds = ((reds+greens+blues)/3);
            greens = ((reds+greens+blues)/3);
            blues = ((reds+greens+blues)/3);
user1088595
  • 151
  • 2
  • 16
  • Worth noting that due to the biology of the human eye, red, green, and blue should not be evenly weighted when an image is converted to grayscale. – Jonathan Grynspan Feb 24 '13 at 20:22

2 Answers2

4

It looks like you're changing the inputs of the Right Hand Side while expecting its value to remain constant. Why not use this?

reds = (reds + greens + blues) / 3;
greens = reds;
blues = reds;
harold
  • 61,398
  • 6
  • 86
  • 164
3

I've always been under the impression that, due to our eyes' differing sensitivities to red, green and blue wavelengths, grayscale should be computed using:

(int) (0.299 * red + 0.587 * green + 0.114 * blue)

Years ago, this used to be easy information to find, but now I can't find too many sources for it. Wikipedia's entry on grayscale is one.

VGR
  • 40,506
  • 4
  • 48
  • 63