Skip to content

AVGContrast

George Plotnikov edited this page Mar 15, 2018 · 2 revisions

AVGContrast

Generates image with calculating average contrast pixels with normalization.

Path

ImageBlendingAlgorithms/IBALib/BlendingAlgorithms/AVGContrast.cs

Essential code

public override Color Calculate(IEnumerable<Color> colors)
{
    var r = 0.5f + (colors.Average(c => c.R) - 0.5f) * 2f;
    if (r < 0) r = 0;
    else if (r > 1f) r = 1f;
    var g = 0.5f + (colors.Average(c => c.G) - 0.5f) * 2f;
    if (g < 0) g = 0;
    else if (g > 1f) g = 1f;
    var _b = 0.5f + (colors.Average(c => c.B) - 0.5f) * 2f;
    if (_b < 0) _b = 0;
    else if (_b > 1f) _b = 1f;
    return new Color(r, g, _b, 1f);
}

example of normalization:

a = 0.75

b = 0.34

c = 0.5 + (0.545 - 0.5) * 2 = 0.5 + 0.09 = 0.59

Examples

the results of handling 3 source images

d22407c1-d820-437d-9980-fec4e21ecdd5


c79778c4-7395-48f8-bf65-e0e33c0bbc31


63a72e6d-bbbc-40ad-b04d-2c4e3a678cd5

Clone this wiki locally