Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 给定背景色和前景色,如何计算它们在图像中的混合量?_Image Processing_Colors_Image Manipulation - Fatal编程技术网

Image processing 给定背景色和前景色,如何计算它们在图像中的混合量?

Image processing 给定背景色和前景色,如何计算它们在图像中的混合量?,image-processing,colors,image-manipulation,Image Processing,Colors,Image Manipulation,我有一个如下所示的输入图像: private static double GetMixAmount(Color fore, Color back, Color input) { double lengthForeToBack = GetLengthBetween3DVectors(fore, back); double lengthForeToInput = GetLengthBetween3DVectors(fore, input); return 1 / (lengt

我有一个如下所示的输入图像:

private static double GetMixAmount(Color fore, Color back, Color input)
{
    double lengthForeToBack = GetLengthBetween3DVectors(fore, back);
    double lengthForeToInput = GetLengthBetween3DVectors(fore, input);
    return 1 / (lengthForeToBack / lengthForeToInput);
}

private static double GetLengthBetween3DVectors(Color a, Color b)
{
    // Typical length between two 3-dimensional points - simply handle RGB as XYZ!
    return Math.Sqrt(
        Math.Pow(a.R - b.R, 2) + Math.Pow(a.G - b.G, 2) + Math.Pow(a.B - b.B, 2));
}

如您所见,它是一个还原窗口图标,带有蓝色色调和粉红色背景

有些像素是两种颜色的混合,我想计算,但不知道如何计算。给出了100%背景色和100%前景色

最后,我想创建一个alpha位图,其中每个像素的RGB量是前景色RGB,但alpha通道是混合量:

在与几位数学家讨论后,我(自己)找到了答案

请阅读我的答案,了解其中的逻辑;在C#中,代码如下所示:

private static double GetMixAmount(Color fore, Color back, Color input)
{
    double lengthForeToBack = GetLengthBetween3DVectors(fore, back);
    double lengthForeToInput = GetLengthBetween3DVectors(fore, input);
    return 1 / (lengthForeToBack / lengthForeToInput);
}

private static double GetLengthBetween3DVectors(Color a, Color b)
{
    // Typical length between two 3-dimensional points - simply handle RGB as XYZ!
    return Math.Sqrt(
        Math.Pow(a.R - b.R, 2) + Math.Pow(a.G - b.G, 2) + Math.Pow(a.B - b.B, 2));
}
如果不知道前景色和背景色是否真的可以混合以产生输入颜色,请确保将alpha值钳制在0.0和1.0之间