Fast Blind Deblurring of QR Code Images Based on Adaptive Scale Control

With the development of 5G technology, the short delay requirements of commercialization and large amounts of data change our lifestyle day-to-day. In this background, this paper proposes a fast blind deblurring algorithm for QR code images, which mainly achieves the effect of adaptive scale control by introducing an evaluation mechanism. Its main purpose is to solve the out-of-focus caused by lens shake, inaccurate focus, and optical noise by speeding up the latent image estimation in the process of multi-scale division iterative deblurring. The algorithm optimizes productivity under the guidance of collaborative computing, based on the characteristics of the QR codes, such as the features of gradient and strength. In the evaluation step, the Tenengrad method is used to evaluate the image quality, and the evaluation value is compared with the empirical value obtained from the experimental data. Combining with the error correction capability, the recognizable QR codes will be output. In addition, we introduced a scale control parameter to study the relationship between the recognition rate and restoration time. Theoretical analysis and experimental results show that the proposed algorithm has high recovery efficiency and well recovery effect, can be effectively applied in industrial applications.


Introduction
As collaborative computing and general technology such as the Internet of Things (IoT) and information technology evolved, it provides an environment where people can share information without being restricted by space and time. Through the Internet, it is possible to collaborate effectively with anyone, anytime, and anywhere [1]. As the main entrance of the mobile Internet, two-dimensional barcodes are widely used in commodity payment, public security, financial insurance, and other fields due to their large storage capacity, wide application range, and strong sharing capabilities. Quick Response (QR) code, as the most common two-dimensional bar codes, has the advantages of low cost, easy production, durability, and so on [2][3][4]. However, in real life, out-of-focus blurred QR code images are often collected due to imaging problems such as lens shake, inaccurate focus, and optical noise. The ubiquitous image degradation usually leads to difficulties in QR code extraction and identification. In the era of commercialization, especially driven by 5G technology, people have higher requirements for the speed of information acquisition. This is why the fast deblurring of QR code images has become a research focus at this stage, especially in industrial applications [5], such as the traceability of salt, food, and medicine in Fig. 1. When an out-of-focus blurred QR code image is acquired, the deblurring algorithm will be used. Its main purpose is to restore the damaged image to the greatest extent by improving the signal-to-noise ratio after a series of processing on the damaged or degraded image. Traditional image restoration assumes that the image degradation function has been given, that is, the blur kernel is known. But in real life, the blur kernel is usually unknown, and the image can only be restored by obtaining the prior image, so as to achieve the effect of blind deblurring.
In recent years, a series of studies have been carried out in the field of blind deblurring at home and abroad. Aiming at the blind deblurring of the binary images, which are similar to the QR code images, Zoran et al. [7] presented a general framework for calculating MAP estimates, showing how to derive an appropriate cost function, how to optimize it, and how to use it to return for the entire image. This framework has made a huge contribution in the field of blind deblurring. The more complex the image is, the better the deblurring will affect. But it pays more attention to details, so it is difficult to eliminate the ringing effect. Pan et al. [8,9] proposed a simple but effective L 0 -regularized text and beyond deblurring algorithm based on the intensity and gradient priors. Compared with the existing blind deblurring algorithms, this algorithm does not need any complicated filtering strategy to select the edge, and can be applied to debluring the low-illumination images. In addition, this algorithm is easy to understand and realize, but the multi-scale iterative estimation method adopted is too redundant to take a long time. On the basis of Pan's algorithm, Liu and Du et al. [10] introduced the binary feature of QR codes to construct a new constraint term to achieve double-layer constraints on QR images and have excellent effects on common blurred kernels and multiple noises. This algorithm is efficient than the traditional algorithm but still does not solve the speed problem of blind deblurring. Nah et al. [11] realized the deblurring of dynamic scenes through the simulation of multi-scale loss function based on a multi-scale convolutional neural network.
However, a large number of training samples and training time are the disadvantages of this algorithm. Bai et al. [12] proposed a graph-based blind image deblurring algorithm by interpreting an image patch as a signal on a weighted graph. This algorithm can deal with various blind image deblurring scenarios, and the reconstructed sharp results are better than the state-of-the-art methods visually and numerically. A common disadvantage is that the algorithm is not ideal for more obscure ones. Based on the Pan's, Wen et al. [13] proposed a novel algorithm with a simplified sparsity prior of local minimal pixels (PMP) rather than directly using the half quadratic splitting algorithm. This algorithm can improve the practical stability and computational efficiency substantially, and have a certain improvement in speed.
We note that, blind image deblurring is an ill-posed problem, so it is difficult to find an effective and universal solution. However, fortunately, the main processes of the existing blind deblurring algorithm based on L 0 regularization is multi-scale iteration, image estimation, and blurred kernel estimation, which can effectively solve this problem. In this paper, we propose a fast blind deblurring algorithm for QR code images because of the slowness of the existing blind deblurring algorithms in the multi-scale iterations. A large number of experiments show that this method can effectively implement  [6] adaptive scale control, which greatly improves the speed of the blind deblurring algorithm. The remainder of this paper is organized as follows. Section 2 briefly reviews the related work on image deblurring and image quality evaluation. Section 3 presents the proposed Algorithm through analysing the evaluation mechanism and the idea of adaptive scale control. Section 4 is the overall process of the algorithm in this paper. In this section, we elaborate the procedure of the  algorithm by three main parts, multi-scale division, image estimation, and blurred kernel estimation. Section 5 shows the experimental results and finally Section 6 concludes the paper.

