Main Content

Select Region of Interest

This example shows how to select a region of active frame from a video stream by using the ROI Selector block from the Vision HDL Toolbox™.

There are numerous applications where the input video is divided into several zones. In medical imaging, the boundaries of a tumor may be defined on an image or in a volume for the purpose of measuring its size. In geographical information systems (GIS), an ROI can be taken as a polygonal selection from a 2-D map.

Example Model

The example model includes a Video Source block that contains a 240p video sample. Each pixel is a scalar uint8 value that represents intensity. The green and red lines represent full-frame processing and pixel-stream processing, respectively.

Serialize the Image

Use Frame To Pixels block to convert a full-frame image into pixel stream. To simulate the effect of horizontal and vertical blanking periods found in real life hardware video systems, the active image is augmented with non-image data. For more information on the streaming pixel protocol, see Streaming Pixel Interface. The Frame To Pixels block is configured as shown:

The Number of components parameter is set to 1 for grayscale image input, and the Video format parameter is 240p to match the video source.

In this example, the Active Video region corresponds to the 240x320 matrix of the source image. Six other parameters, namely, Total pixels per line, Total video lines, Starting active line, Ending active line, Front porch, and Back porch, specify how many non-image data will be augmented on the four sides of the Active Video. For more information, see the Frame To Pixels block reference page.

Note that the sample time of the Video Source block is determined by the product of Total pixels per line and Total video lines.

Select Regions of Interest

The ROI Selection subsystem contains only an ROI Selector block.

Use the ROI Selector block to select regions of interest. You can use the Regions parameter to experiment with different region sizes and examine their effect on the output frames. In this model, the Regions parameter is set to [100 100 50 50;220 170 100 70] which represents two regions, each specified by [hPos vPos hSize vSize]. The first region is 50-by-50 pixels and located 100 pixels to the right and 100 pixels down from the top-left corner of the active frame. The second region is 100 pixels wide and 70 pixels tall, and is located in the bottom-right corner of the active frame.

The ROI Selector block accepts a pixel stream and a bus that contains five control signals from the Frame To Pixels block. It returns each region as a pixel stream that uses the same protocol, by manipulating the control signals. Each region is selected by setting the valid signal in the output pixelcontrol bus to false for any pixels not included in the requested region.

Display Regions of Interest

Use the Pixels To Frame block to convert the pixel stream back into a full frame. Since the output of the Pixels To Frame block is a 2-D matrix of a full image, there is no further need for the pixelcontrol bus.

The Number of components and Video format parameters of both Frame To Pixels and Pixels To Frame are set to 1 and 240p, respectively, to match the format of the video source. The size of each active frame is smaller than 240p after the ROI selection. The Pixels to Frame block returns a 240-by-320 matrix with the active portion of the frame in the top-left corner.

Run the model to display the results. The model displays the output video streams by using three Video Viewer blocks.

  • Source Image View -- The input video from the Video Source block

  • ROI Selector Viewer1 -- The 50-by-50 pixel region

  • ROI Selector Viewer2 -- The 100-by-70 pixel region

One frame of the source video and the two regions are shown from left to right.

The Unit Delay block on the top level of the model is to time-align the matrices for a fair comparison.

Generate HDL Code

To check and generate the HDL code referenced in this example, you must have an HDL Coder™ license.

To generate the HDL code, use the following command:

makehdl('ROISelectionHDL/ROI Selection')

To generate a test bench, use the following command:

makehdltb('ROISelectionHDL/ROI Selection')

See Also

Blocks