Main Content


Convert color information between color spaces


visionhdl.ColorSpaceConverter converts between R'G'B' and Y'CbCr color spaces, and also converts R'G'B' to intensity.

This object uses a streaming pixel interface with a structure for frame control signals. This interface enables the object to operate independently of image size and format and to connect with other Vision HDL Toolbox™ objects. The object accepts and returns a scalar pixel value and control signals as a structure containing five signals. The control signals indicate the validity of each pixel and its location in the frame. To convert a pixel matrix into a pixel stream and control signals, use the visionhdl.FrameToPixels object. For a full description of the interface, see Streaming Pixel Interface.


The ColorSpaceConverter System object™ operates on gamma-corrected color spaces. However, to simplify use of the System object, the property arguments do not include the prime notation.


Starting in R2016b, instead of using the step method to perform the operation defined by the System object, you can call the object with arguments, as if it were a function. For example, y = step(obj,x) and y = obj(x) perform equivalent operations.


CSC = visionhdl.ColorSpaceConverter returns a System object, CSC, that converts R'G'B' to Y'CbCr using the Rec. 601 (SDTV) standard.

CSC = visionhdl.ColorSpaceConverter(Name,Value) returns a System object, CSC, with additional options specified by one or more Name,Value pair arguments. Name is a property name and Value is the corresponding value. Name must appear inside single quotes (''). You can specify several name-value pair arguments in any order as Name1,Value1,...,NameN,ValueN. Properties not specified retain their default values.



Conversion that the object performs on the input video stream.

  • RGB to YCbCr (default)

  • YCbCr to RGB

  • RGB to intensity

The step method accepts input as a vector of three values representing a single pixel. If you choose RGB to intensity, the output is a scalar value. Otherwise, the output is a vector of three values.


Conversion equation to use on the input video stream.

  • Rec. 601 (SDTV) (default)

  • Rec. 709 (HDTV)

This property does not apply when you set Conversion to RGB to intensity.


Scanning standard to use for HDTV conversion.

  • 1250/50/2:1 (default)

  • 1125/60/2:1

This property applies when you set ConversionStandard to Rec. 709 (HDTV).


stepConvert one pixel between color spaces
Common to All System Objects

Allow System object property value changes


collapse all

This example shows how to convert pixel stream data to a different color space.

Set the dimensions of the test image and load a color source image. Select a portion of the image matching the desired test size.

frmActivePixels = 64;
frmActiveLines = 48;
frmOrig = imread('fabric.png');
frmInput = frmOrig(1:frmActiveLines,1:frmActivePixels,:);
title 'Input Image'

Figure contains an axes object. The axes object with title Input Image contains an object of type image.

Create a serializer object and specify size of inactive pixel regions.

frm2pix = visionhdl.FrameToPixels(...

Create a color space converter object. Select a conversion from RGB to grayscale.

convertrgb2gray = visionhdl.ColorSpaceConverter(...
      'Conversion','RGB to intensity');

Serialize the test image. pixIn is a numPixelsPerFrame-by-3 matrix. ctrlIn is a vector of control signal structures.

[pixIn,ctrlIn] = frm2pix(frmInput);

Set up variables, and convert each pixel in the stream to the new color space.

[~,~,numPixelsPerFrame] = getparamfromfrm2pix(frm2pix);
pixOut = zeros(numPixelsPerFrame,1,'uint8');
ctrlOut = repmat(pixelcontrolstruct,numPixelsPerFrame,1);
for p = 1:numPixelsPerFrame  
    [pixOut(p),ctrlOut(p)] = convertrgb2gray(pixIn(p,:),ctrlIn(p));

Create a deserializer object with format matching that of the serializer. Convert the pixel stream to an image frame, and display the grayscale output image.

pix2frm = visionhdl.PixelsToFrame(...
[frmOutput,frmValid] = pix2frm(pixOut,ctrlOut);
if frmValid
    title 'Output Image'

Figure contains an axes object. The axes object with title Output Image contains an object of type image.


This object implements the algorithms described on the Color Space Converter block reference page.

Extended Capabilities

Version History

Introduced in R2015a

See Also

| (Image Processing Toolbox) | (Image Processing Toolbox) | |