Neighborhood (image processing)

from Wikipedia, the free encyclopedia

In digital image processing , a neighborhood describes a small, defined image region around a pixel . Many image processing operations look at the pixels within a neighborhood in order to compute a new color or gray value for their center . With the four-neighborhood (also D-neighborhood ) and the eight-neighborhood there are two basic neighborhood concepts.

Neighborhood of four

Quad neighborhood around P

Each pixel P of an image has four neighbors D , horizontal and vertical . These direct neighbors are characterized by the fact that they each have a pixel edge in common with P. They are called D-neighbors or 4-neighbors .

If one takes the coordinates of P with , then the coordinates of the four D neighbors are through

given. Each D neighbor is exactly one unit away from P.

The set that contains the point P and its neighbors D is called a four-neighborhood. A neighborhood of four therefore consists of five points (see adjacent figure). It is usually referred to as.

See also: Von Neumann neighborhood

Eighth neighborhood

Eighth neighborhood around P

Besides the four D-neighbors of each pixel has P an image four diagonal neighbors N . These have only one corner in common with P and are defined by the coordinates

given. The distance of the neighbor N of P is determined by the used metric. If, for example, the Euclidean metric is used as a basis, the distance is , while it is 2 for the Manhattan metric .

The set that contains the point P and its neighbors D and N is called a neighborhood of eight. A figure eight neighborhood therefore consists of nine points (see adjacent figure). It is often referred to as or simply or .

See also: Moore Neighborhood


Manhattan neighborhood with a maximum distance of 2 around P.

In many operations in digital image processing, new color or gray values ​​are calculated for the pixels on the basis of neighborhoods around the pixels of an image. This is primarily the case with neighborhood operators , such as precedence operators or morphological operators . Neighborhood definitions are also used in other areas, e.g. B. in some segmentation methods required.

If a neighborhood is used in image processing and no explicit reference is made to the use of a neighborhood of four or another in the specific application, a neighborhood of eight is generally used.

The size and shape of a neighborhood always depends on the application. For many operators, a square shape with usual. Deviating from this, a neighborhood can also be defined, for example, according to the Manhattan metric with a maximum distance of 2 from the center point P (see adjacent figure). Round or even completely asymmetrical neighborhoods are also conceivable.

The pixel in the middle of a neighborhood does not necessarily have to be the center point P of the neighborhood, which, however, occurs rather rarely. To avoid confusion, the center point P is also referred to as an anchor in cases where it deviates from the mathematical center point .

Edge problem

Neighborhood fringe problem

In the practical application of neighborhood operators, the edge problem inevitably arises: How is the case handled when a pixel is so close to the edge of an image that the neighborhood “protrudes” over the image (see figure on the right)?

Four different approaches are conceivable:

  • The edge pixels are not considered. The disadvantage here is that the result image is then slightly smaller (at a -Nachbarschaft with odd n to pixels on each side). If several neighborhood operators are applied one after the other, the image shrinks with each application.
  • If the mask protrudes beyond the edge of the image, it is reduced accordingly by the "protruding" areas.
  • The required pixels outside the image are extrapolated according to the closest pixels . The disadvantage here is that extrapolation errors can continue into the interior of the image when several neighborhood operators are used one after the other.
  • The picture continues periodically. This method can only be used if there is at least an approximate periodicity of the image.


  • Bernd Jähne : Digital image processing. 6th, revised and expanded edition. Springer-Verlag, Berlin 2005, ISBN 3-540-24999-0
  • Rafael C. Gonzalez, Richard E. Woods: Digital Image Processing. 2nd Edition. Prentice Hall, 2001, ISBN 0-201-18075-8 (English)