Convert frame-based video to pixel stream


visionhdl.FrameToPixels converts color or grayscale frame-based video to a pixel stream and control structure. 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 generate input for a function targeted for HDL code generation. This block 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.


F2P = visionhdl.FrameToPixels returns a System object, F2P, that serializes a grayscale 1080×1920 frame into a 1080p pixel stream with standard padding around the active data.

F2P = visionhdl.FrameToPixels(Name,Value) returns a System object, F2P, 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 default is 1. The visionhdl.FrameToPixels object returns a P-by-NumComponents matrix, where P is the total number of pixels.


Number of pixels transferred on the streaming interface for each cycle, specified as 1, 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 4 or 8. The visionhdl.FrameToPixels object returns 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 active and inactive regions 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 dimension properties as integers. The frame dimensions are indicated in the diagram.

Video FormatActive Pixels Per LineActive Video LinesTotal Pixels Per LineTotal Video LinesStarting Active LineEnding Active LineFront PorchBack Porch
240p320240 40232412404438
480p6404808005253651516 144
1080p (default)192010802200112542112188192


When using a custom format, the properties you enter for the active and inactive dimensions of the image must add up to the total frame dimensions.

For the horizontal direction, TotalPixelsPerLine must be greater than or equal to FrontPorch + ActivePixelsPerLine. The block calculates BackPorch = TotalPixelsPerLineFrontPorchActivePixelsPerLine.

For the vertical direction, TotalVideoLines must be greater than or equal to StartingActiveLine + ActiveVideoLines − 1. The block calculates EndingActiveLine = StartingActiveLine + ActiveVideoLines − 1.

If you specify a format that does not conform to these rules, the object reports an error.


When using a custom format, ActivePixelsPerLine must be greater than 1. Also, set the horizontal blanking interval, or BackPorch + FrontPorch, according to these guidelines.

  • The total of BackPorch + FrontPorch must be at least 2 times the largest kernel size of the algorithm in the objects following the visionhdl.FrameToPixels object. If the kernel size is < 4, the total porch must be at least 8 pixels.

  • The BackPorch must be at least 6 pixels. This parameter is the number of inactive pixels before the first valid pixel in a frame.


When using multipixel streaming (NumPixels > 1) these requirements apply.

  • The video format must have horizontal dimensions divisible by the NumPixels property value. The horizontal dimensions are set by these properties: ActivePixelsPerLine, TotalPixelsPerLine, FrontPorch, and BackPorch. Standard video protocols 480p, 720p, 1080p, and 4k UHD support NumPixels equal to 4 or 8.

  • The minimum input frame size for multipixel streaming (either 4 or 8 pixels) is 18 rows-by-32 columns.

  • Choose your kernel size and ActivePixelsPerLine such that (ActivePixelsPerLine)/(NumPixels) is at least the kernel width.


stepConvert image frame to pixel stream
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'

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.

Note: This object 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);

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'

Introduced in R2015a