Image Processing Toolbox User's Guide |

**Sliding Neighborhood Operations**

A sliding neighborhood operation is an operation that is performed a pixel at a time, with the value of any given pixel in the output image being determined by the application of an algorithm to the values of the corresponding input pixel's *neighborhood.* A pixel's neighborhood is some set of pixels, defined by their locations relative to that pixel, which is called the *center pixel*. The neighborhood is a rectangular block, and as you move from one element to the next in an image matrix, the neighborhood block slides in the same direction.

The following figure shows the neighborhood blocks for some of the elements in a 6-by-5 matrix with 2-by-3 sliding blocks. The center pixel for each neighborhood is marked with a dot.

**Neighborhood Blocks in a 6-by-5 Matrix
**

The center pixel is the actual pixel in the input image being processed by the operation. If the neighborhood has an odd number of rows and columns, the center pixel is actually in the center of the neighborhood. If one of the dimensions has even length, the center pixel is just to the left of center or just above center. For example, in a 2-by-2 neighborhood, the center pixel is the upper left one.

For any `m`

-by-`n`

neighborhood, the center pixel is

In the 2-by-3 block shown in Figure , the center pixel is (1,2), or the pixel in the second column of the top row of the neighborhood.

To perform a sliding neighborhood operation,

- Select a single pixel.
- Determine the pixel's neighborhood.
- Apply a function to the values of the pixels in the neighborhood. This function must return a scalar.
- Find the pixel in the output image whose position corresponds to that of the center pixel in the input image. Set this output pixel to the value returned by the function.
- Repeat steps 1 through 4 for each pixel in the input image.

For example, the function might be an averaging operation that sums the values of the neighborhood pixels and then divides the result by the number of pixels in the neighborhood. The result of this calculation is the value of the output pixel.

Types of Block Processing Operations | Padding Borders |

© 1994-2005 The MathWorks, Inc.