从RGB到YUV(YCoCg)的颜色转换
Color conversion from RGB to YUV (YCoCg)
我正在尝试实现一个输出到 3 个独立缓冲区的颜色转换Func
。rgb_to_ycocg
函数具有一个 4x8 位通道交错缓冲区 (BGRA( 和 3 个输出缓冲区(Y、Co 和 Cg(,每个缓冲器均为 16 位值。目前,我正在使用这段代码:
void rgb_to_ycocg(const uint8_t *pSrc, int32_t srcStep, int16_t *pDst[3], int32_t dstStep[3], int width, int height)
{
Buffer<uint8_t> inRgb((uint8_t *)pSrc, 4, width, height);
Buffer<int16_t> outY(pDst[0], width, height);
Buffer<int16_t> outCo(pDst[1], width, height);
Buffer<int16_t> outCg(pDst[2], width, height);
Var x, y, c;
Func calcY, calcCo, calcCg, inRgb16;
inRgb16(c, x, y) = cast<int16_t>(inRgb(c, x, y));
calcY(x, y) = (inRgb16(0, x, y) + ((inRgb16(2, x, y) - inRgb16(0, x, y)) >> 1)) + ((inRgb16(1, x, y) - (inRgb16(0, x, y) + ((inRgb16(2, x, y) - inRgb16(0, x, y)) >> 1))) >> 1);
calcCo(x, y) = inRgb16(2, x, y) - inRgb16(0, x, y);
calcCg(x, y) = inRgb16(1, x, y) - (inRgb16(0, x, y) + ((inRgb16(2, x, y) - inRgb16(0, x, y)) >> 1));
Pipeline p =Pipeline({calcY, calcCo, calcCg});
p.vectorize(x, 16).parallel(y);
p.realize({ outY, outCo, outCg });
}
问题是,与参考实现(c 中的基本循环(相比,我的性能很差。我知道我需要尝试更好的调度,但我认为我在输入/输出缓冲区方面做错了什么。我已经看过教程并试图想出一种输出到多个缓冲区的方法。使用Pipeline
是我能找到的唯一方法。我做 3 个Func
并单独调用它们会更好吗?这是对Pipeline
类的正确用法吗?
这里可能出现的最大问题是,每次要转换单个图像时,您都要制作和编译代码。那真的会很慢。使用 ImageParams 而不是 Buffers,定义一次管道,然后多次实现它。
二阶效应是,我认为你实际上想要一个元组而不是一个管道。元组函数在同一个内部循环中计算其所有值,这将重用来自 inRGB 等的负载。暂时忽略重新编译问题,请尝试:
void rgb_to_ycocg(const uint8_t *pSrc, int32_t srcStep, int16_t *pDst[3], int32_t dstStep[3], int width, int height)
{
Buffer<uint8_t> inRgb((uint8_t *)pSrc, 4, width, height);
Buffer<int16_t> outY(pDst[0], width, height);
Buffer<int16_t> outCo(pDst[1], width, height);
Buffer<int16_t> outCg(pDst[2], width, height);
Var x, y, c;
Func calcY, calcCo, calcCg, inRgb16;
inRgb16(c, x, y) = cast<int16_t>(inRgb(c, x, y));
out(x, y) = {
inRgb16(0, x, y) + ((inRgb16(2, x, y) - inRgb16(0, x, y)) >> 1)) + ((inRgb16(1, x, y) - (inRgb16(0, x, y) + ((inRgb16(2, x, y) - inRgb16(0, x, y)) >> 1))) >> 1),
inRgb16(2, x, y) - inRgb16(0, x, y),
inRgb16(1, x, y) - (inRgb16(0, x, y) + ((inRgb16(2, x, y) - inRgb16(0, x, y)) >> 1))
};
out.vectorize(x, 16).parallel(y);
out.realize({ outY, outCo, outCg });
}
相关文章:
- 将"打开的CV图像"中的"颜色"转换为整数格式
- GLSL 将 uint 转换为浮点颜色
- 颜色到灰度转换
- Qmage:使用颜色表从灰度转换为RGB
- OpenCV将一种颜色转换为任何其他颜色
- 从RGB到YUV(YCoCg)的颜色转换
- 如何将每个顶点的颜色转换为时间或某些功能
- 将RGB颜色图像转换为OpenCV C 中的索引颜色图像类型
- 如何将cv::Mat转换为带有颜色的pcl::点云
- 将整数转换为位图颜色 RGB 值 C++
- 将 32bpp 位图转换为 256 种颜色
- 将颜色图像转换为OpenCV中的灰度问题
- 处理 RGB 到 CIEL*a*b* 到 RGB "Out-of-Gamut"颜色转换
- 如何优化 YUV 到 RGB 颜色转换代码
- OpenCV将一种颜色转换为另一种颜色
- OpenGL颜色转换
- 将16位颜色转换为32位
- Nppi颜色转换问题
- 如何在C++中将16位十六进制颜色转换为RGB888值
- 颜色转换从ProPhoto RGB到监视器配置文件