# "Digital Image Processing" learning summary and perception: Chapter 2 Digital Image Fundamentals (4) The relationship between pixels

#### ☞ ░Go to LaoYuanPython blog post directory https://blog.csdn.net/LaoYuanPython ░

### I. Introduction

This series of articles records the old ape’s self-study of Gonzalez's "Digital Image Processing" insights and summary, but it is estimated that the update will be slower. If you have to work during the day, you will find time to study at night. After studying a chapter, you will come back to summarize. Friends who want to learn You can download the electronic version of the English original (currently to the fourth edition) and the Chinese translation (currently the third edition) to watch. If you want to compare and watch the English original, it is recommended to look for the third edition.

This "Digital Image Processing" is worthy of being a classic tutorial on digital image processing. It has a wide range of knowledge, detailed content, and case close to practice. At least it fits the taste of the old ape. However, there are two problems with the Chinese translation:

- Some translations are not accurate enough or fluently. If such content appears in Laosha’s summary knowledge, it will be marked in italics, and some key terms Laosha will be accompanied by the original English words;
- Many of the image cases in the Chinese version are much worse than the original version, and even poorer than the original version, even worse to affect the understanding of the content of the story, so even if you do not read the original text, the image case is best compared to the original.

### 2. Knowledge summary: Some Basic Relationships between Pixels

#### 2.1. Neighbors

The relationship between the pixel p in the image and its surrounding pixels are commonly used as follows:

- 4-neighbors: For each pixel p in the image, the 4 pixels adjacent to it in the vertical and horizontal directions are called 4-neighbors of p, denoted as N
_{4}(p). - Four diagonal neighbors (four diagonal neighbors): The four diagonally adjacent pixels of pixel p are called 4-diagonal neighbors, denoted as N
_{D}(p) - 8-neighbors: The 4-neighbors and 4-diagonal pixels of the pixel p are collectively called the 8-neighbors pixels of p, denoted as N
_{8}(p).

For the pixels at the edge of the image, there are cases where the neighboring pixels are not in the image.

#### 2.2. Adjacency

Suppose V is a set of certain gray values that define adjacency (this definition is a bit confusing, and the old ape understands this: if the gray value of a pixel is in this set, it means that the pixel can be adjacent to the surrounding pixels. Condition, the pixels that are not the gray value of this set will definitely not have a neighboring relationship with other pixels):

- 4-adjacent and 8-adjacent: two pixels p and q, if q appears in the 4-neighborhood or 8-neighborhood of p, and the gray values of p and q are in the set V, then p and q are adjacent, according to Is 4-neighborhood or 8-neighborhood called p and q as 4-adjacency (4-adjacency) or 8-adjacency (8-adjacency)
- m-adjacency (mixed adjacency): the gray values of p and q are both in the set V, q and p are 4 adjacent or q is in the 4-diagonal neighborhood of p and N
_{4}(p)∩N_{4}If there is no pixel value in V in the set of (q), then p and q are called adjacent to each other.

The m-adjacency is an improvement of the 8-adjacency, which is to eliminate the ambiguity of the 8-adjacency. Let V={1}, as shown in the following figure: It

may be too old to react. This figure is easy to understand at first glance, but there are doubts after careful thinking. The old ape only understood for a while. According to my own understanding, the explanation is as follows:

Use a12, a13, a22, and a33 to represent the above 4 elements that are 1 respectively. In the case of 8-adjacent, a13 is the 8-adjacent of a12 and a22 at the same time, but in the case of mixed adjacency, a13 is The mixed adjacency of a12, but not the mixed connection of a22, because the 4 adjacencies of a13 and a22 each have an intersection element a12, which does not satisfy the definition of mixed adjacency.

#### 2.3. Path

From the pixel p (coordinates (x, y)) with the pixel q (coordinates (s, t)) of the **passage** (digital path) (or a curve (Curve)) is the *addition of p and q may be repeated outer no other repetitive The sequence of* pixels (distinct pixels, the Chinese version translates as "specific pixel sequence", the English version has no explanation except for the start point and end point, this is the translation of the old ape for a long time, I don’t know whether it is correct), and its coordinate sequence is:

(x _{0} , y0), (x _{1} , y _{1} ),…, (x _{n} , y _{n} )

Satisfy:

