Adjusting contrast of image purely with numpy

后端 未结 3 1903
庸人自扰
庸人自扰 2021-01-22 20:30

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         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-22 21:27

    You need to apply a mapping curve like this:

    contrast

    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).

提交回复
热议问题