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

发布于 2024-09-16 07:22:49 字数 1145 浏览 3 评论 0原文

一直在谷歌上浏览,但没有找到任何像我所追求的。那么我到底在追求什么呢?嗯,有两件事:

  • 首先,我正在寻找一个 算法/伪代码/白皮书 确定最适合的颜色 给出 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;
} 

Been poking around google and haven't found any like what I'm after. so what is it I'm after? well two things:

  • firstly I'm looking for an
    algorithm/pseudo-code/white-papers
    to determine a best-fit color for a
    give r,g,b tuple from and array of
    256 RGB tuples.

  • Secondly, I'm looking for an
    algorithm/pseudo-code/white-papers to
    recolor a 8bit palette image(using
    the above RGB palette) to either a
    given Hue/Saturation or by r,g,b
    channel modification. also would be
    nice if it was possible to add a fix
    for gamma and artifacting pixels in
    the colorization as well.

anyone got any hints/pointers/tips as to where I might find such a thing(I know they must exist, else a few of photoshops functions wouldn't)

UPDATE: here is a basic euclidean distance RGB to palette index finder:

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;
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑忘罢 2024-09-23 07:22:49

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

See http://en.wikipedia.org/wiki/Color_difference for how to calculate distances between colors so that human eye sensitivity is taken into account.

拒绝两难 2024-09-23 07:22:49

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

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

If you want it faster than linear search, then check out VP-tree or KD-tree.

If you want it perceptually accurate, then do the search in Lab color space.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文