- (x
_{0}, y0) corresponds to the coordinates of p, (x_{n}, y_{n}) corresponds to the coordinates of q - Any two adjacent pixels (x
_{i}, y_{i}) and (x_{i+1}, y_{i+1}) in the sequence are adjacent.

Defined above with respect to the path length of the path is n, i.e., if p and q correspond to the same pixel overlap, the passage is called **a closed circuit** (closed path).

In the above definition, the adjacency of two pixels can be 4 adjacency, 8 adjacency and mixed adjacency, and the corresponding paths are called **4-paths, 8-paths, and m-paths** (4-, 8-, or m-paths) respectively.

In the figure that illustrates the ambiguity in the definition of adjacency above, the dotted line connecting the left figure is the 8-path from the upper right corner to the lower right corner. It can be seen that there are 2 8-paths in the figure, and the right-picture is m-path, with only one.

#### 2.4. Connectivity

Suppose s is a pixel subset of an image:

- If s between two pixels p and q
*exists a path from the one composed of all the pixels s*(path), it can be said s two pixels p and q are**communicating**(Connected) of - According to the type of adjacency used, connectivity can be divided into
**4-connectivity, 8-connectivity and m-connectivity** - For any pixel p in s, s to the set of all communication is referred to as pixel p s of the
**connected components**(connected component) - If there is only one connected component in s, then the set s is called a
**connected set**(connected set)

#### 2.5. Regions

Assuming that R is a pixel subset of an image, if R is a connected set, then R is called a **region** of the image . It should be noted that the concept of a region is related to the type of adjacency, and a certain region may be an 8-adjacent area, but not a 4-adjacent area. The adjacency in the region definition is only based on 4 adjacency or 8 adjacency, and m adjacency cannot be considered. The old ape thinks that it is in the image. If a connected set of m adjacency is not a connected set of 8 adjacencies at the same time, the region in the image may be It feels like there is a break point, because the m adjacency can be two diagonal pixel adjacencies.

For two regions R _{i} and R _{j} , they jointly form a connected set, which is called the two regions **adjacent** (adjacent). Not adjacent (not adjacent) region referred to **do not communicate** (in disjoint) region.

#### 2.6. Boundaries

Suppose an image contains k non-adjacent regions R1, R2,..., RK (for special processing without considering the boundary, it is assumed that these K regions do not touch the boundary of the image), let R _{U} be the _{union} of these K regions set, so that R _{U }^{C} is R _{U} (complement, not an image that is the complement of R _{U} set of pixels), called R _{U} in all points of the image **foreground** (foreground), R _{U }^{C} all of The **background of the** dot image .

The R region **boundary** (boundary, also referred to as **an edge** (border) or **contour** (Contour)) is a collection of a number of such points, these points R and the point adjacent to complement certain concentration (Adjacent), i.e. in the region of the boundary region There is at least one set of pixels adjacent to the background point (here, the adjacent old ape is understood as the gray value of the entire image as an 8-adjacent set). This is called a boundary region **within the boundary** (inner border), corresponding thereto has **an outer boundary** (outer border), i.e. outside the boundary area complement region (background) inner boundary. The outer boundary forms a closed path around the area.

If the region R is the image itself, the boundary in this case is defined as the set of pixels in the first row, first column, and last row and last column of the image.

### 3. Summary of Knowledge: Distance Measures

#### 3.1. Definition

For pixels p (x, y), q (s, t), z(v, w) and function D, if it satisfies:

- D(p,q)≥0[D(p,q)=0 if and only if p=q]
- D(p,q)=D(q,p)
- D(p,z)≤D(p,q)+D(q,z)

Then the function D is a **distance function or metric** (distance function or metric).

#### 3.2 Euclidean distance

Euclidean distance is a distance metric. The **Euclidean distance** (Euclidean distance, referred to as Euclidean distance ) between p (x, y) and q (s, t) is defined as:

This formula fully satisfies the distance metric Definition.

*For Euclidean distance,* the pixel whose distance from the point (x, y) is less than or equal to r is a circular plane with (x, y) as the center and r as the radius.

#### 3.3, D _{4} distance

The D _{4} distance (D _{4} distance, also known as city block distance ) between p (x, y) and q (s, t) is defined as follows:

`D4（p,q） = |x-s|+|y-t|`

This formula completely satisfies the definition of distance metric, so it is also a distance metric.

