Instagram Lux effect

前端 未结 2 1439
-上瘾入骨i
-上瘾入骨i 2021-01-31 00:45

Instagram added a Lux button recently, which allows auto-contrasting / leveling for the pictures you take.

I have a bunch of pictures that I need to autolevel in a simi

相关标签:
2条回答
  • 2021-01-31 01:10

    A simple linear way of performing "auto-contrast" is to linearly stretch and offset the image intensities.
    The idea is to find the stretch (contrast) and offset (intensity) correction parameters such that in the corrected image the 5th percentile will be mapped to 0, and the 95th percentile will be mapped to 255.

    My example is for a grayscale image. For color images you can convert to any color space that has a single intensity channel and 2 color channels (e.g. Lab, HSV, YUV etc.) and perform this only on the intensity channel.

    1. Create an image histogram
    2. Find the 5th and 95 grey-value percentile (use accumulating sum over the histogram values).
    3. Solve for a and b in these 2 simple linear equations:
      a*p5+b=0 and a*p95+b=255, where p5 and p95 are the 5th and 95 grey-value percentiles respectively.
    4. a is the contrast, and b is the intensity corrections.
    5. Now map all your grey pixel intensities according to the equation: g'=a*g+b for all g=0..255.

    Of course, you might want to use different values for the percentile and the actual mappings. See what works for you.

    0 讨论(0)
  • 2021-01-31 01:24

    For those who haven't solved a linear equation in a very long time (such as I) here the required parameters from Adi Shavit's answer in a formula (in pseudo code) - I renamed p5 and p95 to p1 and p2 (as 5 is just a suggestion):

    p_div := float(p1) / p2;
    b := -255 * p_div / (1 - p_div);
    a := (255 - b) / p2;
    

    I don't know if it can be done easier, but you can check that:

    a * p1 + b  -> 0
    a * p2 + b -> 255
    
    0 讨论(0)
提交回复
热议问题