I am trying write a contrast adjustment for images in gray scale colors but couldn\'t find the right way to do it so far. This is what I came up with:
import nu
You need to apply a mapping curve like this:
It makes the dark tones darker, the light tones lighter, and increases the range of the medium shades.
To achieve that, I'd find the minimum and maximum, then create a lookup table that expands the narrow remaining range into a whole range between 0 and 255. After that, I'd apply the lookup table.
This will certainly leave some blocking, because the ranges of nice gradients of the source were compressed in a lossy way. To fix it, you might consider applying a "smart blur" algorithm that blurs only pixels that have low contrast between them, and does not touch those with high contrast. (I don't see a nice link with a numpy-friendly algorithm, though).