Sub topic 11
Removing color fringing with Decontaminate Colors
This chapter assumes you can open the Select and Mask workspace, you know what a layer mask does (white reveals, black hides), and you have already refined a hair edge with Edge Detection and the Refine Edge Brush. Here you will learn why edge pixels pick up the old background color, what Decontaminate Colors does about it, and what it costs you.
Why edges carry the old background
A hair strand is thinner than a pixel. The camera sensor records each pixel as a blend of the strand and whatever is behind it. A pixel on the edge of a dark head of hair against a bright sky is partly dark hair and partly bright sky.
Selection refinement fixes the opacity of that pixel, which is how much of it should show. It does not change the pixel's color. When you place the cutout on a new background, the pixel keeps its sky-colored share. The result is a visible halo or fringe: a light rim around dark hair, or a green rim if the original background was grass.
This is called color contamination. It is a different problem from a bad mask:
| Symptom | Cause | Fixed by |
|---|---|---|
| Strands missing or chopped off | Mask opacity is too low or the edge is too hard | Radius, Refine Edge Brush, Refine Hair |
| Solid rim of old background | Mask edge sits too far outside the subject | Shift Edge, Contrast |
| Soft, semi-transparent rim in the old background's color | Edge pixels contain mixed color | Decontaminate Colors |
Check the table before you reach for the checkbox. If the rim is solid and wide, Decontaminate Colors will not fix it.
What Decontaminate Colors does
Decontaminate Colors is a checkbox in the Output Settings section of the Properties panel in Select and Mask. When you turn it on, Photoshop looks at the partially transparent pixels along the edge. It replaces their colors with colors taken from nearby fully opaque pixels inside the subject. The opacity from your mask stays the same, but the color of each edge pixel now comes from the subject instead of from the background.
The panel also has an Amount slider, from 0% to 100%. It controls how strongly the edge colors are replaced:
- At a low amount, edge colors change only slightly and some fringe remains.
- At 100%, edge pixels take their color entirely from the interior, which removes the most fringe.
- Intermediate values give a blend, which helps when full decontamination looks flat or slightly wrong.
Decontaminate Colors only affects pixels that are partially transparent. A hard-edged selection has no such pixels, so there is nothing to decontaminate. This is why the feature matters most after Edge Detection and the Refine Edge Brush, which create the soft strand pixels in the first place.
Turning it on
- Finish your edge work first. Refine the radius, paint the strands, and apply your global refinements.
- In the Properties panel, scroll to Output Settings.
- Check Decontaminate Colors.
- Drag Amount to 100% as a starting point.
- Set Output To to New Layer with Layer Mask.
- Zoom to 200% or more and compare the edge before and after by toggling the checkbox.
Do the comparison on a view mode that exposes the problem. On White or On Black, a fringe of the opposite color is obvious. On Layers, with a contrasting background layer underneath, you see exactly what the final composite will show.
The next diagram shows where the step sits in the overall flow.
What happens to your document
Because Decontaminate Colors changes pixel colors, the result cannot be stored as a mask alone. Photoshop writes a new layer. That layer contains a copy of your image with the decontaminated edge colors baked in, plus a layer mask holding the opacity.
This has three consequences:
- The original layer stays untouched. The new layer sits above it, so you can hide or delete the new layer and start again.
- The decontaminated pixels are permanent on the new layer. You cannot change the Amount later without redoing the operation. If you want to try another Amount, delete the new layer and reopen Select and Mask from the original layer.
- File size grows. You now have two full-resolution copies of the subject. In a large file with many layers, this adds up.
The mask on the new layer is still editable. You can paint on it with a brush to restore a lost strand or hide a stray patch. Only the color work is fixed in place.
When it works well, and when it does not
Decontaminate Colors works best when three conditions hold:
- The background color is different from the subject's colors.
- The subject has a solid interior near the edge, so there is good color to copy.
- The fringe is only in the semi-transparent pixels.
It struggles in these cases:
- Backlit hair. Light passes through the strands, so the color of the strand itself includes the bright background. Replacing it with interior color can make the hair look darker and heavier than in the photo.
- Fine, sparse strands in open space. Where there is no solid hair nearby to copy from, the algorithm samples from farther away and the color may look wrong.
- Colorful reflections. If the old background reflected onto the subject, such as green light bouncing off grass, the interior color already contains that tint. Decontaminate Colors cannot know the tint is wrong.
- Large, low-opacity areas. Heavy feathering makes a wide band of partial pixels, and replacing color across that whole band can leave smeared patches.
Two habits reduce these problems. Keep the soft edge band narrow by using a modest Radius and little Feather. And set Amount to a value below 100% when full strength looks flat.
A worked example
Suppose you have a portrait of a person with dark brown hair against a pale blue sky. You have a decent mask, but when you drop the cutout onto a dark green background you see a thin bluish glow around the hair.
- Select the original photo layer and open Select and Mask.
- Set View to On Black. The bluish rim shows clearly against the dark background.
- Check Decontaminate Colors and set Amount to 100%.
- The rim shrinks but the hair looks slightly flat and uniform. Lower Amount to about 70%.
- Set Output To to New Layer with Layer Mask and click OK.
- Place a dark green fill layer below the new layer. The blue glow is gone and the strands keep their natural variation.
If a thin rim remains, do not push Amount higher. Check whether the mask edge is too wide. A small negative Shift Edge value, such as −5%, pulls the mask inward and removes the outer layer of mixed pixels. Reapply the output afterward, because decontamination is computed from the mask at the time you click OK.
Manual alternatives
When automatic decontamination fails, you can fix the color yourself, on the new layer rather than on the original.
- Clone or brush with Color blend mode. Create an empty layer clipped to the cutout, set its blend mode to Color, and paint over the fringe with a color sampled from nearby hair. Use a soft brush at low opacity. Because it is a separate layer, you can delete it if it looks wrong.
- Lock transparency and paint. On the decontaminated layer, lock transparent pixels and paint hair color along the edge. This changes only pixels that already exist, so it will not alter the mask.
- Lower the mask edge. Paint black on the layer mask with a very low-opacity soft brush to trim the outermost contaminated pixels.
Prefer the clipped Color layer. It leaves the decontaminated pixels intact and keeps your repair reversible.
Checking your result
Decontamination always has to be judged on the background it will really sit on. Test it on at least three: a light one, a dark one, and one that is close to the original background color. A fringe that vanishes on the first two may reappear against a color similar to the old sky or wall. The next chapter's workflow of output settings and layer masks covers how to keep these test backgrounds as separate layers so you can swap them quickly.
Exercise
You turn on Decontaminate Colors, and the Output To menu no longer offers Selection or Layer Mask. Why, and what should you choose instead?
Show answer
Decontaminate Colors rewrites the colors of edge pixels, and a selection or a mask cannot store color. Photoshop therefore requires an output that creates new pixels. Choose New Layer with Layer Mask, which keeps the original layer intact and keeps the opacity editable.
Exercise
After decontamination, a thick, solid light-colored rim still surrounds the hair on a dark background. Is raising Amount the right fix? What should you try?
Show answer
No. A thick, solid rim means the mask edge extends too far into the old background, and Decontaminate Colors only recolors the pixels that are already there. Reduce the mask with a small negative Shift Edge value or a little more Contrast, then reapply the output with Decontaminate Colors on.
Exercise
The hair in a backlit portrait looks darker and heavier after Decontaminate Colors at 100%. Name one setting change and one non-destructive repair you could try.
Show answer
Lower Amount, for example to 60 to 70%, so edge colors blend the original and interior colors. Alternatively, keep the 100% result and paint over the dark areas with a soft brush on a clipped layer set to the Color blend mode, sampling lighter hair colors.