How to Use the Levels Filter in Krita

Share
In this tutorial, we'll learn how to use the "Levels" filter in Krita (version 5.2), which we can use to adjust the brightness and contrast of an image and to quickly change the blackest and whitest part of an image, and even to manipulate alpha, saturation, and hue values..

The levels filter is a simpler version of the color adjustment filter (also called "curves" in some applications). Everything you can do with levels you can do with curves.

Note: this tutorial assumes you are using a RGB image with 8 bits per pixel, so values are from 0 to 255.

A screenshot of krita levels filter settings as shown in the new filter mask dialog.
A screenshot of Krita's "Levels" filter settings as shown in the new filter mask dialog.

How to Add

The "Levels" filter is found in Filter -> Adjust -> Levels on the menubar. It's recommended to use a filter layer or filter mask instead, to work non-destructively.

Note: in most applications, this filter features a histogram to use it. The histogram is available in Krita as well, however, it isn't available for filter layers for some reason. I'm not sure if this is a bug or a limitation. You can still access the histogram non-destructively by using a filter mask instead of a filter layer, because the filter mask only applies to one layer or group. In particular, if you want to combine the levels filter with another filter layer, e.g. "desaturate," you should add the filter mask to the filter layer, so you would have a "desaturate" filter layer with a "levels" filter mask attached to it, for example.

Settings

The "Levels" filter settings features a histogram showing the distribution of lightness in our image. The left side of the histogram shows darker pixels, while the right side shows lighter pixels. If the histogram shows that there are only pixels in the middle, that means the image is only shades of gray, and has no fully black or fully white pixels in it.

Input Controls: below the histogram, we will find a bar with 3 control points, one at the left, on at the middle, and one at the right. They look like upward arrows. These control the "Input Levels." The leftmost control point sets the minimum input. The rightmost control sets the maximum input. And the middle point control controls the gamma value.

Increasing Contrast: if we drag the minimum input to the right, we make all pixels darker than the minimum input fully black. Similarly, if we drag the maximum input to the left, we make all pixels brighter than it fully white. Since the histogram shows the distribution of lightness in our image, we can use it to make the darkest pixel we have fully black, and the lightest pixel we have fully white simply by moving the control points according to the edges of the data displayed in the histogram. Doing this will increase the contrast of the image, because it makes the darkest and lightest pixels of the image more far apart, and the brightness of the gray pixels between them will stretch linearly accordingly.

Adjusting Brightness: by default, the gamma of the levels filter is 1.0, which makes the gray pixels stretch from black to white linearly. If we move the middle point to one side or another, this changes the gamma, which changes how bright or dark the gray pixels in the middle become without affecting the color of the fully black and white pixels.

Clamping Input: if we make the minimum and maximum input less than the minimum and maximum in the histogram, we will lose some image data because those values will become clamped. For example, if we had an area that slowly faded to dark, increasing the minimum too much will make the whole area fully black, and we lose the data about the fading. Data loss isn't always a bad thing. Losing data can increase the quality of an image if we remove data that isn't useful to begin with (i.e. if we increase the noise to signal ratio). For example, if we take a photo of a black pencil drawing on a white paper, ideally we would want the drawing to be fully black and the background to be fully white, but what actually happens in practice is that the paper will have a "gradient" effect due to varying levels of light reflected across its surface, while the graphite (or even ink) won't look perfectly black either. It's also likely that this photo will be in color, instead of in black and white. We can discard the color data with a desaturate filter, and then discard the gradient on the paper by clamping the maximum lightness input to the darkest "white" pixel on the paper. This will make all pixels on the paper that appear white become fully white. We do the same to the pencil by setting the minimum input to the lightest pencil color. Often these extremes don't actually look very good, so we adjust as needed, but the idea remains the same.

Output Controls: under the input levels, you'll find a similar set of controls labelled "Output Levels." This set has no gamma mid-point. The left and right control points change the color of what would be the black and white pixel, respectively.

Reducing Contrast: if you change the output levels so that black is lighter than black or white is darker than white, the contrast of the image will be reduced.

Clamping Output: in some cases, levels can be used to clamp the output to certain values. This isn't very useful when dealing with photography, but it may be useful when dealing with effects and game development. For example, if we move the maximum output from 255 to 127, that will make the maximum value half of what it normally is. If we had two layers clamped at a maximum of 127, we can safely "add" their values to get a value from 0 to 254. We can even do this in Krita by using the "Addition" layer blend mode. Similarly, if, instead, we made the minimum value 128, so the values range from 128 to 255, and we used the "Multiply" blend mode, then if a pixel was black before, and it would multiply by 0, which always equals 0 (black), now it's going to be 50% gray, which means pixels are multiplied by 0.5 instead. Note that in both cases we could just use the opacity setting of the layer instead.

Banding: if we use levels to increase the contrast of the image, we will inevitably get a "banding" effect because the values are spread out. If you take a look at the Histogram docker after applying the filter, you'll notice there will be various "spikes" in the histogram with gaps between them. To understand what is happening, imagine we had the value 40, 50, 60, and 70, and, using a simple math formula, we stretched 40 to 0, and 70 to 100, what would happen to the values 50 and 60 if they stretch proportionally? One is going to be pulled to one side, while the other is going to be pulled to the other side, leaving a greater gap between them. One way to solve this would be to blur the image somehow, but doing that is going to be blur the image, which will create a different problem.

Levels on Hue, Saturation, Channels, and Alpha: by default, Krita's levels filter only applies to lightness. It's possible to make it apply to hue, saturation, or color channels (red, green, blue, and alpha (transparency)). On the top-left corner of the settings, you'll find two buttons with circles in them, one is light gray, the other has three colors. If you click the colored circle, a dropdown list button will appear, where you can select what the the settings apply to. Note that if you do this, and you edit the red channel, for example, and then switch to the blue channel, your changes to the red channel do not disappear or reset. You can edit all of them at once, and they will all apply together. To reset the settings.

Reset: to reset the settings, click on the button on the top-right corner that looks like a circle with two arrows along it.

Histogram Settings: on top of the input controls, there are a few buttons that change how the histogram is displayed. One of them will make the histogram use logarithmic scale, which makes it easier to tell where the darkest and brightest pixels are.

Auto Levels: on the top-right, next to the reset button, you can find a button that opens a dialog to automatically configure the levels filter based on a set of parameters, such as shadows, highlights, and midtones color. I'm not sure how useful this is since it seems easier and faster to just adjust them manually. Perhaps it's more suited if you're scripting Krita to modify images in bulk?

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *