Multidirectional Gradient Neighbourhood-Weighted Image Sharpness Evaluation Algorithm

Academy of Digital Arts, Xi’an University of Posts and Telecommunications, Xi’an, Shaanxi 710121, China Institute of Education, Shaanxi Normal University, Xi’an, Shaanxi 710062, China School of Computer Science and Technology, Xi’an University of Posts and Telecommunications, Xi’an, Shaanxi 710121, China School of Electronic Information, Northwestern Polytechnical University, Xi’an, Shaanxi 710129, China


Introduction
With the rapid development of digital image technology, as a core link of photoelectric systems, autofocus technology becomes an indispensable tool for obtaining clear images in a modern high-speed information society, which affects the image quality of imaging and the effectiveness of subsequent image algorithms [1][2][3].
e sharpness evaluation function is a core part of autofocus technology. At present, mainstream algorithms for evaluating the sharpness of an image include spatial domain evaluation algorithm, transform domain evaluation algorithm, and statistical evaluation algorithm [4][5][6]. Spatial domain evaluation function makes use of images' features in the spatial domain to distinguish blurred images and clear images. Because the function directly calculates the gray value of the image pixels, the amount of calculation is less and the calculation speed is faster [7][8][9]. However, due to the fact that the edge and contour of an object is complex and changeable, the spatial evaluation function only detects the horizontal and vertical gradients of images, which cannot detect the complex edge contour accurately [10]. Bi et al. [11] proposed a spatial domain evaluation function based on HSV weighting, with a strong ability of evaluating the automatic focus control of the embedded real-time optical measurement platform efficiently. Zhang et al. [12] proposed an improved Brenner sharpness evaluation function. Compared with the gray gradient evaluation function, this evaluation function maintains the unimodality and validity of the evaluation curve under Gaussian noise. It is particularly applicable in the fast-focusing occasion, but the practicability in complex noise environments remains to be tested. Li et al. [13] proposed a sharpness evaluation algorithm that uses sharpness evaluation factors to modify the detection results of the Laplace operator. Under high-noise circumstance, this algorithm can attain fast and good evaluation results, but in some special scenes, the running time of denoising is longer, and the evaluation speed of sharpness is slower. Liu et al. [14] proposed an image sharpness evaluation algorithm based on curve fitting and probabilistic model theory. Although this method effectively improves the limitation that one focusing function is only applicable for one certain type of images, it costs too much system runtime to achieve higher accuracy. When the curve's fitting parameters are complex, the system requires a lot of running time.
According to the analysis of aforementioned image sharpness evaluation functions, aiming at the situation that the edge contours of actual objects in the photoelectric system are complicated and changeable, the image sharpness evaluation is greatly affected by noise. is paper performs multiscale transformation of the input images, introduces multidirectional gradient calculation on the basis of the spatial evaluation function, and obtains accurate image edge contours. From the perspective of optical imaging point diffusion principle, using the correlation among image pixels, combining image gradients, a multidirectional gradient image sharpness evaluation algorithm associating with neighbourhood correlation is proposed.

Qualitative Evaluation
Criteria. An excellent image sharpness evaluation function should have an evaluation curve with good performance. e ideal digital image focus curve is shown in Figure 1.
It can be seen from Figure 1 that the ideal focus curve has a single peak, and the peak is the best clear image [15][16][17]. In the actual applied process, there exist many interfering factors (such as the vibration of the motor in the photoelectric system). e captured images have noise due to environmental factors, and it may fluctuate up and down in the out-of-focus area, or even multipeak may appear [18][19][20].

Quantitative Evaluation Criteria.
e qualitative evaluation of image sharpness can roughly judge the pros and cons of the evaluation algorithm, but when the performance of the algorithm is close, the performance of an algorithm cannot be intuitively judged through qualitative evaluation. erefore, a specific quantitative index is needed to reflect an algorithm's merits and demerits.
is paper uses five standards [21][22][23] unified by industry research to quantitatively evaluate the sharpness function of the images. e schematic diagram of the quantitative evaluation standard for the sharpness evaluation function is shown in Figure 2.
In Figure 2, the vertical axis is image sharpness evaluation value, and it is recorded as the FV value; the horizontal axis is the focus motor position, and the value is Z; e maximum extreme value of its focus curve is recorded as point P(Z max , FV max ).

Criterion 1: Steepness Width.
e numerical characteristics of the focus curve are divided into steep areas and flat areas, and the flat areas of the focus curve are subdivided into left flat areas and right flat areas. e coordinates of the left and right critical points of the steep area are P l (Z lcp , FV lcp ) and P r (Z rcp , FV rcp ), and the distance between the critical points is defined as the width of steep area W s as shown in the following equation:  resolution capability is needed to accurately evaluate the evaluation function. e equation is expressed as where S represents the steepness of the sharpness evaluation function (i.e., the steepness of the focus curve), FV max represents the maximum value of the focus curve, FV min represents the minimum value of the focus curve, and W s represents the width of the steep region of the focus curve.

Criterion 3: Flat Area
Fluctuation. e amount of fluctuation in the flat area can be measured in the form of standard deviation, and the amount of fluctuation in the flat area can be expressed as where FV f represents the fluctuation of the smooth area of the sharpness evaluation function, FV standard represents the standard deviation of the smooth area of the focus curve, FV i represents the value of a single sampling point, and FV p represents the average value of all sample points.

Standard 4: Sensitivity.
Sensitivity can be expressed as where FV sen represents the sensitivity of the sharpness evaluation function, ΔFV represents the reduction of focus value, and FV max represents the maximum value of focus value. e evaluation algorithm with higher sensitivity is more favorable for peak search.

Criterion 5: Average Calculation Time.
e average calculation time is the average time taken by the sharpness evaluation function to process one frame of the image in the image sequence.

Proposed Methods
According to Wiener-Khinchin's theorem [24], two effects of the correlation function are used. First, the gradient function is weighted by the correlation performance generated by defocus blur, distinguishing blurred images and clear images more clearly, and enhances the steepness of the focus curve. Second, correlation is an inherent property of an image. Because there is a certain relationship among pixel content and there is no correlation between noisy pixels and content pixels, the correlation of the pixel content can be used to remove the effect of noise.

Multiscale Transformation of Images.
In recent years, researchers have proposed many effective image multiscale decomposition tools. Compared with curvelet transform and contourlet transform, non-subsampled shearlet transform (NSST) has a parabola scale, and its direction sensitivity is stronger and optimum sparseness [25][26][27]. During the sampling process, NSST avoids losing images' information and has stability as well as translation invariance. erefore, NSST is very suitable for expressing detailed information of an image such as contours, textures, and edges.
According to synthetic wavelet theory, when the decomposition dimension n � 2, the affine function of the shear wave can be expressed as where a, b ∈ Z, c ∈ Z 2 , y ∈ L 2 (R 2 ), L represents an integrable space, M and N are second-order invertible matrices, M a represents a scale transformation matrix, N b represents a geometric transformation matrix, and |detN| � 1.
When T MN (y) satisfies the Parseval framework, the synthetic wavelet (element in the function system) can be expressed as and N � 1 s s 1 , the shearlet change system can be expressed as where d, e, and g are three parameter variables in the shearlet transform system. d is the size of the image, e is the cutting direction, and g is the translation amount. Different images' details are obtained by setting these three parameters.
Shearlet is a multiresolution and multidirectional transformation system. It is a nondownsampling transformation method of NSST. It uses nondownsampling pyramid filters to scale and filter low-frequency approximate images and high-frequency detailed images. e size of each decomposition image is the same as the original input image.

Multidirectional Gradient Calculation.
e multidirectional gradient calculation is performed on the lowfrequency approximate image and the high-frequency detailed image. e gradient of each direction of the image center pixel is shown in Figure 3.
In Figure 3, the gradient vectors of the four directions of the central pixel Z 5 are (Z 1 , Z 9 ), (Z 2 , Z 8 ), (Z 3 , Z 7 ), and (Z 4 , Z 6 ). g � pixel gray level difference/distance of adjacent pixels, and calculate the gradient of the central pixel Z 5 as shown in the following equation: In equation (8), G x , G y , G xy , and G yx correspond to (Z 1 , Z 9 ), (Z 2 , Z 8 ), (Z 3 , Z 7 ), and (Z 4 , Z 6 ) vector magnitude, and the distance between adjacent pixels adapts the European formula.
e gradient values of the four directions of the central pixel are added to the entire image matrix, and the gradient calculation formula of the entire image matrix is obtained as

Numerical Calculation of Image Sharpness Evaluation.
For each center pixel, find the cross-correlation value of neighboring pixels. First, calculate the average gray value of neighboring pixels. e calculation formula is + I(x, y − 1) + I(x, y + 1) + I(x + 1, y − 1) en, find the cross-correlation value of the pixels to this average. In order to ensure that the cross-correlation value of every pixel is less than 1, the mathematical mean inequality a 2 + b 2 ≥ 2ab is used to obtain equation (11) for calculating the cross-correlation.
e correlation value is small in clear images, but it is large in defocused images, which has the opposite effect to the expression of the image gradient value. erefore, the absolute value (|1 − f corr |) of the difference between the cross-correlation value and 1 is taken as the weighting coefficient. e final calculation formula is shown in the following equation: e final evaluation value F can be expressed as where F value H represents the evaluation value of highfrequency detail images and F value L represents the evaluation value of low-frequency approximate images.
Under the effect of correlation weighting on image gradients, the proportion of large gradient values increases and the proportion of small gradient values decreases, which further highlights the difference between clear images and blurred images and improves sensitivity. At the same time, the characteristics of the correlation itself are used to reduce the sensitivity of the gradient to noise and improve the noise resistance.

