Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion to grayscale uses wrong formula #2

Open
rtrussell opened this issue Jan 7, 2021 · 2 comments
Open

Conversion to grayscale uses wrong formula #2

rtrussell opened this issue Jan 7, 2021 · 2 comments

Comments

@rtrussell
Copy link

Currently the conversion to grayscale is using the formula:

Uint8 grayedColor=(rr+gg+bb)/3

This is wrong. When converting to grayscale, perceptual weighing must be applied (for example the eye is much less sensitive to blue than to green, so blue appears much darker when converted to grayscale). The most common formula used is that specified in CCIR 601, which is approximately:

0.30 * rr + 0.59 * gg + 0.11 * bb

or if you prefer to do it all in integers:

(30 * rr + 59 * gg + 11 * bb) / 100

There is much more detail available at Stack Overflow.

@nhurde
Copy link
Contributor

nhurde commented Jan 13, 2021

OMG, never even thought about colors that way before. I will do some changes to see how better it looks now. Also, does the current method apply as a different graphic effect/shader or should I just get rid of it?

@rtrussell
Copy link
Author

No harm leaving it as an option, I guess, but I can't think of any uses for it other than to provide compatibility with earlier versions of your software.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants