Why doesn't computing the average of RGB produce brightness of a pixel?










1














I am doing a bit of research for a small project I intend to make and that included determining the brightness of a pixel. First idea that came to my mind was to just compute brightness = (R + G + B)/3 but then I stumbled upon this answer which had very different and specific equations. Why wouldn't averaging RGB values work?










share|improve this question























  • @CrisLuengo Oh yeah that is correct, thank you
    – Eyad
    Nov 10 at 3:41















1














I am doing a bit of research for a small project I intend to make and that included determining the brightness of a pixel. First idea that came to my mind was to just compute brightness = (R + G + B)/3 but then I stumbled upon this answer which had very different and specific equations. Why wouldn't averaging RGB values work?










share|improve this question























  • @CrisLuengo Oh yeah that is correct, thank you
    – Eyad
    Nov 10 at 3:41













1












1








1


1





I am doing a bit of research for a small project I intend to make and that included determining the brightness of a pixel. First idea that came to my mind was to just compute brightness = (R + G + B)/3 but then I stumbled upon this answer which had very different and specific equations. Why wouldn't averaging RGB values work?










share|improve this question















I am doing a bit of research for a small project I intend to make and that included determining the brightness of a pixel. First idea that came to my mind was to just compute brightness = (R + G + B)/3 but then I stumbled upon this answer which had very different and specific equations. Why wouldn't averaging RGB values work?







image image-processing colors rgb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 3:41

























asked Nov 10 at 1:08









Eyad

113




113











  • @CrisLuengo Oh yeah that is correct, thank you
    – Eyad
    Nov 10 at 3:41
















  • @CrisLuengo Oh yeah that is correct, thank you
    – Eyad
    Nov 10 at 3:41















@CrisLuengo Oh yeah that is correct, thank you
– Eyad
Nov 10 at 3:41




@CrisLuengo Oh yeah that is correct, thank you
– Eyad
Nov 10 at 3:41












1 Answer
1






active

oldest

votes


















3














Our eyes are more sensitive to green light, so 255 in the green channel leads to a larger perception of brightness than 255 in the red or blue channel.



The International Commission on Illumination (CIE) created two standard color spaces in 1931 (CIE 1931 XYZ and CIE 1931 RGB color space), derived from perceptual experiments performed during the 1920's. These experiments and color spaces are the basis of all colorimetry today*.



In the CIE 1931 RGB color space, the luminance equation Y, is defined as:



Y = ( 0.17697 R + 0.81240 G + 0.01063 B ) / 0.17697


However, the definition of Y from RGB depends on the primaries used for R, G and B (e.g. the three pure colors emitted by an LCD monitor) and the color of the white produced by their addition. For example, for a standard D65 white point and the primaries from Rec. 709 and sRGB, the conversion from RGB to Y is as follows:



Y = 0.2126 R + 0.7152 G + 0.0722 B


This equation weights green about ten times more strongly than blue. This matches what is known about color perception, and explains for example why, on a computer screen, green text on a black background is quite OK to read, whereas blue text on the same background is much harder to read.



If you want to learn more about different color spaces, and how to convert between them, you should read Poynton's Color FAQ.




*A lot has been learned about color perception since, and new color spaces such as CIELAB and CIELUV have been published, but CIE XYZ is still the foundation for them.






share|improve this answer






















  • So if I am writing a program and I take the average of RGB values as an indicator of brightness, that's correct? What I understood is that these values determine brightness to our eyes, not to the computer.
    – Eyad
    Nov 10 at 2:27










  • The entire concept of brightness exists in humans, not in computers. It is a perceptual quality. If you want to measure how a computer perceives something, you'll need to do the work to measure it yourself and figure out how it's perceived by the computer. But if you're doing anything that's going to translate the RGB into a brightness as determined by a human, you'll want to use the formulas you found. I can tell you that professional photo and video editing apps use formulas like those in the linked question.
    – user1118321
    Nov 10 at 2:53










  • The idea I have is that my application will determine the brightness of a pixel and replace it with a character. I'll have pre-set ranges of brightness that map differently to characters, so no human perception of the picture or the brightness is actually going to happen. It's all inside the computer and it just outputs a .txt file after it's done with all the characters replacing each pixel depending on that pixels "brightness".
    – Eyad
    Nov 10 at 2:56






  • 1




    @Eyad be aware that calculating the brightness of a character requires gamma correction - a checkerboard of 50% white 50% black looks like (186,186,186) not (128,128,128). If it's not obvious that green (0,255,0) is lighter than blue (0,0,255) then maybe it's better to compare yellow (255,255,0) to magenta (255,0,255).
    – Mark Ransom
    Nov 10 at 3:51






  • 1




    I would argue that you are dealing with human perception. You're trying to convert a human-perceived brightness into a character that has the same brightness. You want the text file to look (i.e. be humanly perceived as) roughly the same brightness in the corresponding areas as the image. You should absolutely use one of the formulas mentioned here for that.
    – user1118321
    Nov 10 at 4:33










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235166%2fwhy-doesnt-computing-the-average-of-rgb-produce-brightness-of-a-pixel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Our eyes are more sensitive to green light, so 255 in the green channel leads to a larger perception of brightness than 255 in the red or blue channel.



The International Commission on Illumination (CIE) created two standard color spaces in 1931 (CIE 1931 XYZ and CIE 1931 RGB color space), derived from perceptual experiments performed during the 1920's. These experiments and color spaces are the basis of all colorimetry today*.



In the CIE 1931 RGB color space, the luminance equation Y, is defined as:



Y = ( 0.17697 R + 0.81240 G + 0.01063 B ) / 0.17697


However, the definition of Y from RGB depends on the primaries used for R, G and B (e.g. the three pure colors emitted by an LCD monitor) and the color of the white produced by their addition. For example, for a standard D65 white point and the primaries from Rec. 709 and sRGB, the conversion from RGB to Y is as follows:



Y = 0.2126 R + 0.7152 G + 0.0722 B


This equation weights green about ten times more strongly than blue. This matches what is known about color perception, and explains for example why, on a computer screen, green text on a black background is quite OK to read, whereas blue text on the same background is much harder to read.



If you want to learn more about different color spaces, and how to convert between them, you should read Poynton's Color FAQ.




*A lot has been learned about color perception since, and new color spaces such as CIELAB and CIELUV have been published, but CIE XYZ is still the foundation for them.






share|improve this answer






















  • So if I am writing a program and I take the average of RGB values as an indicator of brightness, that's correct? What I understood is that these values determine brightness to our eyes, not to the computer.
    – Eyad
    Nov 10 at 2:27










  • The entire concept of brightness exists in humans, not in computers. It is a perceptual quality. If you want to measure how a computer perceives something, you'll need to do the work to measure it yourself and figure out how it's perceived by the computer. But if you're doing anything that's going to translate the RGB into a brightness as determined by a human, you'll want to use the formulas you found. I can tell you that professional photo and video editing apps use formulas like those in the linked question.
    – user1118321
    Nov 10 at 2:53










  • The idea I have is that my application will determine the brightness of a pixel and replace it with a character. I'll have pre-set ranges of brightness that map differently to characters, so no human perception of the picture or the brightness is actually going to happen. It's all inside the computer and it just outputs a .txt file after it's done with all the characters replacing each pixel depending on that pixels "brightness".
    – Eyad
    Nov 10 at 2:56






  • 1




    @Eyad be aware that calculating the brightness of a character requires gamma correction - a checkerboard of 50% white 50% black looks like (186,186,186) not (128,128,128). If it's not obvious that green (0,255,0) is lighter than blue (0,0,255) then maybe it's better to compare yellow (255,255,0) to magenta (255,0,255).
    – Mark Ransom
    Nov 10 at 3:51






  • 1




    I would argue that you are dealing with human perception. You're trying to convert a human-perceived brightness into a character that has the same brightness. You want the text file to look (i.e. be humanly perceived as) roughly the same brightness in the corresponding areas as the image. You should absolutely use one of the formulas mentioned here for that.
    – user1118321
    Nov 10 at 4:33















3














Our eyes are more sensitive to green light, so 255 in the green channel leads to a larger perception of brightness than 255 in the red or blue channel.



The International Commission on Illumination (CIE) created two standard color spaces in 1931 (CIE 1931 XYZ and CIE 1931 RGB color space), derived from perceptual experiments performed during the 1920's. These experiments and color spaces are the basis of all colorimetry today*.



In the CIE 1931 RGB color space, the luminance equation Y, is defined as:



Y = ( 0.17697 R + 0.81240 G + 0.01063 B ) / 0.17697


However, the definition of Y from RGB depends on the primaries used for R, G and B (e.g. the three pure colors emitted by an LCD monitor) and the color of the white produced by their addition. For example, for a standard D65 white point and the primaries from Rec. 709 and sRGB, the conversion from RGB to Y is as follows:



Y = 0.2126 R + 0.7152 G + 0.0722 B


This equation weights green about ten times more strongly than blue. This matches what is known about color perception, and explains for example why, on a computer screen, green text on a black background is quite OK to read, whereas blue text on the same background is much harder to read.



If you want to learn more about different color spaces, and how to convert between them, you should read Poynton's Color FAQ.




*A lot has been learned about color perception since, and new color spaces such as CIELAB and CIELUV have been published, but CIE XYZ is still the foundation for them.






share|improve this answer






















  • So if I am writing a program and I take the average of RGB values as an indicator of brightness, that's correct? What I understood is that these values determine brightness to our eyes, not to the computer.
    – Eyad
    Nov 10 at 2:27










  • The entire concept of brightness exists in humans, not in computers. It is a perceptual quality. If you want to measure how a computer perceives something, you'll need to do the work to measure it yourself and figure out how it's perceived by the computer. But if you're doing anything that's going to translate the RGB into a brightness as determined by a human, you'll want to use the formulas you found. I can tell you that professional photo and video editing apps use formulas like those in the linked question.
    – user1118321
    Nov 10 at 2:53










  • The idea I have is that my application will determine the brightness of a pixel and replace it with a character. I'll have pre-set ranges of brightness that map differently to characters, so no human perception of the picture or the brightness is actually going to happen. It's all inside the computer and it just outputs a .txt file after it's done with all the characters replacing each pixel depending on that pixels "brightness".
    – Eyad
    Nov 10 at 2:56






  • 1




    @Eyad be aware that calculating the brightness of a character requires gamma correction - a checkerboard of 50% white 50% black looks like (186,186,186) not (128,128,128). If it's not obvious that green (0,255,0) is lighter than blue (0,0,255) then maybe it's better to compare yellow (255,255,0) to magenta (255,0,255).
    – Mark Ransom
    Nov 10 at 3:51






  • 1




    I would argue that you are dealing with human perception. You're trying to convert a human-perceived brightness into a character that has the same brightness. You want the text file to look (i.e. be humanly perceived as) roughly the same brightness in the corresponding areas as the image. You should absolutely use one of the formulas mentioned here for that.
    – user1118321
    Nov 10 at 4:33













3












3








3






Our eyes are more sensitive to green light, so 255 in the green channel leads to a larger perception of brightness than 255 in the red or blue channel.



The International Commission on Illumination (CIE) created two standard color spaces in 1931 (CIE 1931 XYZ and CIE 1931 RGB color space), derived from perceptual experiments performed during the 1920's. These experiments and color spaces are the basis of all colorimetry today*.



In the CIE 1931 RGB color space, the luminance equation Y, is defined as:



Y = ( 0.17697 R + 0.81240 G + 0.01063 B ) / 0.17697


However, the definition of Y from RGB depends on the primaries used for R, G and B (e.g. the three pure colors emitted by an LCD monitor) and the color of the white produced by their addition. For example, for a standard D65 white point and the primaries from Rec. 709 and sRGB, the conversion from RGB to Y is as follows:



Y = 0.2126 R + 0.7152 G + 0.0722 B


This equation weights green about ten times more strongly than blue. This matches what is known about color perception, and explains for example why, on a computer screen, green text on a black background is quite OK to read, whereas blue text on the same background is much harder to read.



If you want to learn more about different color spaces, and how to convert between them, you should read Poynton's Color FAQ.




*A lot has been learned about color perception since, and new color spaces such as CIELAB and CIELUV have been published, but CIE XYZ is still the foundation for them.






