gpt4 book ai didi

c++ - 通过近似选择颜色区域

转载 作者:太空宇宙 更新时间:2023-11-04 11:41:18 25 4
gpt4 key购买 nike

有谁知道图像处理器(如 Photoshop 或 Gimp)用来选择具有相似颜色的区域的方法的名称?另外,任何人都可以指出一些链接来解释此方法(如果可能,使用 C++ 代码)吗?

最佳答案

如果您有兴趣,这可能是检查一种颜色是否与另一种颜色相似的示例。它还像 gimp 和 paint.net 那样使用公差作为魔杖。

然而,这个例子比较的是明度上的差异,而不是颜色或亮度上的差异。

/*\ function to check if the color at this position is similar to the one you chose
|* Parameters:
|* int color - the value of the color of choice
|* int x - position x of the pixel
|* int y - position y of the pixel
|* float tolerance - how much this pixels color can differ to still be considered similar
\*/

bool isSimilar(int color, int x, int y, float tolerance)
{
// calculate difference between your color and the max value color can have
int diffMaxColor = 0xFFFFFF - color;
// set the minimum difference between your color and the minimum value of color
int diffMinColor = color;
// pseudo function to get color ( could return 'colorMap[y * width + x];')
int chkColor = getColor(x, y);
// now checking whether or not the color of the pixel is in the range between max and min with tolerance
if(chkColor > (color + (diffMaxColor * tolerance)) || chkColor < ((1 - tolerance) * diffMinColor))
{
// the color is outside our tolerated range
return false;
}
// the color is inside our tolerated range
return true;
}

关于c++ - 通过近似选择颜色区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21331647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com