title: histogram equalization on color image in YCbCr space
body: <p>Edit. I found the reason. I didn't do the clamping, which  I thought I did.</p>
  
  <p>I am trying to implement histogram equalization on an RGB color image.
  I understand that the equalization should be done to the luminance channel only, therefore here is what I am doing:</p>
  
  <ol>
  <li><p>convert R,G,B to Y, Cb, Cr by using the following conversion:
  <a href="https://i.stack.imgur.com/LEg5x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LEg5x.png" alt="enter image description here"></a>
  note the ranges of Y, Cb, Cr are all [0...255]</p></li>
  <li><p>generate the grayscale (Y channel) mapping (i.e, old_Y to new_Y) table by computing the histogram and the CDF </p></li>
  <li><p>for every pixel with value (old_Y, old_Cb, old_Cr), replace it with:
       (new_Y, old_Cb, old_Cr)</p></li>
  <li><p>convert (new_Y, old_Cb, old_Cr) to (new_R, new_G, new_B) by doing the following:
  <a href="https://i.stack.imgur.com/ohyWr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ohyWr.png" alt="enter image description here"></a></p></li>
  <li><p>display the image.</p></li>
  </ol>
  
  <p>Here is what I get for the result:</p>
  
  <p><a href="https://i.stack.imgur.com/eaG5V.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eaG5V.jpg" alt="enter image description here"></a></p>
  
  <p>Any idea about the saturated regions? Am I missing something in doing the color conversion?</p>