JPEG: YCrCb <-> RGB conversion precision

前端 未结 4 609
清酒与你
清酒与你 2021-01-27 02:31

I\'ve implemented rgb->ycrcb and ycrcb->rgb conversion using JPEG conversion formulae from
http://www.w3.org/Graphics/JPEG/jfif3.pdf
(the same at: http://en.wikipedia.o

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-27 02:46

    The problem isn't rounding modes.

    Even if you converted your floating point constants to ratios and used only integer math, you'd still see different values after the inverse.

    To see why, consider a function where I tell you I'm going to shift the numbers 0 through N to the range 0 through N-2. The fact is that this transform is just doesn't have an inverse. You can represent it more or less exactly with a floating point computation (f(x) = x*(N-2)/N), but some of the neighboring values will map to the same result in integer math (pigeonhole principle!). This is a simplification and "compresses" the range, but the same thing happens in arbitrary affine transforms like this one you are using.

    If you had r, g, b in floating point, and kept it that way until you quantized to integer, that would be a different story - but in integers you will necessarily always see some difference between the original and the inverse.

提交回复
热议问题