title: How to convert RGB -> YUV -> RGB (both ways)
body: <p>I want a pair of conversion algorithms, one from RGB to YUV, the other from YUV to RGB, that are inverses of each other.  That is, a round-trip conversion should leave the value unchanged.  (If you like, replace YUV with Y'UV, YUV, YCbCr, YPbPr.)</p>
  
  <p>Does such a thing exist?  If so, what is it?</p>
  
  <p>Posted solutions (<a href="https://stackoverflow.com/questions/1737726/how-to-perform-rgb-yuv-conversion-in-c-c/1737741#1737741">How to perform RGB-&gt;YUV conversion in C/C++?</a>, <a href="http://www.fourcc.org/fccyvrgb.php" rel="noreferrer">http://www.fourcc.org/fccyvrgb.php</a>, <a href="http://en.wikipedia.org/wiki/YUV" rel="noreferrer">http://en.wikipedia.org/wiki/YUV</a>) are only inverses (the two 3x3 matrices are inverses), when omitting the clamping to [0,255].  But omitting that clamping allows things like negative luminance, which plays merry havoc with image processing in YUV space.  Retaining the clamping makes the conversion nonlinear, which makes it tricky to define an inverse.</p>