Main Content

Create Model That Performs Neighborhood Processing

This example shows how to create a model that performs neighborhood processing by using the Neighborhood Processing Subsystem block to blur an image. Neighborhood processing algorithms operate on images by iteratively processing windows of pixels, called neighborhoods, within the image.

Import Image and Output Results

The Neighborhood Processing Subsystem block operates on 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.

Configure Neighborhood Processing Subsystem

The Neighborhood Processing Subsystem block accepts a matrix as input and produces a matrix as output. Inside the subsystem, build an algorithm that accepts a neighborhood of the input matrix as input and produces a scalar as output. The block handles the processes of iteratively passing each neighborhood and assembling the output scalars into an output matrix.

  1. Open the Neighborhood Processing Subsystem 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 parameter to [5 5 1]. The Neighborhood Processing Subsystem block iterates over 5-by-5 windows for each color channel in the input image. A larger window size produces more blur.

  4. Place a Gain block between the Inport and Outport blocks. Set the Gain value to 1/25.

  5. Place a Sum of Elements block between the Gain and Outport blocks. The Sum of Elements block converts a matrix to a scalar. By multiplying the 25 elements of the neighborhood by 1/25 and summing the values, the subsystem computes the average value of the neighborhood. This creates a blur effect by blending nearby pixels together.

Simulate and View Results

Simulate the model. The processed image is blurry compared to the original image.

A Video Viewer display window showing an image of peppers.

A Video Viewer display window showing a blurry image of peppers.

See Also

Related Topics