share|improve this answer














Our eyes are more sensitive to green light, so 255 in the green channel leads to a larger perception of brightness than 255 in the red or blue channel.



The International Commission on Illumination (CIE) created two standard color spaces in 1931 (CIE 1931 XYZ and CIE 1931 RGB color space), derived from perceptual experiments performed during the 1920's. These experiments and color spaces are the basis of all colorimetry today*.



In the CIE 1931 RGB color space, the luminance equation Y, is defined as:



Y = ( 0.17697 R + 0.81240 G + 0.01063 B ) / 0.17697


However, the definition of Y from RGB depends on the primaries used for R, G and B (e.g. the three pure colors emitted by an LCD monitor) and the color of the white produced by their addition. For example, for a standard D65 white point and the primaries from Rec. 709 and sRGB, the conversion from RGB to Y is as follows:



Y = 0.2126 R + 0.7152 G + 0.0722 B


This equation weights green about ten times more strongly than blue. This matches what is known about color perception, and explains for example why, on a computer screen, green text on a black background is quite OK to read, whereas blue text on the same background is much harder to read.



If you want to learn more about different color spaces, and how to convert between them, you should read Poynton's Color FAQ.




*A lot has been learned about color perception since, and new color spaces such as CIELAB and CIELUV have been published, but CIE XYZ is still the foundation for them.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 19:59

























answered Nov 10 at 1:57









Cris Luengo

18.5k51947




18.5k51947











  • So if I am writing a program and I take the average of RGB values as an indicator of brightness, that's correct? What I understood is that these values determine brightness to our eyes, not to the computer.
    – Eyad
    Nov 10 at 2:27










  • The entire concept of brightness exists in humans, not in computers. It is a perceptual quality. If you want to measure how a computer perceives something, you'll need to do the work to measure it yourself and figure out how it's perceived by the computer. But if you're doing anything that's going to translate the RGB into a brightness as determined by a human, you'll want to use the formulas you found. I can tell you that professional photo and video editing apps use formulas like those in the linked question.
    – user1118321
    Nov 10 at 2:53










  • The idea I have is that my application will determine the brightness of a pixel and replace it with a character. I'll have pre-set ranges of brightness that map differently to characters, so no human perception of the picture or the brightness is actually going to happen. It's all inside the computer and it just outputs a .txt file after it's done with all the characters replacing each pixel depending on that pixels "brightness".
    – Eyad
    Nov 10 at 2:56






  • 1




    @Eyad be aware that calculating the brightness of a character requires gamma correction - a checkerboard of 50% white 50% black looks like (186,186,186) not (128,128,128). If it's not obvious that green (0,255,0) is lighter than blue (0,0,255) then maybe it's better to compare yellow (255,255,0) to magenta (255,0,255).
    – Mark Ransom
    Nov 10 at 3:51






  • 1




    I would argue that you are dealing with human perception. You're trying to convert a human-perceived brightness into a character that has the same brightness. You want the text file to look (i.e. be humanly perceived as) roughly the same brightness in the corresponding areas as the image. You should absolutely use one of the formulas mentioned here for that.
    – user1118321
    Nov 10 at 4:33
















  • So if I am writing a program and I take the average of RGB values as an indicator of brightness, that's correct? What I understood is that these values determine brightness to our eyes, not to the computer.
    – Eyad
    Nov 10 at 2:27










  • The entire concept of brightness exists in humans, not in computers. It is a perceptual quality. If you want to measure how a computer perceives something, you'll need to do the work to measure it yourself and figure out how it's perceived by the computer. But if you're doing anything that's going to translate the RGB into a brightness as determined by a human, you'll want to use the formulas you found. I can tell you that professional photo and video editing apps use formulas like those in the linked question.
    – user1118321
    Nov 10 at 2:53










  • The idea I have is that my application will determine the brightness of a pixel and replace it with a character. I'll have pre-set ranges of brightness that map differently to characters, so no human perception of the picture or the brightness is actually going to happen. It's all inside the computer and it just outputs a .txt file after it's done with all the characters replacing each pixel depending on that pixels "brightness".
    – Eyad
    Nov 10 at 2:56






  • 1




    @Eyad be aware that calculating the brightness of a character requires gamma correction - a checkerboard of 50% white 50% black looks like (186,186,186) not (128,128,128). If it's not obvious that green (0,255,0) is lighter than blue (0,0,255) then maybe it's better to compare yellow (255,255,0) to magenta (255,0,255).
    – Mark Ransom
    Nov 10 at 3:51






  • 1




    I would argue that you are dealing with human perception. You're trying to convert a human-perceived brightness into a character that has the same brightness. You want the text file to look (i.e. be humanly perceived as) roughly the same brightness in the corresponding areas as the image. You should absolutely use one of the formulas mentioned here for that.
    – user1118321
    Nov 10 at 4:33















