着色和调色板最佳拟合算法
一直在谷歌上浏览,但没有找到任何像我所追求的。那么我到底在追求什么呢?嗯,有两件事:
首先,我正在寻找一个 算法/伪代码/白皮书 确定最适合的颜色 给出 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅 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.
如果您希望它比线性搜索更快,请查看 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.