Main Content

Specify Region of Interest for Neighborhood Processing

This example shows how to configure a Neighborhood Processing Subsystem block to operate over only a subsection of an input matrix. This subsection is called a region of interest (ROI).

Import Image and Output Results

The Neighborhood Processing Subsystem block operates on numerical matrices such as image data. You can use Computer Vision Toolbox™ blocks to import image data and render images.

  1. Create a model that contains a Neighborhood Processing Subsystem block.

  2. To import an image, add the Image From File (Computer Vision Toolbox) block to your model. Double-click the block to open the block dialog. To prevent precision loss, in the Data Types tab, set the Output data type block parameter to double.

  3. Connect the output port of the Image From File block to the input port of the Neighborhood Processing Subsystem block.

  4. To display images, use the Video Viewer (Computer Vision Toolbox) block. Use two Video Viewer blocks to display the image before and after the Neighborhood Processing Subsystem block.

    Simulink model containing an Image From File block that passes its output to a Video Viewer block, called Before, and a Neighborhood Processing Subsystem block. The Neighborhood Processing Subsystem block passes its output to another Video Viewer block, called After.

Configure Neighborhood Processing Subsystem

The input image peppers.png is 384 pixels tall and 512 pixels wide, with three color channels. Configure the Neighborhood Processing Subsystem block to operate over a 100-by-100 pixel ROI from inside the input image and return that ROI as it appears in the input image.

  1. Open the Neighborhood Processing Subsystem block.

    Subsystem containing a Neighborhood block, an Inport block, and an Outport block. The Inport block connects directly to the Outport block.

  2. The Neighborhood control block in the subsystem configures the behavior of the subsystem. Open the Neighborhood block parameters.

  3. Set the Neighborhood size and Stride parameters to [1 1 1]. The Neighborhood Processing Subsystem block iterates over 1-by-1 windows for each of the three color channels in the input image. Because the Inport block connects directly to the Outport block, the Neighborhood Processing Subsystem block returns the input pixels as they appear in the input image.

  4. Set the Processing offset parameter to [50 40 0]. Instead of beginning by processing the top left pixel of the input image, the Neighborhood Processing Subsystem block begins iterating from 50 pixels down and 40 pixels to the right.

  5. Set the Processing width parameter to [100 100 3]. Instead of iterating over the input image until reaching the lower and rightmost boundaries of the image, the Neighborhood Processing Subsystem block processes only a 100-by-100 pixel region of the image beginning from the pixel you specified in the Processing offset parameter.

Simulate and View Results

Simulate the model. The processed image represents only a section of the original image.

A Video Viewer display window showing an image of peppers.

A Video Viewer display window showing a small section of an image of peppers.

See Also

|

Related Topics