Experimental Platform.
e experimental hardware platform used in this paper is CPU Intel Core I7, CPU clock speed 2.20 GHz, RAM 4G, OS: 64 bit Windows. e experimental software platform is MATLAB 2018b.
In order to verify the effectiveness of the proposed method for evaluating image sharpness, this paper used a certain type of photoelectric system to collect an image sequence as the image sequence which has a real noisy environment. e total number of frames of this image sequence is 461 frames, and the resolution is 640 × 512, as shown in Figure 4. e algorithms used for qualitative and quantitative analysis include gray variance evaluation algorithm, Brenner evaluation algorithm, Roberts evaluation algorithm, Prewitt evaluation algorithm, Laplace evaluation algorithm, Tenengrad evaluation algorithm, Vollath evaluation algorithm, entropy function evaluation algorithm, Fourier transform evaluation algorithm, discrete cosine transform (DCT) evaluation algorithm, and wavelet transform evaluation algorithm.

Qualitative Analysis Results.
In order to guarantee the computational efficiency of the image sharpness evaluation algorithm, this paper evaluated only 1⁄ 4 of the central area in the image. Due to the large amount of image data and many curves, in order to better observe the curve of the evaluation of sharpness, all the experimental results are divided into two groups to display, six kinds of the results per group. e final comprehensive result is shown in Figure 5.
It can be seen from Figure 5 that the overall performance of gray variance evaluation algorithm, DCT transform evaluation algorithm, and entropy function evaluation algorithm curve is poor, the focus curve is less distributed in the flat area, and the whole shows a floating state, which has a large gap compared with other curve trends. ese three evaluation algorithms are not suitable for sharpness evaluation in practical applications. Laplace evaluation algorithm can be clearly seen that there are more jitters and a lower signal-to-noise ratio. Because its own second-order differential amplifies gradient and enhances noise, it is very sensitive to noise. e gradient-based sharpness evaluation algorithm is generally consistent with the focus curve trend, but it can be clearly seen that the proposed method in this paper has a better curve trend and a better unimodality, as well as a smooth flat region.

Quantitative Analysis Results.
In order to apply to the focus curves of different evaluation functions, the left and right critical points of the focus curve are selected by where FV max is the maximum focus value of the focus curve, FV min is the minimum focus value, FV i is the focus value of a single sampling point, and α is a coefficient, and this paper takes α � 0.1. e sampling points on the focus   (14) is set to the right critical point. e results of quantitative analysis based on the five quantitative evaluation criteria are shown in Table 1.
It can be seen from Table 1 that Roberts, Brenner, and the proposed method have a relatively smaller width of the steep region compared with other methods, and the width of the steep region of the proposed method is the smallest. erefore, compared with other methods, the proposed method has a higher steepness; in the aspect of flat area fluctuation, this method does not have a clear superiority contrasted to Brenner, but it has obvious advantages when compared with other methods, indicating that the proposed method has a better antinoise performance in the flat area; and in terms of sensitivity, the proposed method has a higher sensitivity in the peak region and is sensitive to image outof-focus state. Finally, the average calculation time of the proposed method is longer than other gradient evaluation algorithms.

Conclusion
Aiming at the problem that the image sharpness evaluation algorithm in the photoelectric system runs slowly in actual processing and is seriously affected by noise, this paper proposes a sharpness evaluation algorithm based on multidirectional gradient function neighbourhood weighting, which combines multiscale transformation tools and gradient neighbourhood weighting operators to effectively evaluate the image sharpness. First, NSST is used to perform multiscale transformation on the images to obtain high-frequency detail images and low-frequency approximate images. Second, multidirectional gradients on high-frequency images and low-frequency images are calculated, and the calculation results are weighted in conjunction with neighbourhood correlation. Finally, the ratio of high-frequency images and low-frequency images weighted results is used as the evaluation value for the sharpness evaluation function. is paper selects a certain type of photoelectric system acquisition image sequence as the image sequence of the noisy real environment and implements different evaluation functions of sharpness on the MATLAB experimental platform to compare with the proposed method.
rough the intuitive evaluation analysis and quantitative evaluation analysis of the focus curve, the proposed sharpness evaluation algorithm has better unimodality. In contrast with the current mainstream image sharpness evaluation algorithms, the proposed method has a better performance in terms of sensitivity and flat area fluctuation, but it still needs to be improved in terms of running time.

Data Availability
e image data used to support the findings of this study are included within the supplementary information file.

Conflicts of Interest
e authors declare that there are no conflicts of interest regarding the publication of this paper.