How to calculate "amount" of color component in an RGB color
I wanted to perform a simple image analyses where I determine which portion of an image corresponds to a certain "control color range". I have reduced the image to a 2D pixel map containing RGB values but now I'm stuck trying to determine how much red, for example is contained in a certain pixel.
I know so little about color I'm having difficult time even finding the correct terms to use to start my search. Is there a simple formula to calculate the average or majority of an RGB component (the control color) that is contained in an RGB color? The goal is provide a control color and percent of it's amount that exists so I can filter it out from the other colors in the pixel map (ie this pixel is 80% red).
Thanks for your ideas.
Here is an idea.
Load your image into an RGB color array.
Check each entry of the array to find the largest amount of color in that pixel.
Here is a little diagram of what I am trying to explain.
| R | G | B |
| 0 | 1 |255|
Going through you see that blue is the closest number to 255. Add it to an integer.
int r = 0;
int g = 0;
int b = 0;
b = b + 1;
When you are done analyzing each entry in the array check to see what color is the closest to 255.
r = 255 - r;
g = 255 - r;
b = 255 - r;
Compare each value to find the largest number.
And their you go.
链接地址: http://www.djcxy.com/p/87032.html上一篇: 如何计算亮度相同的RGB值
下一篇: 如何计算RGB颜色中颜色分量的“量”