Main Content

Integrate Vision HDL Blocks into Camera Link System

This example shows how to design a Vision HDL Toolbox™ algorithm for integration into an existing system that uses the Camera Link® signal protocol.

Vision HDL Toolbox blocks use a custom streaming video format. If you integrate Vision HDL Toolbox algorithms into existing design and verification code that operates in a different streaming video format, you must convert the control signals at the boundaries. The example uses custom System objects to convert the control signals between the Camera Link format and the Vision HDL Toolboxpixelcontrolformat. The model imports the System objects to Simulink® by using the MATLAB® System block.

Structure of the Model

This model imports pixel data and control signals in the Camera Link format from the MATLAB workspace. TheCameraLink_InvertImagesubsystem is designed for integration into existing systems that use Camera Link protocol. TheCameraLink_InvertImagesubsystem converts the control signals from the Camera Link format to thepixelcontrolformat, modifies the pixel data using the Lookup Table block, and then converts the control signals back to the Camera Link format. The model exports the resulting data and control signals to workspace variables.

Structure of the Subsystem

TheCameraLink2VHTandVHT2CameraLinkblocks are MATLAB System blocks that point to custom System objects. The objects convert between Camera Link signals and thepixelcontrolformat used by Vision HDL Toolbox blocks and objects.

You can put any combination of Vision HDL Toolbox blocks into the middle of the subsystem. This example uses an inversion Lookup Table.

你可以从这个子系统生成高密度脂蛋白。

Import Data in Camera Link Format

Camera Link consists of three control signals: F indicates the valid frame, L indicates each valid line, and D indicates each valid pixel. For this example, the input data and control signals are defined in theInitFcncallback. The vectors describe this 2-by-3, 8-bit grayscale frame. In the figure, the active image area is in the dashed rectangle, and the inactive pixels surround it. The pixels are labeled with their grayscale values.

FIn = logical([0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0]); LIn = logical([0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0]); DIn = logical([0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0]); pixIn = uint8([0,0,0,0,0,0,0,30,60,90,0,0,0,120,150,180,0,0,0,0,0,0,0,0]);

Convert Camera Link Control Signals to pixelcontrol Format

Write a custom System object to convert Camera Link signals to the Vision HDL Toolbox format. This example uses the object designed in theConvert Camera Control Signals to pixelcontrol Formatexample.

The object converts the control signals, and then creates a structure that contains the new control signals. When the object is included in a MATLAB System block, the block translates this structure into the bus format expected by Vision HDL Toolbox blocks. For the complete code for the System object, seeCAMERALINKtoVHT_Adapter.m.

Create a MATLAB System block and point it to the System object.

Design Vision HDL Toolbox Algorithm

Select Vision HDL Toolbox blocks to process the video stream. These blocks accept and return a scalar pixel value and apixelcontrolbus that contains the associated control signals. This standard interface makes it easy to connect blocks from the Vision HDL Toolbox libraries together.

This example uses the Lookup Table block to invert each pixel in the test image. Set the table data to the reverse of theuint8grayscale color space.

Convert pixelcontrol to Camera Link

编写一个定制的系统对象将视觉高密度脂蛋白Toolbox signals back to the Camera Link format. This example uses the object designed in theConvert Camera Control Signals to pixelcontrol Formatexample.

The object accepts a structure of control signals. When you include the object in a MATLAB System block, the block translates the inputpixelcontrolbus into this structure. Then it computes the equivalent Camera Link signals. For the complete code for the System object, seeVHTtoCAMERALINKAdapter.m.

Create a second MATLAB System block and point it to the System object.

View Results

Run the simulation. The resulting vectors represent this inverted 2-by-3, 8-bit grayscale frame. In the figure, the active image area is in the dashed rectangle, and the inactive pixels surround it. The pixels are labeled with their grayscale values.

If you have a DSP System Toolbox™ license, you can view the signals over time using the Logic Analyzer. Select all the signals in theCameraLink_InvertImagesubsystem for streaming, and open the Logic Analyzer. This waveform shows the input and output Camera Link control signals and pixel values at the top, and the input and output of the Lookup Table block inpixelcontrolformat at the bottom. Thepixelcontrolbusses are expanded to observe the boolean control signals.

For more info on observing waveforms in Simulink, seeInspect and Measure Transitions Using the Logic Analyzer(DSP System Toolbox).

Generate HDL Code for Subsystem

To generate HDL code you must have an HDL Coder™ license.

To generate the HDL code, use the following command.

makehdl('CameraLinkAdapterEx/CameraLink_InvertImage')

You can now simulate and synthesize these HDL files along with your existing Camera Link system.

Related Topics