Related work
Generally, image restoration technologies can be coarsely divided into two categories. One is the non-blind deconvolution algorithm. The algorithm refers to the deconvolution processing on the basis of the image blur mechanism and the point spread function (PSF). The other is the blind deconvolution algorithm. When the PSF is not known, the PSF and the original clear image need to be estimated according to the prior knowledge of the blurred image, which is an ill-posed problem. In the aspect of image quality evaluation, according to whether there are reference images, full reference, semi-reference, and no-reference are the main methods for objective evaluation of image quality. The full reference image   The third version of QR code image evaluation method works best, and its premise is that the original reference image can be found. But in general, the reference image is difficult to obtain. The semi-reference image evaluation method is generally used when the complete reference image information cannot be obtained, or only the information of the reference image is extracted. This method often uses features of extraction and comparison to evaluate the image clarity. However, this paper uses the no-reference image quality method, which can directly estimate the clarity of the image by using certain characteristics of the image without reference images. It is not as effective as full reference and semi-reference, but it meets the needs of actual life and has higher practicality. In the following, we only briefly review the previous work closely related to out-of-focus image deblurring and image quality evaluation.

Image Deblurring
Many previous methods introduce complex image priors and regard blind image restoration as a joint optimization problem by penalizing image blurriness and promote image sharpness. For example, L 0 -norm based priors [8][9][10], dark channel prior [14], low-rank prior [15], graph-based prior [12], multi-scale latent structure prior [16], local maximum gradient prior [17] and deep priors [18], etc. These methods can effectively reduce the ill-posed of blind image restoration algorithms, but they are usually computationally expensive. The fundamental reason is mainly through the calculation of any non-convex prior with a large amount of calculation, which leads to complex optimization algorithms. What's more, the parametric assumptions on blur kernels could greatly improve the robustness of blind image deblurring [19,20], a principled algorithm within the maximum a posterior framework to tackle image restoration with a partially known or inaccurate degradation model [21], and other deep learning and other methods that contain a large number of real image sets and training sets using self-supervised methods [22][23][24][25][26], the characteristics of training data sets are often It will greatly affect the performance of the entire model, and in many cases, the construction and processing of data sets are often very expensive and low feasibility.

Image quality evaluation
When an image is blurred or out of focus, it loses the details of the edges. Consequently, it is necessary to apply a nonreference image definition evaluation method with high sensitivity to the gradient in real life. The common reference image evaluation methods are the image histogram method, variance method, Tenengrad method, Laplacian method, fast Fourier transform method, grey variance method, histogram entropy method, and local histogram method [27]. In recent years, the Kang & Park method [28], X-ray tomography [29], StyleGAN [30] etc. are used to analyse and improve image sharpness. The disadvantage of high image sharpness is usually cost, because it requires more expensive systems and longer scan times. Therefore, the traditional Tenengrad method is adopted in this paper. This method not only can reduce the occurrence of local extremum after selecting a certain threshold [31], but also has good sensitivity and accuracy [32,33]. It is a common image clarity evaluation function based on gradient. In image processing, the edge pixel grey of QR code images in ideal state changes faster, that is, the value of gradient function is larger, while the edge pixel grey of blurred QR code images changes more smoothly, and the gradient is smaller.

The proposed algorithm
In this paper, a classic statistical method is used. Under the guidance of collaborative computing, an evaluation mechanism is introduced. That is, the effective boundary values of different scales and the recognition rate and average calculation time under the control of different scales are calculated and analyzed, so as to realize adaptive scale control, which is a fast blind deblurring thought to Section 4. This section shows what is the evaluation mechanism and how to implement adaptive scale control based on theoretical and experimental analysis.

