| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Video and Image Processing Blockset |
| Contents | Index |
| Learn more about Video and Image Processing Blockset |
| On this page… |
|---|
Video in the Video and Image Processing Blockset Blocks Image Data Stored in Column-Major Format Video Duration and Simulation Time |
In the Video and Image Processing Blockset software, images are real-valued ordered sets of color or intensity data. The blocks interpret input matrices as images, where each element of the matrix corresponds to a single pixel in the displayed image. Images can be binary, intensity (grayscale), or RGB. This section explains how to represent these types of images.
Binary images are represented by a Boolean matrix of 0s and 1s, which correspond to black and white pixels, respectively.
For more information, see Binary Images in the Image Processing Toolbox™ documentation.
Intensity images are represented by a matrix of intensity values. While intensity images are not stored with colormaps, you can use a gray colormap to display them.
For more information, see Grayscale Images in the Image Processing Toolbox documentation.
RGB images are also known as a true-color images. With Video and Image Processing Blockset blocks, these images are represented by an array, where the first plane represents the red pixel intensities, the second plane represents the green pixel intensities, and the third plane represents the blue pixel intensities. In the Video and Image Processing Blockset software, you can pass RGB images between blocks as three separate color planes or as one multidimensional array.
For more information, see Truecolor Images in the Image Processing Toolbox documentation.
Video data is a series of images over time. Video in binary or intensity format is a series of single images. Video in RGB format is a series of matrices grouped into sets of three, where each matrix represents an R, G, or B plane.
The values in a binary, intensity, or RGB image can be different data types. The data type of the image values determines which values correspond to black and white as well as the absence or saturation of color. The following table summarizes the interpretation of the upper and lower bound of each data type. To view the data types of the signals at each port, from the Format menu, point to Port/Signal Displays, and select Port Data Types.
Data Type | Black or Absence of Color | White or Saturation of Color |
|---|---|---|
Fixed point | Minimum data type value | Maximum data type value |
Floating point | 0 | 1 |
Note The Video and Image Processing Blockset software considers any data type other than double-precision floating point and single-precision floating point to be fixed point. |
For example, for an intensity image whose image values are 8-bit unsigned integers, 0 is black and 255 is white. For an intensity image whose image values are double-precision floating point, 0 is black and 1 is white. For an intensity image whose image values are 16-bit signed integers, -32768 is black and 32767 is white.
For an RGB image whose image values are 8-bit unsigned integers, 0 0 0 is black, 255 255 255 is white, 255 0 0 is red, 0 255 0 is green, and 0 0 255 is blue. For an RGB image whose image values are double-precision floating point, 0 0 0 is black, 1 1 1 is white, 1 0 0 is red, 0 1 0 is green, and 0 0 1 is blue. For an RGB image whose image values are 16-bit signed integers, -32768 -32768 -32768 is black, 32767 32767 32767 is white, 32767 -32768 -32768 is red, -32768 32767 -32768 is green, and -32768 -32768 32767 is blue.
The Video and Image Processing Blockset software enables you to work with color images and video signals as multidimensional arrays. For example, the following model passes a color image from a source block to a sink block using a 384-by-512-by-3 array.


You can choose to process the image as a multidimensional array by setting the Image signal parameter to One multidimensional signal in the Image From File block dialog box.

The blocks that support multidimensional arrays meet at least one of the following criteria:
They have the Image signal parameter on their block mask.
They have a note in their block reference pages that says, "This block supports intensity and color images on its ports."
Their input and output ports are labeled "Image".
You can also choose to work with the individual color planes of images or video signals. For example, the following model passes a color image from a source block to a sink block using three separate color planes.


To process the individual color planes of an image or video signal, set the Image signal parameter to Separate color signals in both the Image From File and Video Viewer block dialog boxes.


Note The ability to output separate color signals is a legacy option. It is recommend that you use multidimensional signals to represent color data. |
If you are working with a block that only outputs multidimensional arrays, you can use the Selector block to separate the color planes. For an example of this process, see . If you are working with a block that only accepts multidimensional arrays, you can use the Matrix Concatenation block to create a multidimensional array. For an example of this process, see .
You can specify locations in images using various coordinate systems. This topic discusses pixel coordinates and spatial coordinates, which are the two main coordinate systems used in the Video and Image Processing Blockset software.
Pixel coordinates enable you to specify locations in images. In this coordinate system, the image is treated as a grid of discrete elements, ordered from top to bottom and left to right, as shown in the following figure:
![]()
For pixel coordinates, the first component r (the row) increases downward, while the second component c (the column) increases to the right. Pixel coordinates are integer values and range from 0 to the length of the row or column. The pixel coordinates used in Video and Image Processing Blockset software are zero based, while the pixel coordinates used by Image Processing Toolbox and MATLAB are one based. For more information on the pixel coordinate system used by Image Processing Toolbox, see Pixel Coordinates in the Image Processing Toolbox documentation.
Spatial coordinates enable you to specify a location in an image with greater granularity than pixel coordinates. For example, in the pixel coordinate system, a pixel is treated as a discrete unit, uniquely identified by an integer row and column pair, such as (3,4). In a spatial coordinate system, locations in an image can be represented in terms of partial pixels, such as (3.3, 4.7). The following figure illustrates the spatial coordinate system used for images:

