Replace Color in Image
Operator: Abdulla Al Fahad. How tools are built and checked
Changing one colour in a photograph sounds simple until you try it. A red jacket is not one red; it is dozens of reds, from the bright fold to the deep shadow under the arm, and a fill that matches only one of them leaves a speckled mess. A good replacement has to select a range of shades, hand over from selected to unselected smoothly, and then recolour in a way that keeps the light and dark of the original.
This tool does that in three steps you can see: pick colours with the eyedropper, check the selection as a black and white mask, then choose a replacement. For clearing a plain near-white background alone, the remove white background tool is quicker.
Key features
- Up to eight eyedropper picks, each averaged over 3 by 3 pixels
- Selection by CIELAB distance with a smooth soft edge
- Recolour by hue rotation with shading kept, or fade to transparent
- Optional lightness match to the new colour
- PNG or JPG download at up to 4096 pixels
Selecting a colour range in CIELAB
While you work, the page uses a copy of up to 1200 pixels so the sliders stay quick; the download is made from the picture held at up to 4096 pixels, so the saved image keeps its own detail (a GIF gives its first frame).
Click anywhere on the preview to pick a colour. The pick is the average of the 3 by 3 pixels around the click, which stops a single noisy pixel from being chosen, and transparent pixels are ignored. You can add up to eight picks; each appears as a swatch with its hex code and a remove button. The picks are cleared when you load a different image.
Tolerance runs from 1 to 60 and is a colour distance in CIELAB, the colour space designed so equal distances look about equally different. The measure used is CIE76, the plain straight-line distance. A value of about 2 is the smallest difference most people can see, and 20 takes in the nearby tints and shades of a colour. Softness, from 0 to 40, is an extra band beyond the tolerance over which the selection fades from fully selected to untouched.
The replacement is either a new colour or transparency. For a new colour you can choose how far to match its lightness, from 0 percent, which keeps every highlight and shadow, to 100 percent, which moves the object's brightness all the way to the new colour's. PNG keeps transparency; JPG fills it with white. The Mask view shows the selection as white, grey for the soft edge and black for untouched pixels.
How it works
Every pixel is converted once to CIELAB, and that is stored so moving a slider only repeats the distance sums. For each pixel the tool finds the nearest picked colour by distance. If the distance is within the tolerance the pixel is fully selected; between the tolerance and tolerance plus softness the weight falls from 1 to 0 along a smoothstep curve, 1 - t squared times (3 - 2t), which has no visible edge where it starts or ends.
To recolour, the pixel is expressed as lightness, chroma and hue. The hue is turned by the angle between the nearest pick and the new colour, and the chroma is scaled by the ratio of the new colour's chroma to the pick's. Lightness stays as it was unless you raised the match slider, in which case it moves that fraction of the way by the difference between the new colour and the pick. The result is converted back to sRGB, clipped to the displayable range and blended with the original by the selection weight.
A pick that is almost grey, with chroma under 8, has no hue to turn, so selected pixels take the new colour's hue directly with chroma scaled by how coloured they were. In transparent mode, the pixel's opacity is multiplied by one minus the weight, so soft edges stay soft.
Common use cases
- Showing a product in several colourways without reshooting it
- Recolouring a logo that exists only as a flat PNG
- Making a solid-colour screenshot background transparent
- Fixing an off-colour object, such as a wall painted the wrong shade in a render
How to use this tool
- Click the colour you want to change in the preview. Add more picks on the darker and lighter parts of the same object.
- Switch to Mask and adjust tolerance and softness until the object is white and the rest black.
- Choose a new colour, or Transparent, and look at the Result view.
- Pick PNG or JPG and download the full-size image.
Example
A red ball turned blue; pick (220, 30, 30), new colour #1e3cdc, tolerance 25, softness 15
pixel A (220, 30, 30) bright red
pixel B (150, 20, 20) shaded red
pixel C (255, 120, 120) pale highlight
pixel D (30, 200, 30) green leafMask weight and result
A weight 1.00 -> (86, 88, 255)
B weight 0.94 -> (60, 58, 165) darker blue, shading kept
C weight 0.17 -> (234, 126, 142) barely moved from (255, 120, 120)
D weight 0.00 -> (30, 200, 30) untouchedTips for best results
- Pick two or three shades of the object: a mid-tone, one in shadow and one in light. The selection grows to cover all of them without taking in distant colours.
- Start with softness near 10 and a tolerance of 15 to 25. Hard edges (softness 0) suit flat graphics; photos need the fade.
- Use the mask view while adjusting. A grey speckle on the background is a sign that tolerance is too high.
- To change a colour to something much lighter or darker, raise the lightness match, otherwise a dark red object becomes a very dark new colour.
- For a grey or white object, pick it and choose a saturated target. The result is a tinted version with the original shading.
Common pitfalls
Picked colours that look alike but sit far apart in CIELAB are treated as different; add a pick for each shade you want.
Objects behind coloured light, or with a similar colour in the background, will select both. Lower the tolerance or select one shade at a time.
JPEG compression noise around edges can leave a faint halo of the old colour. A softness of 10 to 15 usually hides it.
Colours outside the displayable range are clipped after recolouring, so a very saturated target on a very light pixel can look flatter than the swatch.
The tool replaces colours; it does not detect objects. Two things of the same colour change together.
Common errors and how to fix them
- Nothing changes in the result
- No colour is picked yet, or the tolerance is too small. Click the picture, then check the Mask view for white areas.
- The wrong areas change as well
- Lower the tolerance, or remove the pick that is close to the unwanted colour. The mask shows what is selected.
Best practices
- Keep the picks list short. Four well-chosen shades beat eight overlapping ones.
- Save as PNG if you will recolour again, since JPG adds more compression noise.
Frequently asked questions
Why CIELAB distance instead of RGB?
Equal steps in RGB do not look equal; two blues 30 apart can look identical while two greens 30 apart look different. CIELAB distances track what you see, so one tolerance value behaves similarly across colours.
Does recolouring keep shadows and highlights?
Yes. The hue is rotated and the chroma is scaled, but lightness is left alone unless you raise the lightness match.