image-processingcontrastmath-functions

Which sigmoid function to use for increasing contrast of an image?


Is there a standard sigmoidal function used to increase the contrast in a gray level bitmap?

Currently I am using the following. This would be applied to gray levels represented at values between 0 and 1 inclusive.

static double ContrastCurve(double val, double k = 1)
{
    Func<double,double> logistic_func = (double x) => 1.0 / (1.0 + Math.Exp(-k * (x - 0.5)));
    var low = logistic_func(0);
    var high = logistic_func(1);
    var range = high - low;
    var value = logistic_func(val);
    return (value - low) / range;
}

This is the logistic function applied to a value between 0 and 1 with the output normalized so that the output is also in [0...1]. This function works but it is completely arbitrary, something I just made up, so the k param has no official name or meaning in image processing literature and so forth.

If there is a function that is standard I would prefer that but haven't found anything that seems definitive. Code such as this link seems as ad hoc to me.


Solution

  • As Mark Setchell's comment notes, ImageMagick uses the following function citing "Fundamentals of Image Processing", Hany Farid:

    g(u) = 1 / [1 + exp(-α*u + β)]
    

    scaled such that for domain [0..1] its range is [0..1].

    This is essentially a two parameter version of the function defined in the code in the question above i.e. the code in the question implements the same function but makes the substitution α = k and β = -k/2 which yields a one parameter function f where f(0.5) = 0.5 when scaled such that f(0) = 0 and f(1) = 1.