3

一直在谷歌周围闲逛,并没有找到任何像我所追求的东西。那我在追求什么?有两件事:

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

  • 其次,我正在寻找一种算法/伪代码/白皮书来将 8 位调色板图像(使用上面的 RGB 调色板)重新着色为给定的色相/饱和度或通过 r、g、b 通道修改。如果可以在着色中添加伽玛和伪影像素的修复,那也很好。

任何人都得到了关于我在哪里可以找到这样的东西的任何提示/指针/提示(我知道它们必须存在,否则一些 Photoshop 功能不会)

更新:这是一个基本的欧几里德距离 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;
} 
4

2 回答 2

1

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

于 2011-01-04T14:48:28.167 回答
0

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

如果您希望它在感知上准确,请在Lab 颜色空间中进行搜索。

于 2013-03-05T11:51:19.877 回答