Invention content
To solve the above problems, the purpose of the present invention is to provide a kind of defocus QR code method for blindly restoring image, ensureing
While restoring picture quality, the calculation amount that can be effectively reduced in bar code image recovery process and recovery time.
Technical solution is used by the present invention solves the problems, such as it:
A kind of defocus QR code method for blindly restoring image, includes the following steps:
A, gray processing processing is carried out to the QR code images of input;
B, to gray processing, treated that QR code images intercept, and obtains edge image;
C, edge detection is carried out to edge image, obtains matrix of edge;
D, matrix of edge is scanned by column, obtains the position of edge line;
E, derivation is carried out to edge image, and the maximum point of derivative value change rate is obtained by calculation;
F, the distance between edge line and the maximum point of derivative value change rate, the out-of-focus radius estimated are calculated;
G, point spread function is calculated according to out-of-focus radius, according to point spread function to the QR codes image of defocusing blurring into
Row restores.
Further, the step A carries out gray processing processing to the QR code images of input, wherein carries out ash to QR code images
After degreeization processing, picture element matrix is expressed as:
Wherein a (i, j) be in QR code images position be (i, j) pixel value, 1<i<M, 1<j<N, N are the width of QR code images
Degree, M are the height of QR code images.
Further, to gray processing, treated that QR code images intercept in the step B, the specific steps are:To QR codes
Image is pre-processed, and intercepts 1/4 region in the QR code images upper left corner.Due to the position characteristic of QR code postings, and not
With the posting size of the QR codes of data volume, it is used as detection object by intercepting 1/4 region of the upper left corner, calculation amount can be being reduced
While do not influence the estimation of blur radius.
Further, the step C carries out in edge detection edge image, using Canny detective operators to edge image
Carry out edge detection.Compared to a variety of edge detection operators, Canny operators are preferable to the detection result of edge image.
Further, during the step D scans by column matrix of edge, matrix of edge is looked into using lookup algorithm
It looks for, by comparing until obtaining the row that serial number is 1, the as position where edge line for the first time.
Further, the step E to edge image carry out derivation the specific steps are:Secondary ask is carried out to edge image
It leads, the formula of wherein first time derivation is:
Dx (i, j)=I (i+1, j)-I (i, j);
Dy (i, j)=I (i, j+1)-I (i, j);
Wherein I is edge image, and I (i, j) is the value that position is at (i, j) in edge image I, acquires first derivative
Afterwards, derivation again is carried out to first derivative according to following formula:
G (x, y)=dx (i, j)-dy (i, j).
Further, the maximum point of derivative value change rate is obtained by calculation in the step E, according to the second order of edge image I
The normal direction of derivative and edge line obtains the maximum point of derivative value change rate.Derivative value variation is found in order to efficient
The maximum point of rate, it is necessary to which derivation is carried out again to the first derivative of edge image.
Further, the step G is calculated according to out-of-focus radius in point spread function, and out-of-focus radius is brought into defocus
In degradation model, point spread function is obtained, wherein defocus degradation model is:
Wherein h (x, y) is point spread function, and R is out-of-focus radius.
Further, during the step G restores the QR code images of defocusing blurring according to point spread function, expand according to
Function combination RL algorithms are dissipated to restore the QR code images of defocusing blurring.
The beneficial effects of the invention are as follows:A kind of defocus QR code method for blindly restoring image that the present invention uses, to QR code images
Edge image is obtained after carrying out gray processing processing and edge detection process, then edge image is being handled to obtain edge
Straight line and the maximum point of derivative value change rate, according to edge line and the maximum point of derivative value change rate can be calculated from
Focal radius, and then point spread function can be obtained, finally fuzzy QR code images are restored according to point spread function, are calculated
It is fast to measure small and resume speed.
Specific implementation mode
Referring to Fig.1, a kind of defocus QR code method for blindly restoring image of the invention, includes the following steps:
A, gray processing processing is carried out to the QR code images of input;
Since the QR code images of input are different, there is certain difference in color, state and other everyways, be
Keep the recovery effect of last QR codes image preferable, it is necessary to gray processing processing is carried out to QR code images, to QR codes image into
After the processing of row gray processing, picture element matrix is expressed as:
Wherein a (i, j) be in QR code images position be (i, j) pixel value, 1<i<M, 1<j<N, N are the width of QR code images
Degree, M are the height of QR code images.
B, to gray processing, treated that QR code images intercept, and obtains edge image;
The acquiring way for being primarily due to QR code images is different, is generally obtained by shooting or scanning, so the QR codes obtained
Image can have certain redundant information, so just needing to pre-process the QR code images after gray processing, eliminate QR codes figure
The extra irrelevant information as in, and the true useful information of recovered part, to ensure the effect restored.
After pre-processing QR code images, need to intercept QR code images, due to the position of QR code postings
The posting size of the QR codes of characteristic and different data amount be used as by intercepting 1/4 region of the upper left corner and detects object, can be with
The estimation of blur radius is not influenced while reducing calculation amount.
C, edge detection is carried out to edge image, obtains matrix of edge;
After effect by comparing different edge detection operators, the present invention chooses the preferable Canny detective operators of effect
Edge detection is carried out to edge image, the target of Canny is to find an optimal edge detection algorithm, includes three steps
Suddenly:Denoising;Find the brightness step in image;Edge is tracked in the picture.
Canny detective operators are suitable for different occasions, his parameter allows root as a kind of multistage edge detection algorithm
It is adjusted according to the particular requirement of different realizations to identify different local edges, so Canny detective operators are relative to other
For edge detection operator, detection result is preferable.
D, matrix of edge is scanned by column, obtains the position of edge line L;
Specifically, during the step D scans by column matrix of edge, matrix of edge is looked into using lookup algorithm
It looks for, by comparing until obtaining the row that serial number is 1, the as position where edge line L for the first time.
E, derivation is carried out to edge image, and the maximum point Q of derivative value change rate is obtained by calculation;
Specifically, the step E to edge image carry out derivation the specific steps are:Secondary ask is carried out to edge image
It leads, the formula of wherein first time derivation is:
Dx (i, j)=I (i+1, j)-I (i, j);
Dy (i, j)=I (i, j+1)-I (i, j);
Wherein I is edge image, and I (i, j) is the value that position is at (i, j) in edge image I, acquires first derivative
Afterwards, the maximum point Q of derivative value change rate is found in order to efficient, it is necessary to asked again the first derivative of edge image
It leads, derivation again is carried out to first derivative according to following formula:
G (x, y)=dx (i, j)-dy (i, j).
After the second dervative for acquiring edge image I, according to the second dervative of edge image I and the normal of edge line
Direction obtains the maximum point Q of derivative value change rate.
F, the distance between edge line L and the maximum point Q of derivative value change rate are calculated, that is, correspond between columns away from
From the out-of-focus radius R estimated;
G, point spread function is calculated according to out-of-focus radius R, according to point spread function to the QR code images of defocusing blurring
It is restored.
Specifically, the step G is calculated according to out-of-focus radius in point spread function, and out-of-focus radius is brought into defocus
In degradation model, point spread function is obtained, wherein defocus degradation model is:
Wherein h (x, y) is point spread function.
After obtaining point spread function, the QR code images of defocusing blurring are answered according to point spread function combination RL algorithms
It is former.
In order to verify recovery effect of the present invention for fuzzy QR code images, the fuzzy QR codes figure of a width is inputted first
Picture, as shown in Fig. 2, then gray processing processing is carried out to it, to ensure subsequent recovery effect, then to the QR code images of input
It carries out edge detection and obtains matrix of edge, be illustrated in figure 3 the QR code images after edge detection, then sought using lookup algorithm
Find edge line, the row that first numerical value is all 1 in matrix of edge are the row where edge line, while to through edge graph
The first derivative of picture carries out derivation again, the relational graph after secondary derivation as shown in Figure 4, and ordinate is Grad (i.e. two
Result after secondary derivation), abscissa is the position of image column, and wherein ordinate can be regarded as the location of edge line,
And abscissa can regard the normal of edge line as, be started to find derivative change to its normal direction from the origin of edge line
The maximum point of rate, you can to determine the position of Q points, by Fig. 4 it can be seen that the abscissa of the maximum point of derivative change rate is
10, you can with determine the maximum point Q of derivative change rate position coordinate for 10, and edge line is due to being set as starting point, therefore
The coordinate of edge line is 0, it is possible to which the out-of-focus radius for obtaining estimation is 10, and out-of-focus radius, which is then brought into defocus, degenerates
In model, point spread function is calculatedIt is final to utilize RL algorithm combination point spread functions to fuzzy QR
Code image is restored, and obtains the image after recovery as shown in Figure 5, comparison diagram 2 and Fig. 5, it can be seen that of the invention answers
The recovery effect of original method is preferable, ensures the quality of image while restored image clarity.
Specifically, since the size of out-of-focus radius is determined by the distance between edge line and Q points, so for side
Specific coordinate residing for edge straight line need not obtain, it is only necessary to its position be known, after obtaining the position of edge line, with edge
The location of straight line is used as ordinate, coordinate system is established using the normal direction of edge line as abscissa, then according to two
The result of secondary derivation looks for the maximum point of derivative change rate, since the interval between each point in edge image is consistent
, so the maximum point of derivative change rate can be determined as the size of out-of-focus radius R, that is, Fig. 4 to the distance of edge line
The image column position on abscissa is not the practical specific location in edge image in the middle, but a relative position.
The restored method of the present invention and other several methods being currently known are compared simultaneously, select size for 512*
The time spent in 512 image, which is used as, to be inputted, more entire recuperation,
Method |
Document 1 |
Document 2 |
Document 3 |
Document 4 |
The method of the present invention |
Recovery time |
21.58s |
20.87s |
24.77s |
24.81s |
0.45s |
The time spent in each method, is as shown in table 1:
Table 1 (the recovery time data of the present invention and other methods)
The recovery time spent by the method that the data in table 1 can be seen that the present invention is extremely short, more multiple than others
Original method wants fast 50-60 times.
So not only recovery effect is good for the invention of the present invention, the calculating time of entire recuperation is also relatively short, calculates
Amount is also smaller.
Bibliography:
Document 1:Pan J,Hu Z,Su Z,et al.Deblurring Text Images via L0-Regularized
Intensity and Gradient Prior[C]//Computer Vision and Pattern
Recognition.IEEE,2014:2901-2908.
Document 2:Krishnan D,Tay T,Fergus R.Blind deconvolution using a
normalized sparsity measure[C]//Computer Vision and Pattern Recognition.IEEE,
2011:233-240.
Document 3:Perrone D,Favaro P.A Clearer Picture of Total Variation Blind
Deconvolution[J].IEEE Transactions on Pattern Analysis&Machine Intelligence,
2016,38(6):1041-1055.
Document 4:Gao K,Zhu Z,Dou Z,et al.Variable Exponent Regularization
Approach for Blur Kernel Estimation of Remote Sensing Image Blind Restoration
[J].IEEE Access,2018,6(99):4352-4374.
The above, only presently preferred embodiments of the present invention, the invention is not limited in the above embodiments, as long as
It reaches the technique effect of the present invention with identical means, should all belong to the scope of protection of the present invention.