本文介绍了我如何修复这个YCrCb - > RBG转换公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的公式:

  uint8_t * rgbBuffer = malloc(imageWidth * imageHeight * 3); 

// ..在ITU-R BT.601的高度和宽度上迭代

//舍入为整数
rgbOutput [0] =(298 * (y-16)+ 409 * cr-223)> 8;
rgbOutput [1] =(298 *(y-16)+ 100 * cb + 208 * cr + 136) 8;
rgbOutput [2] =(298 *(y-16)+ 516 * cb-277)> 8;

我假设是基于。





但我认为公式不是非常对,因为输出图像看起来像这样:





如何修复公式?

解决方案

假设第一个计算的最大值( y == 255 cr == 255 ) :

  rgbOutput [0] =(298 *(255  -  16)+ 409 * 255  -  223)> 8; 
rgbOutput [0] =(298 * 239 + 104295 - 223)> 8;
rgbOutput [0] =(71222 + 104295 - 223)> 8;
rgbOutput [0] = 175294> 8; // 175294 == 0x2ACBE
rgbOutput [0] = 684; // 684 == 0x2AC

rgbOutput [0] / code>可以保存 255 。您尝试将 684 分配给它,导致截断。分配给它的实际值为 172 0xAC )。



编辑1



根据您发布的公式,您的第一次计算应该如下:

  rgbOutput [0] =((298 * y)> 8)+((409 * cr)> 8) 

这将产生一个值(假设 y cr 480 ,也会导致截断。



EDIT 2



据说推荐以下公式:





使用此您的第一个计算应该是这样:

  rgbOutput [0] =((255 *(y  -  16))/ 219)+((179 *(cr_128))/ 112; 

480 y cr 的最大值)



$ b b $ b

查看@Robert的完整解决方案。



EDIT 4



y == 0 cr == 0 时,写入 y 也会导致截断,除非执行钳位。


Im using a formula from this question:

uint8_t *rgbBuffer = malloc(imageWidth * imageHeight * 3);

// .. iterate over height and width

// from ITU-R BT.601, rounded to integers
rgbOutput[0] = (298 * (y - 16) + 409 * cr - 223) >> 8;
rgbOutput[1] = (298 * (y - 16) + 100 * cb + 208 * cr + 136) >> 8;
rgbOutput[2] = (298 * (y - 16) + 516 * cb - 277) >> 8;

Which I assume is based in the ITU-R_BT.601 formula in the wiki article.

However I think the formula is not quite right because the output image looks like this:

How do I fix the formula?

解决方案

Assuming max values for the first calculation (y == 255 and cr == 255):

rgbOutput[0] = (298 * (255 - 16) + 409 * 255 - 223) >> 8;
rgbOutput[0] = (298 * 239 + 104295 - 223) >> 8;
rgbOutput[0] = (71222 + 104295 - 223) >> 8;
rgbOutput[0] = 175294 >> 8; // 175294 == 0x2ACBE
rgbOutput[0] = 684; // 684 == 0x2AC

The maximum value that rgbOutput[0] can hold is 255. You're attempting to assign 684 to it, resulting in truncation. The actual value assigned to it is 172 (0xAC).

EDIT 1

According to the formula you posted, your first calculation should be as follows:

rgbOutput[0] = ((298 * y) >> 8) + ((409 * cr) >> 8) - 223;

This results in a value of (assuming max values for y and cr) of 480, which results in truncation as well.

EDIT 2

The following equation is said to be recommended:

Using this instead, your first calculation should be like this:

rgbOutput[0] = ((255 * (y - 16)) / 219) + ((179 * (cr - 128)) / 112;

This results in a value of (assuming max values for y and cr) of 480 (the same answer in EDIT 1), which results in truncation as well.

EDIT 3

See answer from @Robert for complete solution.

EDIT 4

When y == 0 and cr == 0, the value that is written to y will also result in truncation unless clamping is performed.

这篇关于我如何修复这个YCrCb - > RBG转换公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 08:07