ColorConvert

ColorConvert[color,colspace]

converts the color space of a color to the specified color space colspace.

ColorConvert[image,colspace]

converts the color space of image.

ColorConvert[{expr1,},colspace]

converts the color space of a list of colors and images.

Details

  • ColorConvert is typically used to change the color specification of an image. Color spaces are used for different purposes, e.g. CMYK is typically used in printing and Lab is used for color comparison.
  • ColorConvert works with colors and arbitrary 2D and 3D images, as well as an explicit list of color channel values.
  • ColorConvert[list,colspace] by default interprets list as follows:
  • {v}gray level
    {v,α}gray level and alpha parameter
    {r,g,b}red, green, blue levels
    {r,g,b,α}RGB with alpha parameter
  • Supported color spaces colspace include:
  • "Grayscale"gray level (GrayLevel)
    "RGB"red, green, blue (RGBColor)
    "CMYK"cyan, magenta, yellow, black (CMYKColor)
    "HSB"hue, saturation, brightness (Hue)
    "XYZ"CIE XYZ (XYZColor)
    "LAB"CIE (LABColor)
    "LCH"CIE (LCHColor)
    "LUV"CIE (LUVColor)
    ColorProfileData[][i]color profile with the specified rendering intent i
  • When converting to or from "Grayscale", "RGB", "CMYK", and "HSB", channel values are clipped to be between 0 and 1.
  • When converting to and from "XYZ", "LAB", "LUV", and "LCH", channel values are not clipped and when applied to images will result in an image of a real type.
  • ColorConvert automatically performs chromatic (white point) adaptation. D50 white point is assumed for "XYZ", "LAB", "LUV", and "LCH" and D65 for "RGB", "CMYK", "HSB", and "Grayscale".
  • When converting to and from "RGB", the channel values are assumed to be in the sRGB color space.
  • "RGB", "CMYK", "HSB" and "Grayscale" assume a D65 white point. "XYZ", "LAB", "LUV" and "LCH" assume a D50 white point, which can be changed using the WhitePoint option.
  • The WhitePoint specifies the white point for chromatic adaptation when converting between RGB and XYZ and the white reference when converting between XYZ and Lab or Luv.
  • ColorConvert[input,src->dst] can be used to convert to the color space specified by dst, while interpreting channel values in input according to the color space src. Both src and dst can be either a known color space or a color profile.
  • ColorConvert[image,colspace] is equivalent to ColorConvert[image,ImageColorSpace[image]->colspace].
  • Color space specified by src should be compatible with the number of channels in image.
  • If dst is a color profile, one of the device or connection spaces should match the color space of the input or a specified source color space src.

Examples

open allclose all

Basic Examples  (3)

Convert a color photo to grayscale:

Convert to CMYK:

This shows that the previous output is a CMYK image:

Convert an RGB color object to CMYK:

Scope  (9)

Convert an intensity value to grayscale:

Convert an intensity value to RGB:

Convert out-of-range values:

Convert RGB intensity values to CMYK:

Convert a color to another color space:

Convert a list of colors:

Convert a grayscale image to RGB:

Convert from a known color space to Lab:

Specify the color space for the image with an unknown color space and convert to RGB:

Convert a list of images:

Use a color profile to convert to the sRGB version 4 color space:

Specify device profiles for both source and destination:

Specify the rendering intent:

Convert a 3D image to LCh:

Options  (2)

WhitePoint  (2)

The default white point when converting to a CIE color space is D50:

Specify a different white:

Use an explicit XYZColor:

When converting from a white color to XYZ, the result matches the reference white given:

This is true for LAB and LUV models as well:

Applications  (2)

Convert an image to its "LAB" representation and perform custom color negations:

Convert an image to the "LCH" color model to perform specific chroma and hue transformations:

Segment out the three strawberries in the image:

Transform the colors in each image segment and combine the results:

Properties & Relations  (3)

ColorConvert automatically performs a chromatic adaptation when using color directives:

ChromaticityPlot3D can visualize the difference between adapted and unadapted representation:

When the destination is specified with a ColorProfileData, the result is in the device color space:

The grayscale representation of an RGB color is equivalent to the luma in the Y'CbCr color model:

Possible Issues  (1)

Conversion using a color profile may result in an approximate color representation:

In such cases converting back to the original color space gives a different color:

This difference may become significant after several conversion steps:

Built-in conversions between RGB and CMYK preserve the color:

Wolfram Research (2008), ColorConvert, Wolfram Language function, https://reference.wolfram.com/language/ref/ColorConvert.html (updated 2021).

Text

Wolfram Research (2008), ColorConvert, Wolfram Language function, https://reference.wolfram.com/language/ref/ColorConvert.html (updated 2021).

CMS

Wolfram Language. 2008. "ColorConvert." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/ColorConvert.html.

APA

Wolfram Language. (2008). ColorConvert. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ColorConvert.html

BibTeX

@misc{reference.wolfram_2022_colorconvert, author="Wolfram Research", title="{ColorConvert}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/ColorConvert.html}", note=[Accessed: 02-July-2022 ]}

BibLaTeX

@online{reference.wolfram_2022_colorconvert, organization={Wolfram Research}, title={ColorConvert}, year={2021}, url={https://reference.wolfram.com/language/ref/ColorConvert.html}, note=[Accessed: 02-July-2022 ]}