Instagram Lux effect

拜拜、爱过 提交于 2019-12-02 16:52:56

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!