visionhdl.ColorSpaceConverter

Convert color information between color spaces

Description

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.

Note

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.

Note

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.

Construction

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.

Properties

Conversion

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.

ConversionStandard

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.

ScanningStandard

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).

Methods

stepConvert one pixel between color spaces
Common to All System Objects
release

Allow System object property value changes

Examples

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,:);
figure
imshow(frmInput,'InitialMagnification',300)
title 'Input Image'

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

frm2pix = visionhdl.FrameToPixels(...
      'NumComponents',3,...
      'VideoFormat','custom',...
      'ActivePixelsPerLine',frmActivePixels,...
      'ActiveVideoLines',frmActiveLines,...
      'TotalPixelsPerLine',frmActivePixels+10,...
      'TotalVideoLines',frmActiveLines+10,...
      'StartingActiveLine',6,...     
      'FrontPorch',5);

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.

Note: This syntax runs only in R2016b or later. If you are using an earlier release, replace each call of an object with the equivalent step syntax. For example, replace myObject(x) with step(myObject,x).

[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));
end

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(...
      'NumComponents',1,...
      'VideoFormat','custom',...
      'ActivePixelsPerLine',frmActivePixels,...
      'ActiveVideoLines',frmActiveLines);
[frmOutput,frmValid] = pix2frm(pixOut,ctrlOut);
if frmValid
    figure
    imshow(frmOutput,'InitialMagnification',300)
    title 'Output Image'
end

Algorithms

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

See Also

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

Introduced in R2015a