# Problems with using a rough greyscale algorithm?

• A+
Category：Languages

So I'm designing a few programs for editing photos in `python` using `PIL` and one of them was converting an image to greyscale (without using any functions from `PIL`).

The algorithm I've employed is simple: for each pixel (colour-depth is 24), I've calculated the average of the `R`, `G` and `B` values and set the RGB values to this average.

My program was producing greyscale images which seemed accurate, but I was wondering if I'd employed the correct algorithm, and I came across this answer to a question, where it seems that the 'correct' algorithm is to calculate `0.299 R + 0.587 G + 0.114 B`.

I decided to compare my program to this algorithm. I generated a greyscale image using my program and another one (using the same input) from a website online (the top Google result for `'image to grayscale'`.

To my naked eye, it seemed that they were exactly the same, and if there was any variation, I couldn't see it. However, I decided to use this website (top Google result for `'compare two images online'`) to compare my greyscale images. It turned out that deep in the pixels, they had slight variations, but none which were perceivable to the human eye.

My Questions (the first is the main question):

1. Are there any disadvantages to using my 'rough' greyscale algorithm?
2. Does anyone have any input images where my greyscale algorithm would produce a visibly different image to the one that would be 'correct' ?
3. Are there any colours/RBG combinations for which my algorithm won't work as well?

My key piece of code (if needed):

``def greyScale(pixelTuple):     return tuple([round(sum(pixelTuple) / 3)] * 3) ``

The 'correct' algorithm (which seems to heavily weight green):

``def greyScale(pixelTuple):     return tuple([round(0.299 * pixelTuple[0] + 0.587 * pixelTuple[1] + 0.114 * pixelTuple[2])] * 3) ``

My input image:

The greyscale image my algorithm produces:

The greyscale image which is 'correct':

When the greyscale images are compared online (highlighted red are the differences, using a fuzz of 10%):

Despite the variations in pixels highlighted above, the greyscale images above appear as nearly the exact same (at least, to me).

The images look pretty similar, but your eye can tell the difference, specially if you put one in place of the other:

For example, you can note that the flowers in the background look brighter in the averaging conversion.

It is not that there is anything intrinsically "bad" about averaging the three channels. The reason for that formula is that we do not perceive red, green and blue equally, so their contributions to the intensities in a grayscale image shouldn't be the same; since we perceive green more intensely, green pixels should look brighter on grayscale. However, as commented by Mark there is no unique perfect conversion to grayscale, since we see in color, and in any case everyone's vision is slightly different, so any formula will just try to make an approximation so pixel intensities feel "right" for most people.