This spatial coordinate system corresponds to the pixel coordinate system in the following ways. First, both are defined in terms of row and column positions. Second, the spatial coordinates of the center point of any pixel are identical to the pixel coordinates for that pixel. However, the pixel coordinate system is discrete, while the spatial coordinate system is continuous. This means that, in pixel coordinates, the upper-left corner of an image is (0,0), while in spatial coordinates, this location is (-0.5,-0.5). The spatial coordinate system used by the Video and Image Processing Blockset software differs from the one used by Image Processing Toolbox. For more information on this spatial coordinate system, see Spatial Coordinates in the Image Processing Toolbox documentation.
The MATLAB technical computing software and Video and Image Processing Blockset blocks use column-major data organization. The blocks' data buffers store data elements from the first column first, then data elements from the second column second, and so on through the last column.
If you have imported an image or a video stream into the MATLAB workspace using a function from the MATLAB environment or the Image Processing Toolbox, the Video and Image Processing Blockset blocks will display this image or video stream correctly. If you have written your own function or code to import images into the MATLAB environment, you must take the column-major convention into account.
Because the Video and Image Processing blocks calculate values directly rather than solving differential equations, you must configure the Simulink Solver to behave like a scheduler that uses each block's sample time to determine when the code behind the block is executed. The following steps show you how to do this:
From the model's Simulation menu, select Configuration Parameters.
The Configuration dialog box opens.
From the Solver list, choose Discrete (no continuous states).
The following figure shows the correctly configured Configuration dialog box.

The Solver, while in scheduler mode, uses a block's sample time to determine when the code behind each block is executed. For example, if the sample time of a Video From Workspace block is 0.05, the Solver executes the code behind this block, and every other block with this sample time, once every 0.05 second.
The duration of the simulation is controlled by the Stop time parameter — not the input video. If you want the simulation to run for the duration of the input video, you must adjust the Stop time parameter. If your video is being cropped, increase the parameter value. If your video is complete and the display window is black, decrease the parameter value. To view the first N frames of your video, set the Stop time parameter to (N-1)*Ts, where Ts is the sample time of your source block.
You can access the Stop time parameter in the model window, as shown in the following figure, or on the Solver pane of the Configuration dialog box.

The Simulink software offer Accelerator and Rapid Accelerator simulation modes that remove much of the computational overhead required by Simulink models. These modes compile target code of your model. Through this method, the Simulink environment can achieve substantial performance improvements for larger models. The performance gains are tied to the size and complexity of your model. Therefore, large models that contain Video and Image Processing Blockset blocks run faster in Rapid Accelerator or Accelerator mode.
To change between Rapid Accelerator, Accelerator, and Normal mode, use the drop-down list at the top of the model window.

For more information on the accelerator modes in Simulink, see Accelerating Models in the Simulink User's Guide.
Video processing is computationally intensive, and the ability to perform real-time video processing is affected by the following factors:
Hardware capability
Model complexity
Model implementation
Input data size
Optimizing your implementation is a crucial step toward real-time video processing. The following tips can help improve the performance of your model:
Minimize the number of blocks in your model.
Process only the regions of interest to reduce the input data size.
Use efficient algorithms or the simplest version of an algorithm that achieves the desired result.
Use efficient block parameter settings. However, you need to decide whether these settings best suit your algorithm. For example, the most efficient block parameter settings might not yield the most accurate results. You can find out more about individual block parameters and their effect on performance by reviewing specific block reference pages.
The two following examples show settings that make each block's operation the least computationally expensive:
Resize block — Interpolation method = Nearest neighbor
Blocks that support fixed point — On the Fixed-Point tab, Overflow mode = Wrap
Choose data types carefully.
Avoid data type conversions.
Use the smallest data type necessary to represent your data to reduce memory usage and accelerate data processing.
In simulation mode, models with floating-point data types run faster than models with fixed-point data types. To speed up fixed-point models, you must run them in accelerator mode. Simulink contains additional code to process all fixed-point data types. This code affects simulation performance. After you run your model in accelerator mode or generate code for your target using Real-Time Workshop, the fixed-point data types are specific to the choices you made for the fixed-point parameters. Therefore, the fixed-point model and generated code run faster.
Use the following general process guidelines to develop real-time video processing models to run on embedded targets. By optimizing the model at each step, you improve its final performance.
Create the initial model and optimize the implementation algorithm. Use floating-point data types so that the model runs faster in simulation mode. If you are working with a floating-point processor, go to step 3.
If you are working with a fixed-point processor, gradually change the model data types to fixed point, and run the model after every modification.
During this process, you can use data type conversion blocks to isolate the floating point sections of the model from the fixed-point sections. You should see a performance improvement if you run the model in accelerator mode.
Remove unnecessary sink blocks, including scopes, and blocks that log data to files.
Compile the model for deployment on the embedded target.
The Video and Image Processing Blockset, Real-Time Workshop®, and Real-Time Workshop® Embedded Coder™ software enable you to generate code that you can use to implement your model for a practical application. For instance, you can create an executable from your Simulink model to run on a target chip. For more information, see Understanding Code Generation in Signal Processing Blockset Getting Started Guide..
For the blocks listed in the table below, copy the shared library files from the machine where the blockset software is installed to a folder on the system path of the destination machine.
| Block | Dependent library file | Product |
|---|---|---|
To Multimedia File | tommfile.dll SldirectShow.dll | Signal Processing Blockset™ |
From Multimedia File | frommmfile.dll SldirectShow.dll | Signal Processing Blockset |
To Video Display | tovideodevice.dll SldirectShow.dll | Video and Image Processing Blockset |
![]() | Working with the Documentation | Block Data Type Support | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |