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.
Create a model that contains a Neighborhood Processing Subsystem block.
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
.Connect the output port of the Image From File block to the input port of the Neighborhood Processing Subsystem block.
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 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.
Open the Neighborhood Processing Subsystem block.
The Neighborhood control block in the subsystem configures the behavior of the subsystem. Open the Neighborhood block parameters.
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.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.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.
See Also
Neighborhood Processing Subsystem | Neighborhood