ColorReplace[image,color]
finds regions in image whose pixel values are similar to color and replaces them with transparent pixels.
ColorReplace[image,colorreplacement]
replaces all pixels with the specified replacement color.
ColorReplace[image,colorreplacement,d]
replaces all pixels whose values are within a distance d from color.
ColorReplace[image,{color1replacement1,…},{d1,…}]
does multiple color replacements.
ColorReplace
ColorReplace[image,color]
finds regions in image whose pixel values are similar to color and replaces them with transparent pixels.
ColorReplace[image,colorreplacement]
replaces all pixels with the specified replacement color.
ColorReplace[image,colorreplacement,d]
replaces all pixels whose values are within a distance d from color.
ColorReplace[image,{color1replacement1,…},{d1,…}]
does multiple color replacements.
Details
- ColorReplace works with arbitrary 2D and 3D images.
- ColorReplace[image,color] is equivalent to ColorReplace[image,color,0.1].
Examples
open all close allBasic Examples (2)
Scope (4)
Use a selected color to specify the pixel values to be replaced:
ColorReplace[[image], RGBColor[{223/255, 14/17, 61/85}] -> Red]Use a marker image to specify the pixel values to be replaced:
ColorReplace[[image], [image] -> Red]ColorReplace[[image], [image] -> Red, 0.2]Specify multicolor replacement and a default background:
ColorReplace[[image], {RGBColor[0.7, 0.02, 0.15] -> White, RGBColor[0.4, 0.6, 0.2] -> Gray, _ -> Black}]Replace red pixels in a 3D image:
ColorReplace[[image], Red -> Yellow]Applications (4)
ColorReplace[[image], Green, .25]ColorReplace[[image], Red -> Green, .3]ColorReplace[%, Black -> White]Remove background colors with white:
ColorReplace[[image], {LightYellow -> White, Yellow -> White}, .15]Shuffle colors on a logo by random color replacement:
i = [image];Find dominant colors in the image and generate random replacement:
colors = DominantColors[i]replacements = RandomColor[Length[colors]]ColorReplace[RemoveAlphaChannel[i], Prepend[Thread[Rule[colors, replacements]], White -> White]]Properties & Relations (2)
Replacing pixels of a grayscale image with color values will result in a color image:
ColorReplace[[image], Black -> Red, .2]Use DominantColors to find the dominant green color to be replaced:
image = [image];
g = Nearest[DominantColors[image, 10], Green, DistanceFunction -> ColorDistance]Replace the detected shade of green with transparent:
ColorReplace[image, g]Related Guides
Text
Wolfram Research (2012), ColorReplace, Wolfram Language function, https://reference.wolfram.com/language/ref/ColorReplace.html (updated 2014).
CMS
Wolfram Language. 2012. "ColorReplace." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/ColorReplace.html.
APA
Wolfram Language. (2012). ColorReplace. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ColorReplace.html
BibTeX
@misc{reference.wolfram_2026_colorreplace, author="Wolfram Research", title="{ColorReplace}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/ColorReplace.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_colorreplace, organization={Wolfram Research}, title={ColorReplace}, year={2014}, url={https://reference.wolfram.com/language/ref/ColorReplace.html}, note=[Accessed: 13-June-2026]}