0

My first question on this forum, please be soft with me :)

I have a bunch of BMP files (created by the script i wrote ) and i would like to change the color level of them. Currently, i open Gimp, i go to "color level" set the input level values from 0~255 to 200~255 , i click "ok" and i get what i want. But i would like to understand what is the algorithm behind that, so that i can code it. I tried to search , i read the Gimp documentation but i did not find enough information. If someone could help, that would be great !

Thanks a lot for you help :)

1 Answers1

1

The first googled ling shows documentation https://docs.gimp.org/en/gimp-tool-levels.html

If you don't need gamma correction (middle slider), use simple linear transformation, where V and NV is old value and new (corrected) value for ever color channel (R, G, B), L and H are Low and High levels.

 NV = Min(255, Max(0, (V - L) * 255 / (H - L)))
MBo
  • 77,366
  • 5
  • 53
  • 86
  • 1
    Thank you for the link, i did find it too... However, the formula you wrote is not part of this documentation , isn't it ? May i ask where you found it ? Thank you ! – kalonkadour Aug 26 '16 at 21:28
  • I make formula from thinking that transformation should transform L value 0, H value to max (255), and it is linear . – MBo Aug 27 '16 at 02:53
  • I just tested your algorithm and it worked. Thanks! Keep in mind that if `H = L` then it will fail due to a divide-by-zero, though. – Sam Nov 12 '18 at 20:20