# An Improved Method for Evaluating Image Sharpness Based on Edge Information
## 2 Principle and Design of the Sharpness Evaluation Method
### Analysis of Edge Width
#### 2.3.1 Determination of Edge Direction  
[PERSON] et al. [16] calculated the gradient of each edge point in the measured image by a Sobel operator and defined the gradient direction (including the negative direction of the gradient) as the edge direction of that edge point. Different from the idea of using a gradient to determine the edge direction, this paper proposes a method based on the difference of a grayscale between the pixel points in the eight neighborhoods of the edge  
Figure 4: Improved Lena edge detection diagram.  
Figure 3: The principle of an improved Canny edge detection algorithm: (**a**) edge detection result under a high threshold; (**b**) edge detection result under a low threshold; (**c**) edge detection result after initial activation; (**d**) edge detection result after multiple activations; (**e**) final edge detection result.  
points. Compared with the gradient determining method, this method not only improves the accuracy of determining the edge direction but also saves twice the computational time.  
Figure 5 illustrates the calculation principle of the eight-neighborhood grayscale difference method. For each edge point (\(\text{G}_{\text{Edge}}\) denotes an edge point in the figure below), the four grayscale differences of its eight-neighborhood pixel points are calculated along the horizontal, vertical, \(45^{\circ}\), and \(-45^{\circ}\) directions, respectively, namely:  
\[\begin{array}{c}D_{\text{horizontal}}=\text{ABS}(G_{12}-G_{32})\\ D_{\text{vertical}}=\text{ABS}(G_{21}-G_{23})\\ D_{45^{\circ}}=\text{ABS}(G_{31}-G_{13})\\ D_{-45^{\circ}}=\text{ABS}(G_{11}-G_{33})\\ \end{array} \tag{1}\]  
The opposite direction of the direction corresponding to the minimum value of the four differences in the above equations is the edge direction obtained by this method. For example, the opposite direction of the horizontal direction is the vertical direction, and the opposite direction of the \(45^{\circ}\) direction is the \(-45^{\circ}\) direction.  
The following figure shows the effect of determining the edge direction of the Lena test image using the gradient determining method in reference [14] and the eight-neighborhood grayscale difference method in this paper, respectively. The results of the gradient determining method for determining the edge directions of the edge points (where the pentagrams are located) in Figure 6a-d are the vertical direction, vertical direction, horizontal direction, and vertical direction, respectively. Accordingly, the edge direction determination results of the eight-neighborhood grayscale difference method are \(-45^{\circ}\) direction, horizontal direction, vertical direction, and \(-45^{\circ}\) direction, respectively. It is thus clear that the determination results of the edge direction by the eight-neighborhood grayscale difference method are more realistic and accurate.  
In addition to comparing the accuracy of the above two methods, this paper further compares the computational time of the gradient determining method and the eight-neighborhood grayscale difference method by calculating four images with typical edge directions.  
We performed the gradient determining operation on the four images in Figure 7 in Visual Studio 2019 using C++ under the Windows 10 operating system, and the average processing time was 10 ms per image, while the average processing time was 3 ms per image for the eight-neighborhood grayscale difference operation on the four images. It can be seen that the eight-neighborhood grayscale difference method proposed in this paper  
Figure 5: Eight-neighborhood grayscale difference method.  
can quickly and efficiently determine the edge direction of each edge point, which creates the condition for accurate calculation of the edge width in the next step.