English 中文(简体)
Color Detection using YCrCb color space?
原标题:

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.

问题回答

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) )))

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

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签