【问题标题】:Selecting color region by approximation通过近似选择颜色区域
【发布时间】:2014-02-15 09:16:48
【问题描述】:

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

【问题讨论】:

标签: c++ image colors picker


【解决方案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;
}

【讨论】:

  • 感谢代码示例。我只有一个问题:如果我有三个颜色分量(红色、绿色、蓝色),我如何评估第一个参数(int color)的值?
  • 现在我明白你的意思了。参数 int color 只是您要与当前像素进行比较的颜色。使用魔棒时,此参数等于您单击的第一个像素的颜色。
猜你喜欢
  • 1970-01-01
  • 2020-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-16
  • 1970-01-01
相关资源
最近更新 更多