Sub topic 4
Levels: black point, white point, and midtones
This chapter assumes you can create an adjustment layer, open its controls in the Properties panel, and read a histogram at a basic level. It also assumes you know that an 8-bit RGB channel stores values from 0 (black) to 255 (white). Levels is the simplest tool that remaps those values, so it is a good place to learn how tonal adjustments work.
What Levels does
A Levels adjustment layer remaps the brightness of every pixel with a small set of numbers. It has five controls:
- Input black point. Any input value at or below this number becomes pure black.
- Input white point. Any input value at or above this number becomes pure white.
- Midtone (gamma) slider. This bends the values between the two points. It moves the middle without moving the ends.
- Output black point. This lifts the darkest value up from 0.
- Output white point. This lowers the brightest value down from 255.
The Properties panel shows the histogram of the current image above the input sliders. The three input sliders sit under the histogram: black triangle on the left, gray in the middle, white on the right. The two output sliders sit below a gradient bar.
Because Levels is an adjustment layer, none of this changes the pixels underneath. You can reopen the layer and change the numbers at any time.
The math behind the sliders
The function below models the Levels math. It rescales the input between the black and white points, clips it, applies the midtone gamma, and rescales to the output range.
def levels(value, in_black=0, in_white=255, gamma=1.0, out_black=0, out_white=255):
"""Map one 8-bit channel value the way a Levels adjustment does."""
t = (value - in_black) / (in_white - in_black)
t = min(max(t, 0.0), 1.0) # clip below the black point and above the white point
t = t ** (1.0 / gamma) # gamma > 1 brightens midtones, gamma < 1 darkens them
return round(out_black + t * (out_white - out_black))Read it in four steps:
- Subtract the black point and divide by the width of the input range. This turns the input into a number
tfrom 0 to 1. - Clip
tinto the range 0 to 1. This is where shadow and highlight detail is lost. - Raise
tto the power1 / gamma. This is the midtone slider. - Scale
tto the output range.
Try a few values to see the behavior:
print(levels(40, in_black=40)) # 0, at the black point
print(levels(128)) # 128, no change
print(levels(128, gamma=1.5)) # 160, brighter midtones
print(levels(128, gamma=0.7)) # 99, darker midtones
print(levels(10, out_black=20, out_white=235)) # 30, lifted blacks
print(levels(250, in_white=200)) # 255, clipped to whitePhotoshop's gamma field in the Levels panel works the same way. The middle number shows values like 1.00, 1.50, or 0.70. Values above 1.00 brighten midtones, and values below 1.00 darken them.
Setting the black and white points
The most common use of Levels is to stretch an image that does not use the full tonal range. A flat, hazy photo often has a histogram that stops short of both ends. There is empty space on the left, on the right, or on both sides.
To fix this, drag the input black triangle to the point where the histogram starts on the left. Then drag the input white triangle to where it ends on the right. Pixels at those positions now map to 0 and 255. Everything between is spread across the full range, so contrast increases.
# A hazy image whose values run only from 50 to 200.
samples = [50, 90, 125, 160, 200]
stretched = [levels(v, in_black=50, in_white=200) for v in samples]
print(stretched) # [0, 68, 128, 187, 255]The gap between the darkest and lightest sample grows from 150 levels to 255.
Previewing clipping while you drag
Moving a slider past the start of the histogram clips data. Pixels beyond the black point all become 0, and pixels beyond the white point all become 255. Clipped values cannot be recovered by moving the sliders back later, but with an adjustment layer you can undo the whole adjustment. The original pixels are still there.
Photoshop shows clipping if you hold Alt (Windows) or Option (macOS) while dragging the black or white input triangle. The image area turns white or black, and clipped pixels appear in color or as bright spots. Stop dragging just as the first colored pixels appear. This gives you a full-range image with little or no lost detail.
The midtone slider
After you set the black and white points, the gray slider controls how bright the middle of the image looks. Moving it left makes the image brighter. Moving it right makes it darker. The panel shows this as the gamma number, which goes up as you move left.
The slider position and the gamma number move in opposite directions, which confuses many learners. A simple rule: the slider moves toward the side you want to grow. Dragging toward the shadows pulls more of the image into brighter values, and dragging toward the highlights pushes more of it darker.
The midtone slider does not change the black point or the white point. A pixel at 0 stays at 0, and a pixel at 255 stays at 255. Only values in between shift. This is why it is the safe control for brightening a photo that already has good blacks and whites.
| Midtone gamma | Effect on the middle (128) | Visual result |
|---|---|---|
| 0.70 | about 99 | Darker midtones |
| 1.00 | 128 | No change |
| 1.50 | about 160 | Brighter midtones |
| 2.20 | about 186 | Much brighter midtones |
The output sliders
The output sliders compress the range instead of stretching it. Raising the output black to 20 means no pixel can be darker than 20. Lowering the output white to 235 means no pixel can be brighter than 235.
Uses for output sliders are narrower than for input sliders:
- Creating a faded or matte look by lifting the blacks.
- Reducing the maximum brightness so a layer sits more softly over other content.
- Keeping values inside a limit, such as printing limits for very light or very dark areas.
If you want more contrast, leave the output sliders at 0 and 255. Moving them inward reduces contrast.
Levels on individual channels
The Levels panel has a channel menu at the top. It starts on RGB, which is the composite. Switching it to Red, Green, or Blue lets you adjust one channel's histogram on its own.
Adjusting a single channel changes color balance as well as brightness. If you move the midtone slider for the Blue channel toward the shadows, blue increases in the midtones, so the image shifts toward blue. If you move it toward the highlights, blue decreases and the image shifts toward yellow. This is the basis of color cast correction, which a later chapter covers in detail.
# Pull the blue channel's midtones down to remove a blue cast.
r, g, b = 120, 130, 160
corrected = (r, g, levels(b, gamma=0.8))
print(corrected) # (120, 130, 140)Auto, eyedroppers, and presets
The panel offers three shortcuts. Understand what each does before you trust it.
- Auto. Photoshop chooses black and white points for you. The result depends on the Auto options, and it may change color balance as well as contrast. Use it as a starting point and check the result.
- Eyedroppers. The three droppers set the black point, gray point, and white point from a pixel you click in the image. The gray dropper is useful for neutralizing a cast when you can find something that should be neutral gray. Clicking on a pixel that is not truly neutral gives a wrong correction.
- Presets. The preset menu holds saved settings such as Darker or Increase Contrast. They are quick but they do not look at your histogram.
Common errors
- Dragging past the histogram. This clips detail. Use the Alt or Option preview to stop in time.
- Moving the midtone slider before setting the end points. The midtone changes how the ends look. Set black and white first, then adjust the middle.
- Applying Levels once for brightness and again for contrast without a plan. Two Levels layers stacked together compound their clipping. One layer with five good numbers is easier to maintain.
- Using the output sliders to add contrast. They reduce it.
- Judging by the number alone. The gamma value depends on how your image's data is spread. Judge the result by the picture and the histogram, not by a target number.
- Working on a flattened copy. Applying Levels directly through Image > Adjustments writes the change into the pixels. Use a Levels adjustment layer so you can reopen it.
Choosing Levels over other tools
Levels is the right first tool when the main problem is that the image does not use the full range or the midtones are too dark or too light. It has only three control points per channel, so it cannot shape contrast within the shadows or within the highlights separately. For that, use Curves, which the next chapter covers. Curves can do everything Levels does, but Levels is faster and easier to repeat for simple fixes.
Exercise
A photo's histogram has no data below 30 or above 220. You set the input black point to 30 and the input white point to 220, leaving gamma at 1.00 and the outputs at 0 and 255. What 8-bit output value does the pixel at input 125 receive? Use the levels() function from this chapter to check your answer.
Show answer
The value t is (125 - 30) / (220 - 30) = 95 / 190 = 0.5, so the output is round(0.5 * 255) = 128 (127.5 rounds to 128 in Python, which rounds half to even). Running levels(125, inblack=30, inwhite=220) prints 128. The midpoint of the input range lands at the midpoint of the output range, and the image now uses all 256 values.
Exercise
You want a brighter photo without changing its darkest or lightest pixels. Which Levels control do you use, and in which direction do you drag it? What gamma value does the panel show afterward?
Show answer
Use the gray midtone slider and drag it toward the shadows (left). The panel's gamma value rises above 1.00, for example 1.30. Pixels at 0 and 255 do not move, because the midtone slider only bends the values between the two end points.