Main Content


Convert pixel stream to frame-based video


visionhdl.PixelsToFrame converts a color or grayscale pixel stream and control structures into frame-based video. The control structure indicates the validity of each pixel and its location in the frame. The pixel stream format can include padding pixels around the active frame. You can configure the frame and padding dimensions by selecting a common video format or specifying custom dimensions. See Streaming Pixel Interface for details of the pixel stream format.

Use this object to convert the output of a function targeted for HDL code generation back to frames. This object does not support HDL code generation.

If your design converts frames to a pixel stream and later converts the stream back to frames, specify the same video format for the FrameToPixels object and the PixelsToFrame object.


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.


P2F = visionhdl.PixelsToFrame returns a System object, P2F, that converts a 1080p pixel stream, with standard padding, to a grayscale 1080×1920 frame.

P2F = visionhdl.PixelsToFrame(Name,Value) returns a System object, P2F, 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.



Components of each pixel, specified as 1, 3, or 4. Set to 1 for grayscale video. Set to 3 for color video, for example, {R,G,B} or {Y,Cb,Cr}. Set to 4 to use color with an alpha channel for transparency. The visionhdl.PixelsToFrame object expects a matrix of P-by-NumComponents values, where P is the total number of pixels. The default is 1.


Number of pixels transferred on the streaming interface for each cycle, specified as 1, 2, 4, or 8. The default is 1. To enable multipixel streaming and increase throughput for high-resolution or high-frame-rate video, set this property to 2, 4, or 8. The visionhdl.PixelsToFrame object expects a P-by-NumPixels matrix, where P is the total number of pixels. When you set NumPixels>1, you must set the NumComponents property to 1.


You can simulate System objects with a multipixel streaming interface, but they are not supported for HDL code generation. Use the equivalent blocks to generate HDL code for multipixel algorithms.


Dimensions of the active region of a video frame. To select a predefined format, specify the VideoFormat property as one of the options in the first column of the table. For a custom format, set VideoFormat to 'Custom', and specify the dimensional properties as integers.

Video FormatActive Pixels Per LineActive Video Lines
1080p (default)19201080


stepConvert pixel stream to image frame
Common to All System Objects

Allow System object property value changes


collapse all

This example converts a custom-size grayscale image to a pixel stream. It uses the visionhdl.LookupTable object to obtain the negative image. Then it converts the pixel-stream back to a full-frame image.

Load the source image from a file. Select a portion of the image matching the desired test size.

frmOrig = imread('rice.png');
frmActivePixels = 64;
frmActiveLines = 48;
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 lookup table (LUT) object to generate the negative of the input image.

tabledata = linspace(255,0,256);
inverter = visionhdl.LookupTable(tabledata);

Serialize the test image by calling the serializer object. pixIn is a vector of intensity values. ctrlIn is a vector of control signal structures.

[pixIn,ctrlIn] = frm2pix(frmInput);

Prepare to process pixels by preallocating output vectors.

[~,~,numPixelsPerFrame] = getparamfromfrm2pix(frm2pix);
pixOut = zeros(numPixelsPerFrame,1,'uint8');
ctrlOut = repmat(pixelcontrolstruct,numPixelsPerFrame,1);

For each pixel in the stream, look up the negative of the pixel value.

for p = 1:numPixelsPerFrame  
    [pixOut(p),ctrlOut(p)] = inverter(pixIn(p),ctrlIn(p));

Create a deserializer object with a format matching that of the serializer. Convert the pixel stream to an image frame by calling the deserializer object. Display the resulting 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.

Version History

Introduced in R2015a