So if I am writing a program and I take the average of RGB values as an indicator of brightness, that's correct? What I understood is that these values determine brightness to our eyes, not to the computer.
– Eyad
Nov 10 at 2:27




So if I am writing a program and I take the average of RGB values as an indicator of brightness, that's correct? What I understood is that these values determine brightness to our eyes, not to the computer.
– Eyad
Nov 10 at 2:27












The entire concept of brightness exists in humans, not in computers. It is a perceptual quality. If you want to measure how a computer perceives something, you'll need to do the work to measure it yourself and figure out how it's perceived by the computer. But if you're doing anything that's going to translate the RGB into a brightness as determined by a human, you'll want to use the formulas you found. I can tell you that professional photo and video editing apps use formulas like those in the linked question.
– user1118321
Nov 10 at 2:53




The entire concept of brightness exists in humans, not in computers. It is a perceptual quality. If you want to measure how a computer perceives something, you'll need to do the work to measure it yourself and figure out how it's perceived by the computer. But if you're doing anything that's going to translate the RGB into a brightness as determined by a human, you'll want to use the formulas you found. I can tell you that professional photo and video editing apps use formulas like those in the linked question.
– user1118321
Nov 10 at 2:53












The idea I have is that my application will determine the brightness of a pixel and replace it with a character. I'll have pre-set ranges of brightness that map differently to characters, so no human perception of the picture or the brightness is actually going to happen. It's all inside the computer and it just outputs a .txt file after it's done with all the characters replacing each pixel depending on that pixels "brightness".
– Eyad
Nov 10 at 2:56




The idea I have is that my application will determine the brightness of a pixel and replace it with a character. I'll have pre-set ranges of brightness that map differently to characters, so no human perception of the picture or the brightness is actually going to happen. It's all inside the computer and it just outputs a .txt file after it's done with all the characters replacing each pixel depending on that pixels "brightness".
– Eyad
Nov 10 at 2:56




1




1




@Eyad be aware that calculating the brightness of a character requires gamma correction - a checkerboard of 50% white 50% black looks like (186,186,186) not (128,128,128). If it's not obvious that green (0,255,0) is lighter than blue (0,0,255) then maybe it's better to compare yellow (255,255,0) to magenta (255,0,255).
– Mark Ransom
Nov 10 at 3:51




@Eyad be aware that calculating the brightness of a character requires gamma correction - a checkerboard of 50% white 50% black looks like (186,186,186) not (128,128,128). If it's not obvious that green (0,255,0) is lighter than blue (0,0,255) then maybe it's better to compare yellow (255,255,0) to magenta (255,0,255).
– Mark Ransom
Nov 10 at 3:51




1




1




I would argue that you are dealing with human perception. You're trying to convert a human-perceived brightness into a character that has the same brightness. You want the text file to look (i.e. be humanly perceived as) roughly the same brightness in the corresponding areas as the image. You should absolutely use one of the formulas mentioned here for that.
– user1118321
Nov 10 at 4:33




I would argue that you are dealing with human perception. You're trying to convert a human-perceived brightness into a character that has the same brightness. You want the text file to look (i.e. be humanly perceived as) roughly the same brightness in the corresponding areas as the image. You should absolutely use one of the formulas mentioned here for that.
– user1118321
Nov 10 at 4:33

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235166%2fwhy-doesnt-computing-the-average-of-rgb-produce-brightness-of-a-pixel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)