Neighborhood
Description
The Neighborhood block serves as a control block for the Neighborhood Processing Subsystem block. The Neighborhood Processing Subsystem block iterates over an input matrix. At each iteration, the inport inside the subsystem receives a small matrix representing a configurable window of elements around one element of the input matrix. Use the Neighborhood block parameters to configure the behavior of the Neighborhood Processing Subsystem block, such as the window dimensions, the size of the output matrix, and the region of interest (ROI) over which to iterate.
Examples
Calculate Optical Flow by Using Neighborhood Processing Subsystem Blocks
Use Neighborhood Processing Subsystem blocks to calculate the apparent motion of objects in a video.
Perform Edge Detection by Using a Neighborhood Processing Subsystem Block
Use a Neighborhood Processing Subsystem block to detect edges in an image.
Perform Corner Detection by Using Neighborhood Processing Subsystem Blocks
Use Neighborhood Processing Subsystem blocks to detect corners in an image.
Perform Fog Rectification by Using Neighborhood Processing Subsystem Blocks
Use Neighborhood Processing Subsystem blocks to remove fog from an image.
Convert RGB Image to Grayscale by Using a Pixel Processing Subsystem Block
Use a Neighborhood Processing Subsystem block to convert a color image to grayscale.
Parameters
Neighborhood size — Dimensions of neighborhood window
[3 3]
(default) | array of positive scalars
Configure the dimensions of the neighborhood window that the subsystem receives at each iteration. The dimensions of the neighborhood cannot exceed the dimensions of the region of interest that you specify with the Processing width and Processing offset parameters.
For example, consider this input matrix:
.
If you set Neighborhood size to [3 3]
, then
on the seventh iteration, the Neighborhood Processing Subsystem block
receives this 3-by-3 window that surrounds the seventh element:
.
Programmatic Use
Block Parameter:
NeighborhoodSize |
Type: array |
Values: [3 3] |
'<array>' |
Default: [3 3] |
Stride — Number of input matrix elements to skip between iterations
[1 1]
(default) | array of positive scalars
Configure the Neighborhood Processing Subsystem block to skip a
number of elements in the input matrix between each iteration. For example, the value
[1 2]
configures the subsystem to iterate over alternating columns
from the input matrix and the value [3 1]
configures the subsystem to
iterate over every third row from the input matrix. Larger Stride
values produce smaller output matrices because the Neighborhood Processing
Subsystem block processes fewer elements.
See the difference between the Stride parameter values of
[1 1]
and [2 3]
.
Programmatic Use
Block Parameter:
Stride |
Type: array |
Values: [1 1] |
'<array>' |
Default: [1 1] |
Processing offset — Offset of each iteration
[0 0]
(default) | array of positive scalars
Configure a distance by which to offset each iteration of the algorithm. This distance defines the top left boundary the ROI within the input matrix.
For example, consider this input matrix:
.
If you use the default Processing offset parameter value of
[0 0]
, then the first iteration uses a neighborhood around the
element 1
, the second iteration centers around element
2
, and so on. If you set the Processing offset
parameter value to [1 2]
, then the Neighborhood Processing
Subsystem block offsets the center of each iteration by 1 along the vertical
axis and 2 along the horizontal axis. The first iteration centers on element
8
, the second iteration centers on element 9
,
and so on. Because the region of interest cannot extend outside the input matrix, the
output matrix is smaller than the input matrix.
Use the Processing offset and Processing width parameters together to process only a subsection of an input matrix. For an example, see Specify Region of Interest for Neighborhood Processing.
Programmatic Use
Block Parameter:
ProcessingOffset |
Type: array |
Values: [0 0] |
'<array>' |
Default: [0 0] |
Processing width — Subsection of input matrix to process
-1
(default) | array of scalars
Configure the dimensions of the ROI of the input matrix to process. The dimensions of the Processing width parameter cannot exceed the dimensions of the input matrix.
For example, consider this input matrix:
.
If you use the default Processing width parameter value of
-1
, then the Neighborhood Processing Subsystem
block iterates over the entire input matrix. In this example, this behavior is
equivalent to a Processing width parameter value of [5
5]
. If you use a Processing width parameter value of
[3 4]
, then the Neighborhood Processing Subsystem
block iterates over only the top left 3-by-4 region of the input matrix.
You can use the value -1
within a Processing
width parameter vector value to configure the Neighborhood
Processing Subsystem block to iterate over the full length of a particular
dimension. In the preceding example, if you use a Processing width
parameter value of [2 -1]
, then the Neighborhood Processing
Subsystem block iterates over the top 2-by-5 region of the input
matrix.
Use the Processing offset and Processing width parameters together to define the top left and bottom right boundaries of a region of interest. For an example, see Specify Region of Interest for Neighborhood Processing.
Programmatic Use
Block Parameter:
ProcessingWidth |
Type: array |
Values: -1 |
'<array>' |
Default: -1 |
Output size — Dimensions of output matrix
Same
(default) | Full
| Valid
Configure which ROI elements you want the Neighborhood Processing
Subsystem block to iterate over by selecting the value
Same
, Full
, or
Valid
. This determines the dimensions of the output
matrix.
Each example graphic shows a 5-by-5 region of interest with three highlighted subsections.
The blue top left subsection represents the neighborhood that the Neighborhood Processing Subsystem block processes in the first iteration.
The orange bottom right subsection represents the neighborhood of the last iteration.
The green center subsection represents the dimensions of the output matrix, which spans the centers of the first and last iterations.
For settings that use padded values, the example graphics denote padded values as
?
.
Each example graphic assumes a Neighborhood size parameter
value of [3 3]
, which defines a 3-by-3 neighborhood. Because each
example graphic assumes the default value of [0 0]
for the
Processing offset parameter and the default value of
-1
for the Processing width parameter, the
region of interest is the full input matrix. For information about how the
Neighborhood Processing Subsystem block pads values when you configure
a region of interest, see Use Neighborhood Processing Subsystem Block Padding Options with Region of Interest.
Same
–– The output matrix has the same dimensions as the region of interest. For elements near the edges, the neighborhood extends beyond the input matrix. Use the Padding option parameter to configure how to pad elements outside the input matrix.Full
–– The output matrix is larger than the region of interest. The matrix includes an element for every neighborhood that includes at least one element from the region of interest, even if the neighborhood center is outside the region of interest. Use the Padding option parameter to configure how to pad elements outside the input matrix.Valid
–– The output matrix is smaller than the region of interest. The output matrix includes only the elements whose neighborhoods fall entirely within the region of interest.
Programmatic Use
Block Parameter:
OutputSize |
Type: character vector |
Values: 'Same' |
'Full' | 'Valid' |
Default: 'Same' |
Padding option — Values to use outside of input matrix
Constant
(default) | Replicate
| Symmetric
| Circular
Configure how to pad values outside the input matrix. When you select the value
Full
or Same
for the
Output size parameter, some neighborhoods extend beyond the input
matrix and use padded matrix element values.
To fully illustrate the logic of each padding option, each example graphic shows the
5-by-5 input matrix padded with 5-by-5 matrices. In practice, not every padded value is
necessarily part of a neighborhood, depending on the Neighborhood
size and Output size parameters. For example, if you
set Neighborhood size to [3 3]
and
Output size to Same
, the subsystem
uses only the innermost layer of padded values.
Constant
–– Use a configurable constant value for elements outside the input matrix. For example, this matrix uses a constant value of0
..
Replicate
–– Extend the values of the edge parameters..
Symmetric
–– Mirror the input matrix..
Circular
–– Repeat the input matrix in a tiled pattern..
For information about how the Padding option parameter interacts with the Processing offset and Processing width parameters, see Use Neighborhood Processing Subsystem Block Padding Options with Region of Interest.
Programmatic Use
Block Parameter:
PaddingOption |
Type: character vector |
Values: 'Constant' |
'Replicate' | 'Symmetric' |
'Circular' |
Default:
'Constant' |
Dependencies
To enable this parameter, set Output
size to Same
or
Full
.
Padding constant — Value to use outside input matrix
0
(default) | scalar
Configure the value to use for the Constant
padding
option.
Dependencies
To enable this parameter, set Padding option to
Constant
.
Programmatic Use
Block Parameter:
PaddingConstant |
Type: scalar |
Values: 0 |
'<scalar>' |
Default: 0 |
Extended Capabilities
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
This block has one default HDL architecture.
Version History
Introduced in R2022b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)