C++ 用近似法选择颜色区域
有人知道Photoshop或Gimp等图像处理器用来选择颜色相似区域的方法的名称吗?另外,如果有可能的话,有人能用C++代码来解释这个方法的一些链接吗?< /p> < P>如果你感兴趣,这可以是一个检验颜色是否与另一个颜色相似的例子。 它还像gimp和paint.net中的魔杖一样使用公差 但是,此示例比较的是值的差异,而不是颜色或亮度的差异C++ 用近似法选择颜色区域,c++,image,colors,picker,C++,Image,Colors,Picker,有人知道Photoshop或Gimp等图像处理器用来选择颜色相似区域的方法的名称吗?另外,如果有可能的话,有人能用C++代码来解释这个方法的一些链接吗?< /p> < P>如果你感兴趣,这可以是一个检验颜色是否与另一个颜色相似的例子。 它还像gimp和paint.net中的魔杖一样使用公差 但是,此示例比较的是值的差异,而不是颜色或亮度的差异 /*\ function to check if the color at this position is similar to the one you
/*\ 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;
}
它应该使用一个简单的泛光填充算法,如这里所示,将相似度计算为RGB空间中两种颜色之间的距离。非常感谢,这就是我想要的。感谢代码示例。我只有一个问题:如果我有三个颜色分量,红色,绿色,蓝色,我如何计算第一个参数int color的值?现在我知道你的意思了。参数int color就是要与当前像素进行比较的颜色。使用魔杖,此参数等于您单击的第一个像素的颜色。