Evaluation mechanism
To study the adaptive scale control to shorten the time of the blind deblurring algorithm of QR code images, the value of image clarity plays a very important role in the entire algorithm. In this paper, the Tenengrad method is used for image edge detection calculation, using the Sobel horizontal and vertical operators to find the gradient and intensity of the image [27] as follows: The gradient boundary value of the image is defined as In Eq.
, T is the given edge detection threshold, n is the total number of pixels. After the average grey value of the image is processed by the Sobel operator, the larger value is, the sharper image will be. This paper uses the Zxing software package to evaluate the clarity of each QR code before deblurring. The results are shown in Fig. 2. It can be obtained that the Tenengrad method has a good performance on QR code image clarity evaluation. The larger defocus blur radius is, the more blurred will image be. This method can well represent images which have sharp edges. For the QR code images with different degrees of blur, their recognition can be distinguished according to the boundary value. To obtain the boundary value accurately, in this paper, we select QR code images of three different contents for each version to simulate 300 blurred images with a blur radius of [0.05,15]. It can be seen from Fig. 2 that there is a certain relationship between the recognizability of QR code and Tenengrad value, which can be used as an indicator to judge whether the QR code images can be recognized. According to the statistics of the experimental results, for QR code images with the same version but different contents, the recognition boundaries are also similar. The boundary defocuses ratio B of the 1-5 version of QR codes are about B1 = 9.1, B2 = 8.9, B3 = 6.75, B4 = 5.5, and B5 = 4.9. After that, to improve the accuracy of the boundary value, we shorten the different lengths and deblur the images by adding and subtracting 0.02 defocus ratio. Therefore, we obtain the effective boundary values (Q) at different scales under different versions as shown in Table 1. After obtaining Q, we can get the average boundary value (Q max ) of different versions, which is the evaluation mechanism proposed in this paper, as shown in Table 2. Table 2 is the average value of Table 1. It can be seen from Table 2 that the evaluation value becomes larger with the increase of scale or version relatively.
As we all know, QR codes have certain error correction capabilities, and the higher version, the more stored content. Besides, the chosen error correction level and the type of encoded data influence capability [2]. It can be obtained through large quantities of experiments that the deblurring intervals of 1-5 version can be r o u g h l y s e t a s I 1 ∈ [ 9 . 1 , 1 2 . 2 ] , I2 ∈ [8.9,11.8],I3 ∈ [6.75,11.35], I4 ∈ [5.5,11.1] and I5 ∈ [4.9,9.95]. Since image deblurring requires six scale iterations, we introduce the scale control parameter p (p ∈ [0, 5]) to improve the accuracy of the algorithm in this paper. p (p ∈ [0, 5]) indicates that each blurred image abandons the previous p scale comparisons during the scale iteration process, and further compares recognition rate of QR codes. After that, we randomly generate the QR code sample libraries in these intervals, and obtain the recognition rate R and deblurring time T from the identifiable images as shown in Table 3. From Table 3, the relationship between R and T can be obtained under the same p. As p increases, R and T also increase, and the larger p, the longer time required for adjacent scales. That is while improving the deblurring speed of the QR code images, it lost a certain recognition rate.

Adaptive scale control
QR codes have the ability to read at high speed and support error correction processing. That is, when the QR code image is normalized and the multi-scale iterative deblurring operation is performed, it has the recognition ability before the next scale iteration. Based on this feature of the QR code images, this paper makes a  [8,34,35]). It can be clearly seen that as the number of iterations increases, the QR codes become clearer gradually, but the blurred QR code image already has the ability to recognize before the number of iterations ends. This is because the QR code has a certain error correction rate, and can be recognized when the image is not optimal. Based on the aspect of QR codes, this paper introduces the Tenengrad method based on the existing blind deblurring algorithms, which realizes adaptive scale control of QR code images, thereby improving the speed of the blind deblurring algorithm.

