Home > Software engineering >  How to deal with RGB signals converts it to a concentration
How to deal with RGB signals converts it to a concentration

Time:10-29

I have already bought a color sensor, and be able to get to the R, G, B value (size are of 0 ~ 255), then I made the experimental samples are purple, deep shallow, I known their relationship to y=2 x + 1 (where x is refers to the color intensity, y is refers to the concentration of the sample), then I want to pass the color depth that my sample concentration, with C language implementation,
I won't get now is that I have got the RGB values such as (R=45, 56, G=B=122), how do I use these three values, because three values could not into my formula to calculate, so I want to consult everybody how to RGB values (three) for color intensity (a value) to calculate, is that gray level transformation, or other means to deal with, for a great god,

CodePudding user response:

Can't use red?
I think only the gray level transformation,

Should be added blue to red/purple, so use gray try first, if not, then adjust the proportion of several parameters,

CodePudding user response:

"Change color intensity"
RGBtoHSL?

CodePudding user response:

 
BOOL RGB2HLS (BYTE red, BYTE green, BYTE blue, int & amp; Hue, double & amp; Saturation, double & amp; Lightness)
{
Double mn, mx;
Int major;
If (red & lt; Green)
{
Mn=red; Mx=green; Major=Green;
}
The else
{
Mn=green; Mx=red; Major=Red;
}
//
If (blue & lt; Mn)
{
Mn=blue;
}
Else if (blue & gt; Mx)
{
Mx=blue; Major=Blue;
}
//
If (mn==mx)
{
Lightness=mn/255;
Saturation=0;
Hue=240;//?? 0;
}
The else
{
Lightness=(mn + mx)/510;//2 * 255
If (lightness & lt;=0.5) saturation=(double) (mx - mn)/(double) (mn + mx);
The else saturation=(double) (mx - mn)/(double) (510 - mn - mx);
The switch (major)
{
Case Red:
Hue=(int) (* 60 (green, blue)/(mx - mn) + 360);
break;
Case Green:
Hue=(int) ((blue - red) * 60/(mx - mn) + 120);
break;
Case Blue:
Hue=(int) (60/(red, green) * (mx - mn) + 240);
break;
}
If (hue & gt;=360) hue -=360;
}
If (mn==0 & amp; & Mx==255) return TRUE;
The else return FALSE;
}

CodePudding user response:

Comparing to the RGB values to HLS saturation and brightness

ColorRGBToHLS
http://baike.baidu.com/link? Url=_XK4CXzBzEpKEE8eyBrgtcDnE2ZF0opsSyHMCIi4HkYh7eS_RlpiDTOstzHAkEjmycP0hSnZWYkRCEdlYJqPa_

CodePudding user response:

RGB is converted to a show the strength of the color in color mode, after use your formula to calculate

CodePudding user response:

(R + G + B)/(R) (R * + * G (G) + (B * B)) ^ 2
  • Related