Skip to content

MostContrastBW

George Plotnikov edited this page Mar 15, 2018 · 1 revision

MostContrastBW

Generates image with grayscale contrast deviation selection.

Path

ImageBlendingAlgorithms/IBALib/BlendingAlgorithms/MostContrastBW.cs

Essential code

public override Color Calculate(IEnumerable<Color> colors)
{
    var a = colors.ElementAt(0);
    var b = colors.ElementAt(1);
    var aY = Math.Abs(128 - GetY(a));
    var bY = Math.Abs(128 - GetY(b));
    return aY > bY ? a : b;
}

static double GetY(Color c) => 0.299 * c.R + 0.587 * c.G + 0.114 * c.B;

Examples

the results of handling 3 source images

cf6b3704-3cd6-427b-bb30-aff99a92cc63


4273d578-da3e-469f-96e4-feb0e38f53dc


7e5a8bec-a2ef-42b5-b027-e09ecc86762a

Clone this wiki locally