Images are built on a grid of pixels. To describe how close two pixels are, we need a definition of distance. Different distance measures produce different paths, neighborhoods, and ideas of connectivity.
1. Pixels as Coordinates
A pixel can be described by its position on the image grid. Let two pixels be
On this page, \(x\) represents horizontal position and \(y\) represents vertical position.
Define the horizontal and vertical coordinate differences as
2. Euclidean Distance
Euclidean distance, also called the \(L_2\) distance, measures the direct straight-line distance between two points.
3. Manhattan / City-Block Distance
Manhattan distance, also called the \(L_1\) distance, measures distance using horizontal and vertical movement.
4. Chebyshev / Chessboard Distance
Chebyshev distance, also called the \(L_\infty\) distance, allows horizontal, vertical, and diagonal movement. A diagonal step costs the same as a horizontal or vertical step.
5. Same Pixels, Different Distances
Suppose the two pixels differ by
6. Neighborhoods Defined by Distance
A neighborhood around a center pixel \(p\) can be defined by selecting every pixel \(q\) whose distance from \(p\) is no greater than radius \(r\):
The examples below all use the same radius, \(r=3\).
7. 4-Neighborhood and 8-Neighborhood
Two especially common local neighborhoods use only the pixels immediately surrounding a center pixel.
4-Neighborhood
Horizontal and vertical neighbors only.
8-Neighborhood
Horizontal, vertical, and diagonal neighbors.
8. Why Does the Distance Definition Matter?
Distance is not only used to say how far apart two pixels are. It also helps define several other image-processing concepts.
9. Interactive Example
The interactive visualizer below uses the same pixel grid in two different ways.
Compare Two Pixels
Select pixels \(p\) and \(q\).
The visualizer calculates \(\Delta x\), \(\Delta y\), Euclidean distance, Manhattan distance, and Chebyshev distance.
You can then display a representative shortest path for each distance rule.
Build a Neighborhood
Select a center pixel, a distance measure, and radius \(r\).
Every pixel satisfying \(d(p,q)\le r\) is highlighted.
Switching the distance rule changes the neighborhood shape immediately.
Summary
| Concept | Meaning |
|---|---|
| \(\Delta x\) | Absolute horizontal coordinate difference. |
| \(\Delta y\) | Absolute vertical coordinate difference. |
| Euclidean / \(L_2\) | \[ d_E = \sqrt{ (\Delta x)^2 + (\Delta y)^2 } \] |
| Manhattan / City-Block / \(L_1\) | \[ d_M = \Delta x+\Delta y \] |
| Chebyshev / Chessboard / \(L_\infty\) | \[ d_C = \max( \Delta x, \Delta y ) \] |
| \(N_r(p)\) | Pixels whose selected distance from \(p\) is no greater than radius \(r\). |
| 4-Neighborhood | Immediate horizontal and vertical neighbors. |
| 8-Neighborhood | Immediate horizontal, vertical, and diagonal neighbors. |
q = —
Δy = —
Be First to Comment