代码之家  ›  专栏  ›  技术社区  ›  Necrolis

着色和调色板最佳匹配算法

  •  3
  • Necrolis  · 技术社区  · 14 年前

    一直在搜索谷歌,却没有找到我想要的东西。我在找什么?有两件事:

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

    • 其次,我在找一个 算法/伪代码/白皮书 对8位调色板图像重新着色(使用 上面的RGB调色板)到 给定色调/饱和度或r、g、b 信道修改。也会 很好,如果可以添加修复 对于gamma和伪影像素 还有着色。

    任何人都能得到我在哪里可以找到这样一个东西的任何提示/指针/提示(我知道它们一定存在,否则一些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 回复  |  直到 12 年前
        1
  •  1
  •   kbjorklu    14 年前

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

        2
  •  0
  •   Kornel    12 年前

    如果你想要比线性搜索更快的速度,那就去看看 VP-tree 或KD树。

    如果你想让它感觉准确,那就在 Lab color space .