有没有人知道图像处理器(如Photoshop或Gimp)使用的方法名称来选择颜色相似的区域?另外,任何人都可以指出一些链接来解释这个方法(如果可能的话用C ++代码)?
答案 0 :(得分:1)
如果您感兴趣,这可能是检查颜色是否与另一种颜色相似的示例。 它也使用容忍作为来自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;
}