着色和调色板最佳拟合算法

时间:2010-08-25 17:19:43

标签: c++ c assembly rgb color-palette

一直在谷歌四处寻找并没有找到任何像我追求的东西。那么我追求的是什么?好两件事:

  • 首先我正在寻找一个 算法/伪码/白论文 确定一个最合适的颜色 给出r,g,b元组和数组 256个RGB元组。

  • 其次,我正在寻找一个 算法/伪代码/白皮书 重新着色8位调色板图像(使用 以上RGB调色板)要么a 给定色调/饱和度或r,g,b 渠道修改。也会 很好,如果可以添加修复程序 用于伽玛和伪像像素 着色也是如此。

任何人都有任何提示/指示/提示,我可能会找到这样的东西(我知道它们必须存在,否则一些photoshops功能不会)

更新:这是一个基本的欧氏距离RGB到调色板索引查找器:

uint_8 __stdcall GFXUTIL_GetNearestPaletteIndex(const uint_8* pPalette, size_t nSize, uint_8 nRed, uint_8 nGreen, uint_8 nBlue)
{
    if(pPalette == NULL)
        return 0;

    int nDistance = -1;
    size_t nIndex = 0, nFoundIndex = 0;
    while(nIndex < nSize)
    {
        int nDistRed = pPalette[0] - nRed;
        int nDistGreen = pPalette[1] - nGreen;
        int nDistBlue = pPalette[2] - nBlue;
        int nCurrentDistance = (nDistRed * nDistRed) + (nDistGreen * nDistGreen) + (nDistBlue * nDistBlue);
        if(nCurrentDistance < nDistance)
        {
            nFoundIndex = nIndex;
            nDistance = nCurrentDistance;
        }

        nIndex++;
        pPalette += sizeof(uint_32);
    }

    return nFoundIndex;
} 

2 个答案:

答案 0 :(得分:1)

请参阅http://en.wikipedia.org/wiki/Color_difference了解如何计算颜色之间的距离,以便考虑人眼敏感度。

答案 1 :(得分:0)

如果您希望它比线性搜索更快,请查看VP-tree或KD树。

如果您希望它在感知上准确,请在Lab color space中进行搜索。