Sub topic 11
Removing color casts with per-channel Levels and Curves
A color cast is a tint that affects the whole image, such as a blue shift from shade, an orange glow from tungsten bulbs, or a green tinge from fluorescent light. This chapter assumes you can create a Levels or Curves adjustment layer, read the Properties panel, and read a histogram. Earlier chapters covered all three. Here you apply them one color channel at a time.
Why a cast is a channel problem
An RGB image stores three grayscale channels: Red, Green, and Blue. A pixel looks neutral gray when its three values are equal. A cast means the channels have drifted apart. A gray wall might read R=110, G=128, B=140, which looks bluish.
The composite RGB control in Levels or Curves moves all three channels together, so it can't fix this. It changes brightness and contrast but keeps the imbalance. To remove a cast, switch the channel dropdown in the Properties panel from RGB to Red, Green, or Blue. Then correct each channel separately.
Each channel has an opposite color. Moving a channel's curve or midtone slider toward that opposite removes the matching tint.
| To reduce this tint | Lower this channel | Or raise this channel |
|---|---|---|
| Blue | Blue | Red and Green together (adds yellow) |
| Yellow | Red and Green together | Blue |
| Red | Red | Green and Blue together (adds cyan) |
| Cyan | Green and Blue together | Red |
| Green | Green | Red and Blue together (adds magenta) |
| Magenta | Red and Blue together | Green |
In practice you usually move only one or two channels. Keep the fewest, smallest moves that make neutral things look neutral.
Finding something that should be neutral
Every cast correction starts with a reference: an area that should be gray, white, or black. Good candidates are a gray card, white paper, a concrete wall, an overcast sky's cloud edges, or the white of an eye. Colored surfaces are bad references, because their color is real and you would remove it.
Measure the reference before changing anything:
- Open the Info panel (Window > Info).
- Choose the Eyedropper tool and set Sample Size to 5 by 5 Average in the options bar. A single pixel includes noise, and the average is steadier.
- Hover over the reference area and read the R, G, and B values.
The channel with the largest or smallest value tells you the direction of the cast. In the example above, blue is high and red is low.
Method 1: per-channel Levels
Levels has two jobs in a cast fix, and each channel has its own histogram.
Match the black and white points
Switch to one channel and look at its histogram. In an image with a cast, the three channel histograms often start and end at different places. For example, blue may reach the right edge, but red may stop well short of it. Dragging the white-point slider for the red channel in to where the data ends stretches red to fill the range. That raises red in the highlights and removes the blue-cyan tint there. Do the same for the black point.
Hold Alt (Windows) or Option (Mac) while dragging a black or white slider. The image shows which pixels clip in that channel. Stop just as the first few pixels appear, or you will lose detail.
This approach assumes the scene really has a pure white and a pure black. A sunset has neither, and stretching each channel to its edges will flatten its warm color. Photoshop's own "Auto Color" option has the same weakness.
Match the midtones
Highlights and shadows can be right while the midtones are still tinted. The middle slider, the gamma, fixes this for one channel without touching its endpoints. Moving it left brightens that channel's midtones, and moving it right darkens them.
You can calculate the correction from a measured gray. The function below computes the gamma that moves a sampled channel value onto a target value. It also applies the Levels formula from the earlier Levels chapter.
import math
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)
t = t ** (1.0 / gamma)
return round(out_black + t * (out_white - out_black))
def neutralizing_gamma(sampled, target):
"""Gamma that maps `sampled` to `target` (both strictly between 0 and 255)."""
return math.log(sampled / 255) / math.log(target / 255)
sample = {"R": 110, "G": 128, "B": 140} # a gray wall with a blue cast
target = round(sum(sample.values()) / 3) # keep overall brightness: 126
for channel, value in sample.items():
g = neutralizing_gamma(value, target)
print(channel, round(g, 3), "->", levels(value, gamma=g))This prints gamma values of about 1.193 for red, 0.978 for green, and 0.851 for blue. Each channel maps to 126. Red gets a midtone value above 1, which brightens it. Blue gets one below 1, which darkens it. Green barely changes.
In Photoshop you type these numbers into the middle field of Levels while the matching channel is selected. In the real application the gamma applies to the whole channel, not just the gray you measured. Other tones shift by smaller amounts, and that is usually what you want.
Method 2: the gray-point eyedropper
Levels and Curves both have three eyedroppers in the Properties panel: black point, gray point, and white point. The middle one is the fastest cast fix. Select it and click the reference area. Photoshop shifts the channels so the clicked pixel becomes neutral gray.
Two cautions apply:
- The eyedropper uses its own sample size setting, so check it before clicking.
- A single click can overcorrect if the pixel you chose was slightly colored. Click a different spot and compare, or reduce the layer's opacity.
Because the work happens on an adjustment layer, nothing is permanent. You can delete the layer and try again.
Method 3: per-channel Curves
Curves does the same job with more control, because you can bend part of a channel's range instead of the whole thing. A cast often differs between shadows and highlights. A common example is warm highlights from a lamp and cool shadows from a window.
Pick a channel and drag a point on its curve:
- Pull a point up to add that channel's color, or down to add its opposite.
- Anchor the other end with a second point so the shadows stay fixed while you correct the highlights, or the reverse.
- Ctrl+click (Windows) or Cmd+click (Mac) a spot in the image to place a point on the current channel curve at that pixel's value. This lets you tie a correction to a specific tone you can see.
The next function shows what an adjustment on one channel does. It reuses the straight-segment curve idea, but applies a different curve to each channel.
def curve(value, points):
"""Look up an 8-bit value on a curve defined by (input, output) control points."""
pts = sorted(points)
for (x0, y0), (x1, y1) in zip(pts, pts[1:]):
if x0 <= value <= x1:
return y0 + (y1 - y0) * (value - x0) / (x1 - x0)
raise ValueError("value is outside the curve's input range")
# Warm highlights, neutral shadows: pull blue up and red down in the bright half only.
red_curve = [(0, 0), (128, 128), (255, 240)]
blue_curve = [(0, 0), (128, 128), (255, 255)]
blue_curve_fix = [(0, 0), (128, 128), (255, 255)]
highlight = {"R": 250, "G": 235, "B": 205} # a warm-tinted highlight
fixed = {
"R": curve(highlight["R"], red_curve),
"G": highlight["G"],
"B": highlight["B"],
}
print({k: round(v) for k, v in fixed.items()})The red curve ends at 240 instead of 255, so red 250 becomes about 236, close to the green value of 235. Blue stays low at 205, so the highlight is still yellowish. To fix that you would raise blue's top point too. Cast correction usually takes a few rounds of this kind of adjustment, and judging it by eye matters as much as the numbers.
A repeatable procedure
Use these steps in order:
- Add one Levels or Curves adjustment layer above the image. Keep it separate from your contrast adjustments so you can switch it off and compare.
- Try the gray-point eyedropper on a reliable neutral.
- If the highlights and shadows are still tinted, set per-channel black and white points in Levels.
- If the midtones are still tinted, change the channel gamma, or add a point on that channel's curve.
- Toggle the layer's eye icon to compare before and after. Your eyes adapt quickly to a tint, so check after a short rest.
- Review something with a known color, such as skin or sky. If it looks wrong, lower the layer's opacity.
Common errors
- Correcting in the composite RGB view only. It can't change the balance between channels, so the cast stays.
- Picking a colored surface as the gray. The correction will shift everything else the wrong way. Verify the choice with a second reference.
- Pushing black and white points to the channel edges every time. Scenes without true white or black end up with distorted color. Stop at the clipping warning or earlier.
- Moving one channel a long way. A large move in one channel usually means the better fix is a smaller move in the other two in the opposite direction.
- Doing the fix after contrast work. A steep S-curve exaggerates a cast and makes the neutral reference harder to read. Place the cast correction below contrast layers in the stack.
Exercise
A white shirt measures R=235, G=228, B=205 in the Info panel. Which color is the cast, which channel would you adjust first in Levels, and in which direction should its midtone slider move?
Show answer
The cast is yellow, because blue is the lowest channel. Select the Blue channel in Levels and move its midtone slider to the left, which raises the blue midtones (gamma above 1). You could instead lower red and green slightly, but one blue move is simpler. Then sample the shirt again and check that the three values are closer together.
Exercise
Using the formula in this chapter, what gamma would you enter for a channel whose gray sample reads 100 when the target is 128? Is the channel brightened or darkened?
Show answer
Gamma = ln(100/255) / ln(128/255), which is about -0.936 / -0.689, or roughly 1.36. A gamma above 1 brightens the midtones, so the channel is brightened and 100 maps to 128.