Fast blind deblurring algorithm
Based on the existing blind deblurring algorithms [8,9,[34][35][36][37] and the evaluation mechanism [9,27,28,30,31,38], this paper proposes a fast blind deblurring algorithm for QR code images based on adaptive scale control. Firstly, we uniformly normalize the input QR code images. After that, the images are obtained by multi-scale division, image estimation and blurred kernel estimation algorithm. Finally, a Tenengrad evaluation function was introduced to obtain the empirical value. The image normalization is normalized into a 300 × 300 matrix without damaging any information of the image. Multi-scale division, that is, the image is divided into multiple scales for deblurring operation. The blurred kernels estimated at each scale will be up-sampled to the next scale and used as the next input, and finally obtain a clear QR code image. Image estimation is to deconvolve the blurred kernels and blurred QR code images, then predict clearer QR code images. Blurred kernel estimation is to use the clearer QR code images and blurred image obtained in the previous step as input, and obtain a more accurate blurred kernel finally. When the maximum number of iterations is reached, the Tenengrad method will be used. We use this method when the original reference image cannot be found, and rely on gradient features of the image to directly estimate the clarity of the image. This method firstly obtains empirical values of QR code images by a large number of experimental statistics. After that, each experimental object was evaluated. Last but not least, the numerical value Q generated by evaluation was compared with empirical value Q max before deblurring operation on each scale. If Q > Q max , the QR code under this scale can already be identified, and no further operation is required to achieve the adaptive scale effect of blind deblurring. The overall flow of the algorithm is shown (see Fig.9). The proposed algorithm will be analyzed and calculated from three main parts, that is, multiscale division, image estimation and blurred kernel estimation.

Multi-scale division
The multi-scale division algorithm firstly unifies the input blurred QR code image y into a 300 × 300 matrix and the blurred kernel k into a 31 × 31 matrix. Then, we refer to Cho's idea [36], a coarse-to-fine scheme, when estimating the latent image and blurred kernel. When the QR code image is at the coarse scale, it will initialize k and down-sample y, and then estimate image and blurred kernel. Each scale has five iterative optimizations of k. After obtaining the estimated value of k, it will be up-sampled to the next scale level by bilinear interpolation, and then execute the estimation operation and down-sample the blurred image y. The scale division formula is as follows (see (3) and (4)): In Eqs. (3) and (4), r ¼ ffiffiffiffiffiffi ffi 0:5 p , d represents the number of scale divisions, k d is the estimated blurred kernel size, k l is the divided blurred kernel scale. For a 31 × 31 matrix-size blurred kernel and a matrix size (300 × 300) QR code image, after multi-scale division and downward rounding, we get 6 different scales. The sizes of blurred kernels are 7 × 7, 9 × 9, 11 × 11, 17 × 17, 23 × 23, 31 × 31 from the coarse-to-fine scheme. The image will also be down sampled to 52 × 52, 74 × 74, 105 × 105, 148 × 148, 211 × 211 and 300 × 300. y l is the image after division.

Image estimation
Taking the first version as an example, the QR code image is a binary image, which has a strong contrast for its background is white and the module is black. Compared with the text image, the module of the QR code image is a whole square. For clear images, their values are distributed between 0 and 255 in terms of intensity (see Fig.10(b)). On the contrary, the blurred image is distributed with a large number of non-zero values, and there are very few values where the pixel intensity is zero (see Fig.11(b)). In terms of image gradient, the image pixel gradient feature performs well for suppressing artifacts in QR codes, that is, in nonedge regions, the gradient is zero, and between black and white modules, the number of zero is relatively rare (see Fig.10(c) and Fig.11(c)). The intensity and gradient distribution of QR code images with different blurred degrees are similar. Therefore, the prior of QR code image blind deblurring can be defined as: In Eq. (5), σ represents the weight. P t (∇x) describes the QR code image gradient andP t (∇x) = ||∇x|| 0 ; P t (x) describes the intensity characteristics of the QR image, and P t (x) = ||x|| 0 , where ||x|| 0 represents L 0 -regularization.
Based on the prior of the QR code image, this paper quoted the algorithm mechanism of Pan [8,9]. Under the assumption that the blurred kernel is known or initialized, the non-blind deconvolution method of the image is used to perform the deblurring process to obtain a clear image, that is, the L 0regularization of the intensity and gradient of the image is used as the constraint below: In Eq. (6), x is the clear image, k denotes a blurred kernel, y is a blurred image, λ is the weight parameter, P(x) represents the prior of the image, ⊗ is the convolution operator, k k 2 2 is the regularization constraint term. And quote u and g(g h , g v ) T as auxiliary variables. u is used to approximate x, g(g h , g v ) T is used to approximate ∇x by: In Eq. (7), β and μ are regularization parameters. When their values are infinitely close to ∞, eq. (7) is equivalent to eq. (6). By fixing other variables, we use an alternating minimization method to minimize x. The values of μ and g are initialized to zero. In each iteration, the solution of x is obtained as follows.
x ¼ min  The closed-form solution to this minimization problem is to use the extreme value to derive the formula (8), and use the fast Fourier transform method to convert the convolution operation in the matrix space into a point multiplication operation in the frequency domain as: In Eq. (9), F( ) and F −1 ( ) respectively represent fast Fourier transform (FFT) and inverse FFT. Fð Þ is a complex conjugate operator, where ∇ h and ∇ v respectively represent horizontal and vertical differential operators. After solving x, we calculate u and g (see (10) and (11)): Eqs. (10) and (11) are pixel-based minimization problems. The solutions of u and g are obtained (see (12) and (13)) based on Liu [10].

Blurred kernel estimation
For a given image x, this paper refers to Cho [36] using the predicted gradient idea to further estimate the blurred kernels by using the minimized energy function, the formula is as follows (see (14)): Similarly, for better calculations, we derive the formula (14) and use the fast Fourier transform method to transform the convolution operation in matrix space into a dot product operation in the frequency domain, we can obtain (see (15)): In formula (15), the gradient of f(k) should be evaluated multiple times during the minimization process. F and F −1 also represent the Fourier transform and its inverse transform, and Fð Þ is a conjugate fast Fourier transform. F(∇x) and F(∇y) calculations are preprocessed before the conjugate gradient starts to reduce the number of FFT calculations in each iteration.

Experimental results and analysis
The error correction level of the QR code images is H. Based on a series of experiments, compared to other QR code generators, the Caoliao QR code website has little effect on the Tenengrad value of QR codes with different error correction rates. Therefore, this paper uses the Caoliao website to generate the corresponding version of the QR code and uses the Zxing 3.4.0 software package to decode. The input images are uniformly initialized to a matrix (300 × 300). The experimental environment of this article is the Intel i7 processor, CPU 3.20GHz and Matlab2018a. We will compare the deblurring effects of different algorithms from simulation experiments, and analyze the advantages of the algorithms from two dimensions of deblurring time and recognition rate after deblurring in the second section.

Deblurring time and recognition rate
After that, combining with Tables 3, 4 and 5  Last but not least, deblurring time and recognition rate are compared between the proposed algorithm and other blind deblurring algorithms, as shown in Fig. 22 and Fig. 23 respectively. The analysis of these figures reveals that not only the operation speed of the algorithm in this paper is improved greatly, but also the recognition rate is higher than Zoran's algorithm and Wen's algorithm but lower than Pan's algorithm. After comparison, for slightly blurred images, it can be easily determined that the QR code images are recognizable in the small-scale process, and the deblurring algorithm is ended ahead of the next scale, avoiding excessive redundant calculations. This algorithm can initially show that within the identifiable range after image deblurring, as the blurring degree increases, the algorithm time in this paper gradually increases, and with the increase of version or scale control, the time also gradually increases. However, it can be seen that the algorithm in this paper has more practical application value than the existing algorithms in the field of blind deblurring of QR codes.

Discussion and conclusion
In this paper, we propose a simple and fast algorithm for blind deblurring of QR code images based on adaptive scale control, which has wide applications in e-commerce, web and mobile computing and the Internet of Things. Based on the existing blind deblurring algorithms, an evaluation mechanism is presented to realize the image scale adaption. Besides, we introduce a scale control parameter to measure the relationship between the parameter and the recognition rate and deblurring time. The experimental results show that the proposed algorithm can quickly identify unified versions of QR codes, which are generated in various industrial fields such as the traceability of salt, seeds, medicines et al. In comparison with the existing blind deblurring algorithms, our approach has more advantages in speed and efficacy.  There are still some limitations in the proposed algorithm. The first limitation is that the proposed algorithm is temporarily applied to the averagely blurred QR code images. However, for the uneven blurred QR code images, its recovery effect is not so satisfactory. The second limitation is that the QR images may be easily corrupted or attacked by socalled adversarial perturbations. For future work, we will continue to solve the limitations of the proposed algorithm and study a more universal deblurring method. Besides, we will focus on exploring the combination of most state-of-art techniques to further improve the performance. In real life, a customized two-dimensional barcode [5] can effectively prevent the forgery of imitation physical labels and maintain good anti-counterfeiting aesthetics, a unified gradient regularization family [39] can effectively solve the so-called confrontation that QR images may suffer disturbance destruction or attack, spectral-domain feature segmentation [40] can extract the QR code images in a complex environment.