Main Content

visionhdl.ChromaResampler

Downsample or upsample chrominance component

Description

visionhdl.ChromaResampler downsamples or upsamples a pixel stream.

  • Downsampling reduces bandwidth and storage requirements in a video system by combining pixel chrominance components over multiple pixels. You can specify a filter to prevent aliasing, by selecting the default filter or by entering coefficients.

  • Upsampling restores a signal to its original rate. You can use interpolation or replication to calculate the extra sample.

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 object accepts luma and the chrominance components. The object does not modify the luma component and applies delay to align with the resampled chrominance outputs. The rate of the output luma component is the same as the input.

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

CR = visionhdl.ChromaResampler returns a System object, CR, that downsamples from 4:4:4 to 4:2:2 and applies the default antialiasing filter.

CR = visionhdl.ChromaResampler(Name,Value) returns a chroma resampler System object, CR, 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

Resampling

Resampling format.

  • 4:4:4 to 4:2:2 (default) — Perform a downsampling operation.

  • 4:2:2 to 4:4:4 — Perform an upsampling operation.

AntialiasingFilterSource

Lowpass filter to accompany a downsample operation.

  • Auto (default) — Built-in lowpass filter.

  • Property — Filter using the coefficients in HorizontalFilterCoefficients property.

  • None — No filtering of the input signal.

This property applies when you set Resampling to 4:4:4 to 4:2:2.

HorizontalFilterCoefficients

Coefficients for the antialiasing filter.

Enter the coefficients as a vector. This property applies when you set Resampling to 4:4:4 to 4:2:2 and Antialiasing filter to Property.

Default: [0.2,0.6,0.2]

InterpolationFilter

Interpolation method for an upsample operation.

  • Linear (default) — Linear interpolation to calculate the missing values.

  • Pixel replication — Repeat the chrominance value of the preceding pixel to create the missing pixel.

This property applies when you set Resampling to 4:2:2 to 4:4:4.

RoundingMethod

Rounding mode used for fixed-point operations.

The object uses fixed-point arithmetic for internal calculations when the input is any integer or fixed-point data type. This option does not apply when the input data type is single or double.

Default: Floor

OverflowAction

Overflow action used for fixed-point operations.

The object uses fixed-point arithmetic for internal calculations when the input is any integer or fixed-point data type. This option does not apply when the input data type is single or double.

Default: Wrap

CustomCoefficientsDataType

Data type for the antialiasing filter coefficients.

Specify a custom data type as a character vector. This parameter applies when you set Antialiasing filter to Property or Auto.

Default: 'fixdt(1,16,0)'

Methods

stepCompute next pixel in upsampled or downsampled pixel stream
Common to All System Objects
release

Allow System object property value changes

Examples

collapse all

Resample a 4:4:4 Y'CbCr image to 4:2:2. The example also shows how to convert a R'G'B' input image to Y'CbCr color space.

Prepare a test image by selecting a portion of an image file.

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

Create a serializer and specify the size of inactive pixel regions. The number of padding pixels on each line must be greater than the latency of each pixel-processing object.

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

Create a color space converter and resampler, using the default property values. The default conversion is 'RGB to YCbCr'. The default resampling mode is '4:4:4 to 4:2:2'. The default anti-aliasing filter is a 29-tap lowpass filter. This gives the object a latency of 30 cycles.

convert2ycbcr = visionhdl.ColorSpaceConverter();
downsampler = visionhdl.ChromaResampler();

Serialize the test image using the serializer object. pixIn is a numPixelsPerFrame -by-3 matrix. ctrlIn is a vector of control signal structures. Preallocate vectors for the output signals.

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

[~,~,numPixelsPerFrame] = getparamfromfrm2pix(frm2pix);
pix444 = zeros(numPixelsPerFrame,3,'uint8');
ctrl444  = repmat(pixelcontrolstruct,numPixelsPerFrame,1);
pix422 = zeros(numPixelsPerFrame,3,'uint8');
ctrl422 = repmat(pixelcontrolstruct,numPixelsPerFrame,1);

For each pixel in the stream, convert to YCbCr, then downsample.

for p = 1:numPixelsPerFrame  
    [pix444(p,:),ctrl444(p)] = convert2ycbcr(pixIn(p,:),ctrlIn(p));
    [pix422(p,:),ctrl422(p)] = downsampler(pix444(p,:),ctrl444(p));
end

Create deserializers with a format matching that of the serializer. Convert the 4:4:4 and 4:2:2 pixel streams back to image frames.

pix2frm444 = visionhdl.PixelsToFrame(...
      'NumComponents',3,...
      'VideoFormat','custom',...
      'ActivePixelsPerLine',frmActivePixels,...
      'ActiveVideoLines',frmActiveLines);

pix2frm422 = visionhdl.PixelsToFrame(...
     'NumComponents',3,...
     'VideoFormat','custom',...
     'ActivePixelsPerLine',frmActivePixels,...
     'ActiveVideoLines',frmActiveLines);

[frm444,frmValid] = pix2frm444(pix444,ctrl444);
[frm422,frmValid] = pix2frm422(pix422,ctrl422);

There are the same number of pixels in the 4:2:2 and 4:4:4 pixel-streams and frames. To examine the resampled data, regroup the pixel data for the first 8 pixels of the first line. The first row is the Y elements of the pixels, the second row is the Cb elements, and the third row is the Cr elements. Notice that, in the 4:2:2 data, the Cb and Cr elements change only every second sample.

YCbCr444 = [frm444(1,1:8,1); frm444(1,1:8,2); frm444(1,1:8,3)]
YCbCr444 = 3x8 uint8 matrix

   132   134   129   124   125   122   118   119
   116   118   119   122   122   121   123   123
   135   131   125   121   119   116   118   118

YCbCr422 = [frm422(1,1:8,1); frm422(1,1:8,2); frm422(1,1:8,3)]
YCbCr422 = 3x8 uint8 matrix

   132   134   129   124   125   122   118   119
   116   116   120   120   122   122   123   123
   135   135   126   126   119   119   118   118


figure
imshow(frm422,'InitialMagnification',300)
title '4:2:2'

Figure contains an axes object. The axes object with title 4:2:2 contains an object of type image.

figure
imshow(frm444,'InitialMagnification',300)
title '4:4:4'

Figure contains an axes object. The axes object with title 4:4:4 contains an object of type image.

Algorithms

This object implements the algorithms described on the Chroma Resampler block reference page.

Extended Capabilities

Introduced in R2015a