Disclosure of Invention
In order to solve the above problems, an object of the present invention is to provide a blind restoration method for an out-of-focus QR code image, which can effectively reduce the amount of computation and the restoration time in the process of restoring a barcode image while ensuring the quality of the restored image.
The technical scheme adopted by the invention for solving the problems is as follows:
a blind restoration method for an out-of-focus QR code image comprises the following steps:
A. carrying out graying processing on an input QR code image;
B. intercepting the QR code image after the graying treatment to obtain an edge image;
C. carrying out edge detection on the edge image to obtain an edge matrix;
D. scanning the edge matrix column by column to obtain the position of an edge straight line;
E. the edge image is subjected to derivation, and a point with the maximum change rate of the derivative value is obtained through calculation;
F. calculating the distance between the edge straight line and the point with the maximum derivative value change rate to obtain an estimated defocus radius;
G. and calculating according to the defocusing radius to obtain a point spread function, and restoring the defocused and blurred QR code image according to the point spread function.
Further, the step a performs a graying process on the input QR code image, where after the graying process is performed on the QR code image, a pixel matrix of the QR code image is expressed as:
and a (i, j) is a pixel value with a position (i, j) in the QR code image, 1< i < M, 1< j < N, N is the width of the QR code image, and M is the height of the QR code image.
Further, in the step B, the grayed QR code image is intercepted, and the specific steps are as follows: and preprocessing the QR code image, and intercepting an 1/4 area at the upper left corner of the QR code image. Due to the position characteristics of the QR code positioning frame and the size of the positioning frame of the QR code of different data amounts, by intercepting the upper left corner 1/4 region as a detection object, it is possible to reduce the amount of calculation without affecting the estimation of the blur radius.
Further, in the step C, in the edge detection of the edge image, a Canny detection operator is adopted to perform edge detection on the edge image. Compared with various edge detection operators, the Canny operator has a better effect of detecting the edge images.
Further, in the step D of scanning the edge matrix column by column, the edge matrix is searched by using a search algorithm, and the edge matrix is compared until a column with a continuous numerical value of 1 is obtained for the first time, that is, the position of the edge straight line is obtained.
Further, the step E of deriving the edge image specifically includes the steps of: and carrying out secondary derivation on the edge image, wherein the formula of the primary derivation is as follows:
dx(i,j)=I(i+1,j)-I(i,j);
dy(i,j)=I(i,j+1)-I(i,j);
wherein I is an edge image, I (I, j) is a value at a position (I, j) in the edge image I, and after a first derivative is obtained, the first derivative is derived again according to the following formula:
G(x,y)=dx(i,j)-dy(i,j)。
further, the step E obtains a point with the maximum change rate of the derivative value through calculation, and obtains a point with the maximum change rate of the derivative value according to the second derivative of the edge image I and the normal direction of the edge straight line. In order to efficiently find the point at which the rate of change of the derivative value is the greatest, it is necessary to further derive the first derivative of the edge image.
Further, the step G obtains a point spread function by calculating according to the defocus radius, and brings the defocus radius into the defocus degradation model to obtain the point spread function, where the defocus degradation model is:
where h (x, y) is the point spread function and R is the defocus radius.
Furthermore, in the step G, in restoring the defocused blurred QR code image according to the point spread function, the defocused blurred QR code image is restored according to the point spread function and the RL algorithm.
The invention has the beneficial effects that: according to the blind restoration method for the out-of-focus QR code image, the QR code image is subjected to graying processing and edge detection processing to obtain the edge image, then the edge image is processed to obtain the edge straight line and the point with the maximum derivative value change rate, the out-of-focus radius can be calculated according to the edge straight line and the point with the maximum derivative value change rate, further the point spread function can be obtained, finally the blurred QR code image is restored according to the point spread function, the calculation amount is small, and the restoration speed is high.
Detailed Description
Referring to fig. 1, the blind restoration method for the out-of-focus QR code image of the present invention includes the following steps:
A. carrying out graying processing on an input QR code image;
because the input QR code images are different from each other and have certain differences in color, state, and other aspects, in order to make the restoration effect of the final QR code image better, it is necessary to perform the graying process on the QR code image, and after the graying process is performed on the QR code image, the pixel matrix is expressed as:
and a (i, j) is a pixel value with a position (i, j) in the QR code image, 1< i < M, 1< j < N, N is the width of the QR code image, and M is the height of the QR code image.
B. Intercepting the QR code image after the graying treatment to obtain an edge image;
firstly, because the QR code image is obtained by shooting or scanning in different ways, the obtained QR code image has certain redundant information, so that the grayed QR code image needs to be preprocessed to eliminate redundant irrelevant information in the QR code image and restore part of real useful information, so as to ensure the restoration effect.
After the QR code image is preprocessed, the QR code image needs to be intercepted, and due to the position characteristics of the QR code positioning frame and the sizes of the positioning frames of the QR codes with different data volumes, the estimation of the fuzzy radius is not influenced while the calculation amount is reduced by intercepting the upper left corner 1/4 area as a detection object.
C. Carrying out edge detection on the edge image to obtain an edge matrix;
after comparing the effects of different edge detection operators, the method selects a Canny detection operator with a better effect to carry out edge detection on the edge image, and the Canny aims at finding an optimal edge detection algorithm, and comprises the following three steps: denoising; finding a brightness gradient in the image; edges are tracked in the image.
The Canny detection operator is used as a multi-stage edge detection algorithm and is suitable for different occasions, and parameters of the Canny detection operator are allowed to be adjusted according to different implementation specific requirements so as to identify different edge characteristics, so that the Canny detection operator has a better detection effect compared with other edge detection operators.
D. Scanning the edge matrix column by column to obtain the position of an edge straight line L;
specifically, in the step D, during the column-by-column scanning of the edge matrix, the edge matrix is searched by using a search algorithm, and the edge matrix is compared until a column with a continuous numerical value of 1 is obtained for the first time, that is, the position of the edge straight line L is obtained.
E. The edge image is subjected to derivation, and a point Q with the maximum change rate of the derivative value is obtained through calculation;
specifically, the derivation of the edge image in step E specifically includes: and carrying out secondary derivation on the edge image, wherein the formula of the primary derivation is as follows:
dx(i,j)=I(i+1,j)-I(i,j);
dy(i,j)=I(i,j+1)-I(i,j);
after the first derivative is obtained, in order to efficiently find the point Q with the maximum change rate of the derivative value, the first derivative of the edge image needs to be subjected to derivation again, and the first derivative is subjected to derivation again according to the following formula:
G(x,y)=dx(i,j)-dy(i,j)。
and after the second derivative of the edge image I is obtained, obtaining a point Q with the maximum derivative value change rate according to the second derivative of the edge image I and the normal direction of the edge straight line.
F. Calculating the distance between the edge straight line L and the point Q with the maximum derivative value change rate, namely the distance between the corresponding columns to obtain an estimated defocus radius R;
G. and calculating to obtain a point spread function according to the defocusing radius R, and restoring the defocused and blurred QR code image according to the point spread function.
Specifically, the step G obtains a point spread function by calculating according to the defocus radius, and brings the defocus radius into the defocus degradation model to obtain the point spread function, where the defocus degradation model is:
where h (x, y) is the point spread function.
After the point spread function is obtained, restoring the defocused and blurred QR code image according to the point spread function and an RL algorithm.
In order to verify the restoration effect of the invention on the blurred QR code image, a blurred QR code image is firstly input as shown in FIG. 2, and then is subjected to graying processing to ensure thatThen, after a subsequent restoration effect, performing edge detection on the input QR code image to obtain an edge matrix, as shown in fig. 3, which is the QR code image after edge detection, then using a search algorithm to find edge straight lines, where the columns with the first numerical values all 1 in the edge matrix are the columns where the edge straight lines are located, and performing derivation again on the first derivative of the edge image, as shown in the relationship diagram after second derivation shown in fig. 4, where the vertical coordinate is a gradient value (i.e., the result after second derivation), and the horizontal coordinate is the position of the image column, where the vertical coordinate may be regarded as the position where the edge straight line is located, and the horizontal coordinate may be regarded as the normal of the edge straight line, starting to search the point with the largest derivative change rate of the origin from the normal direction of the edge straight line, that is to determine the position of the Q point, and as shown in fig. 4, the horizontal coordinate of the point with the largest derivative change rate is 10, that is, the coordinate of the position of the point Q where the derivative change rate is the largest can be determined to be 10, and the coordinate of the edge straight line is 0 since the edge straight line is set as the starting point, so that the estimated defocus radius of 10 can be obtained, and then the defocus radius is substituted into the defocus degradation model, and the point spread function is calculated
![Figure BDA0001629243520000081](https://patentimages.storage.googleapis.com/54/0b/a0/e5cd39652be1b9/BDA0001629243520000081.png)
Finally, the RL algorithm is combined with the point spread function to restore the blurred QR code image to obtain a restored image shown in fig. 5, and compared with fig. 2 and 5, the restoration method has the advantages that the restoration effect is better, the image definition is restored, and the image quality is ensured.
Specifically, since the size of the defocus radius is determined by the distance between the edge line and the point Q, the specific coordinate where the edge line is located does not need to be obtained, and only the position of the edge line needs to be known, after the position of the edge line is obtained, the position where the edge line is located is taken as the ordinate, the normal direction of the edge line is taken as the abscissa to establish a coordinate system, and then the point with the maximum derivative change rate is found according to the result of the second derivation, since the intervals between the points in the edge image are consistent, the distance from the point with the maximum derivative change rate to the edge line can be determined as the size of the defocus radius R, that is, the image column position on the abscissa in fig. 4 is not the specific position actually in the edge image, but a relative position.
Meanwhile, the restoration method of the invention is compared with other known methods, an image with the size of 512 x 512 is selected as an input, the time spent in the whole restoration process is compared,
Method
|
document 1
|
Document 2
|
Document 3
|
Document 4
|
The method of the invention
|
Recovery time
|
21.58s
|
20.87s
|
24.77s
|
24.81s
|
0.45s |
The time spent by each method is shown in table 1:
TABLE 1 (recovery time data for the invention and other methods)
As can be seen from the data in Table 1, the recovery time spent by the method of the present invention is considerably shorter, 50-60 times faster than other recovery methods.
Therefore, the invention has good restoration effect, relatively short calculation time in the whole restoration process and small calculation amount.
Reference documents:
document 1: pan J, Hu Z, Su Z, et al, Deblurring Text Images via L0-regulated Intensity and Gradient primer [ C ]// Computer Vision and Pattern recognition. IEEE 2014: 2901-.
Document 2: krishnan D, Tay T, Fergus R.Blind reduction using a normalized specific measure [ C ]// Computer Vision and Pattern recognition. IEEE,2011: 233-.
Document 3: perrone D, Favaro P.A clean Picture of Total Variation Blanket reduction [ J ]. IEEE Transactions on Pattern Analysis & Machine understanding, 2016,38(6): 1041-.
Document 4: gao K, Zhu Z, Dou Z, et al. variable exposure Regulation application for blade Kernel Estimation of Remote Sensing Image blade retrieval [ J ]. IEEE Access,2018,6(99): 4352-.
The above description is only a preferred embodiment of the present invention, and the present invention is not limited to the above embodiment, and the present invention shall fall within the protection scope of the present invention as long as the technical effects of the present invention are achieved by the same means.