title: Robust color tracking vs exposure and white balance changes
body: <p>Does anyone had the experience with color matching and frame-to-frame tracking of it video when the exposure settings and white balance are constantly changing?</p>
  
  <p>I'm working on color tracking app that uses iPad 2 frontal camera to capture video. I need to detect colored objects (of predefined color we took earlier) on each frame. My problem is that the camera software are like to adjust WB and Exposure each frame. So if we remember one color at frame N, on N+10 frame the WB will be different and this can lead to big difference in color.</p>
  
  <p>For calculating color distance I'm using <strong>LAB</strong> color space and <strong>CIE76</strong> formula:
  <img src="https://i.stack.imgur.com/3bJGG.png" alt="enter image description here"></p>
  
  <p>Yes, i know there is much better CIEDE2000 distance function, but I'm working with ARM processor and I'm afraid this formula will be too heavy even for ARM NEON manually optimized assembly code that i use already. </p>
  
  <p>CIE76 provides a good results in general, but in poor or very bright lighting scenes the camera either generate too much noise or over-saturate the image so the colors becomes too far from their original. In addition to simple thresholding using color distance i implemented per-component thresholding of LAB pixel values based on standard deviation of the calibrated color. This had also increased correctness of the detection, however, this isn't solving the main issue.</p>
  
  <p>The camera itself provide frames in RGB color space, but the API doesn't provide functions to get white point or color temperature of the current frame. Currently i assume D50 illuminant to  perform RGB -> LAB conversion.</p>
  
  <p>And this is the my main doubt. <strong>My idea is to compute the white point of the given RGB image, and then convert it to XYZ color space and then convert XYZ to LAB using calculated white point.</strong> Is it possible? </p>
  
  <blockquote>
    <p><strong>From Wikipedia: White Point</strong></p>
    
    <p>Expressing color as tristimulus coordinates in the LMS color space, one can "translate" the object's color according to the von Kries transform simply by scaling the LMS coordinates by the ratio of the maximum of the tristimulus values at both white points. This provides a simple, but rough estimate.</p>
  </blockquote>
  
  <p><a href="http://en.wikipedia.org/wiki/White_point" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/White_point</a></p>
  
  <p>Are this going to work? Or there is a better way to calculate white point (even roughly)? By the way, i came out for <a href="http://en.wikipedia.org/wiki/Color_constancy" rel="nofollow noreferrer">Retinex</a> algorithm, which demonstrate good color enhancement in shadows, does anyone used it? What it's pros and cons? </p>