Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram Lux effect

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 similar manner, making those pics better looking. If I would want to use a batch command with Imagemagick, what would be the "secret ingredients" to use? Should I just stick to the contrast setting, or play around with levels, etc.?

As I do not know if the original picture will be dark, bright, already contrasted, I will need to analyse the pic before processing it.

Therefore 2 questions:

  1. What are the settings I should look at in creating my batch command for Imagemagick that will consistently output better looking pics?

  2. Does it make sense to run the batch and revert the "false positives" by hand later (I have around 50,000 pics to process)?

like image 745
0-alpha Avatar asked Mar 16 '12 20:03

0-alpha


1 Answers

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.

like image 51
Adi Shavit Avatar answered Oct 31 '22 15:10

Adi Shavit