Products & Services Solutions Academia Support User Community Company

Learn more about Video and Image Processing Blockset   

Key Blockset Concepts

Image Types

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

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

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

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 in the Video and Image Processing Blockset Blocks

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.

Defining Intensity and Color

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

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.

Color Image Processing

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:

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.

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 .

Coordinate Systems

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

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

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.

Image Data Stored in Column-Major Format

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.

Sample Time

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:

  1. From the model's Simulation menu, select Configuration Parameters.

    The Configuration dialog box opens.

  2. From the Type list, choose Fixed-step.

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

Video Duration and Simulation Time

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.

Acceleration Modes

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.

Strategies for Real-Time Video Processing

Video processing is computationally intensive, and the ability to perform real-time video processing is affected by the following factors:

Optimizing Your Implementation

Optimizing your implementation is a crucial step toward real-time video processing. The following tips can help improve the performance of your model:

Developing Your Models

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.

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

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

  3. Remove unnecessary sink blocks, including scopes, and blocks that log data to files.

  4. Compile the model for deployment on the embedded target.

Code Generation

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

Shared Library Dependencies

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.

BlockDependent library fileProduct

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

  


Related Products & Applications

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