Color Detection using YCrCb color space?

橙三吉。 提交于 2019-12-08 05:26:33

问题


This code I have found attempt to track red color in RGB color space,

  // red color detection, turn the detected one into white
  if (((red > (0.85 * (green + blue))) && (red > 105)) 
     && ((red - green > 73)) && (((green < 150) 
     || ((green >= 150) && (blue > 140)))))  {
        // set the pixel to white
        red = 255; green = 255; blue = 255;
  }

Does anyone know how to track color using YCrCb color space instead RGB? I just don't know what exactly was the range for every color in order to track it, e.g. red color range in YCrCb.

Edit: I've tried HSV, It doesn't give better result than RGB above as expected, consequently, I consider to use YCrCb.

Thanks.


回答1:


First of all you can take a look here for a better definition. This color model (YCrCb) is more widely used in video formats like mpeg. Most video formats, if the video uses the the format 4:2:2, which means that the Y component (representing luminance) has the same size of the source RGB image while Yb (blue component) and Yr (Red component) are represented by half of the original image resolution. Doing that its possible to decrease the bandwidth of the file.

But, as kigurai said, if you want to track colors, you will better do it using HSV (or HSI) format. In that format the H (Hue) component represents the color itself raging from 0..359 (360 degrees). So to avoid rounding the numbers from 0..255 you can use a 16bit matrix to represent that channel in memory. Also in this color space S represents saturation (how much of the color component in H is present at that pixel) and S (or I) represents the image brightness.

To algorithm to implement it is not hard:

I = 1/3 * (R+G+B)

S = 1 - (3/(R+G+B))*(min(R,G,B))

H = cos^-1 ( (((R-G)+(R-B))/2)/ (sqrt((R-G)^2 + (R-B)*(G-B) )))




回答2:


I suggest you instead use HSV colour space which will most likely make this a lot easier.




回答3:


In YCbCr, the typical range is 16 to 240 for each component. See the following Wikipedia entry that details the various formulas to convert between RGB and YCbCr.



来源:https://stackoverflow.com/questions/1847821/color-detection-using-ycrcb-color-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!