Bug 397391

Summary: Unusual Output from Levels Filter in Krita
Product: [Applications] krita Reporter: Jeremy Hollobon <jem.hollobon>
Component: FiltersAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: minor CC: halla
Priority: NOR    
Version First Reported In: 4.1.0   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Jeremy Hollobon 2018-08-12 00:50:39 UTC
The Levels filter in Krita doesn't conform with the expected behaviour of such a filter. Whereas other applications apply the filter in HSV space, Krita uses LAB space, which produces a poor result.

To reproduce:
1. Start with an ordinary 8-bit RGB image, containing colour information, like this:
https://nofile.io/f/wtOOsvPgU09/moonlit+blue+sky_sm.png

2. Apply a Levels filter, and set the minimum input slider to 127, like this:
https://nofile.io/f/OhGtyS7QvY0/levels_dialog_adjusted.png

3. One would expect all pixels with a Value of 127 or less to be clipped to black. And pixels with a Value from 128-255 should be re-mapped to the specified output range (in this case, 0-255).
So the result should look like this:

https://nofile.io/f/O7Yee3qgMD9/levels_test_correctResult.png

And that's the result I get from the Levels filter in every other image manipulation software I've tried, including Gimp, Inkscape, Photoshop, Affinity Photo, and even compositors such as Fusion.

But Krita's output is the odd one out. None of the dark areas have been clipped, and all the details in the bottom half of the image are still visible:

https://nofile.io/f/s2MWUd6fFwV/levels_test_incorrectResult.png

In the relevant forum thread (https://forum.kde.org/viewtopic.php?f=137&t=153522&sid=f98ff5a4bfd173434daa7574efba1eb0&p=402380#p402377), Krita developer boudewijn comments:

"I do see that gimp 2.8 and Krita 4.1.1 do something different, and I suspect that's because Krita converts the image to LAB and modifies the L channel, and Gimp to HSV and modifies the Value channel."
Comment 1 Jeremy Hollobon 2019-01-06 07:20:12 UTC
Somewhere along the line (probably Krita 4.1.1) this got fixed. As far as I can tell, it now works as expected. Big thanks to the devs for their great work.