The pixels whose distance from the point (x, y) D4 is less than or equal to r form a diamond with the center at the point (x, y). For example, pixels with D4 distance equal to 1 constitute the 4 neighborhood of the center point, and pixels with D4 distance less than or equal to 2 are similar to the following contour:

```
2
2 1 2
2 1 0 1 2
2 1 2
2
```

#### 3.4, D _{8} distance

The D _{8} distance (D _{8} distance, also known as chessboard distance ) between p (x, y) and q (s, t) is defined as follows:

`D8（p,q） = max(|x-s|,|y-t|)`

This formula also fully meets the definition of distance metric, so it is also a distance metric.

The pixels whose distance from the point (x, y) D8 is less than or equal to r form a `2r+1`

square whose center is at the point (x, y) . The pixel whose D8 distance of point (x, y) is 1 is the 8-neighborhood of point (x, y).

### Four, summary and perception

This article introduces the neighborhood relationship of pixels in the image. The neighborhood relationship is defined based on the set of limited gray values. The path between pixels can be constructed through the neighborhood, and the connected relationship and connected set between pixels are constructed based on the path. And further define the area and boundary of the image.

If a function satisfies the definition of a distance measure between image pixels, then the function is a distance function or distance measure. Common distances include Euclidean distance, D _{4} distance, and D _{8} distance.

Through the introduction of these contents, everyone can understand the neighborhood, adjacency, connection relationship between pixels, as well as the definition of regions and boundaries, and understand the distance calculation methods for different distance measures between pixels.

The content introduced in this article is the relationship between pixels. Through these definitions, we can understand the concepts of neighborhood, adjacency, connectivity, area and boundary. Before learning, the old ape may have a vague feeling about this knowledge, but the real definition is not known at all. These concepts are very important for understanding image processing.

In addition, the translation of the Chinese version of "Digital Image Processing" is still not well done. If you are not familiar with image processing and review it carefully, you can understand these situations. Related translation issues have been marked in italics in the text, and some places have been explained separately, I hope it will be helpful to everyone.

**For more image processing, please refer to the introductions in the columns** " OpenCV-Python Graphics and Image Processing " and " Basics of Image Processing ".

For those who lack Python foundation, you can learn Python from scratch through Lao Yuan’s free column " Column: Python Basic Tutorial Directory ".

###### Blogging is not easy, please support:

If you have gained something from reading this article, please like, comment, and bookmark. Thank you for your support!

### Paid column about the old ape

- The paid column " https://blog.csdn.net/laoyuanpython/category_9607725.html Using PyQt to Develop Graphical Interface Python Applications" specifically introduces the basic tutorials of Python-based PyQt graphical interface development. The corresponding article directory is " https://blog.csdn .net/LaoYuanPython/article/details/107580932 Use PyQt to develop a graphical interface Python application column directory ";
- The paid column " https://blog.csdn.net/laoyuanpython/category_10232926.html moviepy audio and video development column ) details the related methods of moviepy audio and video editing and synthesis processing and the use of related methods to process related editing and synthesis scenes, corresponding to the article The directory is " https://blog.csdn.net/LaoYuanPython/article/details/107574583 moviepy audio and video development column article directory ";
- The paid column " https://blog.csdn.net/laoyuanpython/category_10581071.html OpenCV-Python Difficult Questions for Beginners " is " https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python graphics and image processing "The companion column" is an integration of the author’s personal perceptions of some of the problems encountered in the learning of OpenCV-Python graphics and image processing. The relevant information is basically the result of repeated research by the old ape, which helps OpenCV-Python beginners to more in-depth To understand OpenCV, the corresponding article directory is " https://blog.csdn.net/LaoYuanPython/article/details/109713407 OpenCV-Python Beginners Difficult Question Collection Column Directory "
- The paid column " https://blog.csdn.net/laoyuanpython/category_10762553.html Introduction to Python Crawlers" introduces the content of crawler development from the perspective of an Internet front-end developer, including the basic knowledge of crawling Take CSDN article information, blogger information, like articles, comments and other actual content.

The first two columns are suitable for novice readers who have a certain Python foundation but no relevant knowledge to learn. The third column, please combine " https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python graphics and image processing " Learning to use.

For those who lack Python foundation, you can learn Python from scratch through Lao Yuan’s free column " https://blog.csdn.net/laoyuanpython/category_9831699.html column: Python basic tutorial directory ).

If you are interested and willing to support the readers of the old ape, welcome to buy the paid column.