Summary of the invention
The present invention is directed to the low problem of discrimination that dot matrix DataMatrix Quick Response Code exists, propose the image pre-processing method of a series of morphological transformation in conjunction with binaryzation, and make smoothly fuzzyly with morphological transformation, there is adaptivity by spot detection.The method can overcome the problems such as dot matrix DataMatrix code is excessive in identification intermediate gap, the even noise of uneven illumination, and dot matrix DM Quick Response Code is converted into the form of standard, thus detect by the current hand-held identification equipment of DM code, without the need to secondary development on hardware, system is feasible fast effectively, can meet at present to the actual demand that dot matrix DM decodes.
The invention provides a kind of dot matrix DM image in 2 D code disposal route, comprising:
Step one: read dot matrix DM image in 2 D code, on the basis not changing initial point configuration DM image in 2 D code wide high proportion, utilizes arest neighbors interpolation algorithm or bilinear interpolation algorithm to carry out the unitized process of width;
Step 2: the image after uniform sizes is converted to gray-scale map;
Step 3: carry out Gaussian smoothing filter process to the image after gray processing, removes the tiny texture of image background, makes the solid dot of dot matrix code element more level and smooth;
Step 4: the grayscale image after Gaussian smoothing filter is converted into black white binarization image;
Step 5: carry out symbol detection to the image after binaryzation in step 4, obtains the diameter of dot matrix code element;
Step 6: the diameter of the dot matrix code element obtained according to step 5 and change the size of average template dynamically, and then dynamic mean filter process is carried out to the gray-scale map in step 2, the gray-scale map after dynamic mean filter is carried out again to the binary conversion treatment of the improvement that kittler algorithm combines with Bernsen algorithm;
Step 7: the binary image that step 6 obtains is carried out morphologic opening operation and closed operation operation, obtain the dot matrix image after processing, wherein,
Opening operation following formula represents:
Closed operation following formula represents:
Wherein A is the bianry image of input, and B is square structure element.
Step 8: dot matrix image step 7 obtained, by medium filtering denoising, changes the standard DM image in 2 D code of discernible block structure into.
Further, the length of side of the square structure element B in described step 7 opening operation is preferably 1/3 of dot matrix code element diameter, and in closed operation, the length of side of square structure element B is preferably less than dot matrix code element diameter 1 to 5 display pixel point.
Further, the medium filtering denoising that step 8 uses realizes preferably by following steps:
The value of any in image is replaced with the Mesophyticum of each point value in a neighborhood of this point, allows the pixel value of surrounding close to actual value, thus eliminate isolated noise spot, wherein two dimension median filter is exported and is obtained by following formula:
g(x,y)=med{f(x-k,y-1),(k,1∈W)}
Wherein, med{} represents the intermediate value of getting array sequence; F (x, y), g (x, y) are respectively original image and the rear image of process; W is the two dimension pattern plate of 3 × 3 sizes; K, l are integer, the increment respectively on denotation coordination x, y direction.
Further, the dynamic mean filter process of step 6 preferably comprises the steps: further
(1) template size is obtained by following formula:
wherein round represents floor operation;
(2) average filter template is calculated:
Wherein, k is the size of average template, and D is the diameter of dot matrix code element, and ε is average template;
(3) be averaged filtering according to the following formula:
I
1(x,y)=ε*I(x,y)
Wherein I (x, y) represents gray-scale map matrix, I
1(x, y) represents filtered image gray matrix;
Further, the process in step 4, the grayscale image after Gaussian smoothing filter being converted into black white binarization image specifically comprises:
(1) obtain global threshold T with Kittler algorithm, the method calculating this global threshold T is as follows:
Wherein, f (x, y) is the original gray-scale map that step 2 obtains, e (x, y)=max{|e
x|, | e
y| i.e. maximum of gradients, e
x=f (x-1, y)-f (x+1, y) is the gradient in horizontal direction, e
y=f (x, y-1)-f (x, y+1) is the gradient in vertical direction;
(2) scan whole f (x, y) gray level image, then binaryzation result is:
Wherein b (x, y) is binaryzation result.
Further, the binary conversion treatment of the improvement that the kittler algorithm that step 6 uses combines with Bernsen algorithm comprises following concrete steps:
Step (1) obtains global threshold T with Kittler algorithm, and the method calculating this global threshold T is as follows:
Wherein, f (x, y) is the original gray-scale map that step 2 obtains, e (x, y)=max{|e
x|, | e
y| i.e. maximum of gradients, e
x=f (x-1, y)-f (x+1, y) is the gradient in horizontal direction, e
y=f (x, y-1)-f (x, y+1) is the gradient in vertical direction;
Step (2) adopts Bernsen algorithm to process the interval of uneven illumination in image histogram, and the gray-scale value in this interval concentrates near the global threshold T that step (1) obtains, if T
3> D, D are the interval width of Bernsen algorithm process and the diameter of dot matrix code element
Then binaryzation result
If T
3< D, D are the interval width of Bernsen algorithm process and the diameter of dot matrix code element
Then binaryzation result
Wherein,
T
3be Threshold selection foundation and T
3(x, y)=max
s-min
s,
T
2(x,y)=0.5(max
d+min
d),
T
4(x,y)=0.5(T+T
2(x,y));
Wherein,
max
drepresent that pixel (x, y) is max pixel value in the window of 4w*4w in size;
represent that pixel (x, y) is minimum pixel value in the larger window of 4w*4w in size;
represent that pixel (x, y) is max pixel value in the comparatively wicket of 2w*2w in size;
represent that pixel (x, y) is minimum pixel value in the comparatively wicket of 2w*2w in size;
Max in above-mentioned formula represents the maximal value of getting pixel in window, and min represents the minimum value of getting pixel in window, k and l is integer, the increment respectively on denotation coordination x, y direction; W represents the window of local threshold computing, and w span is 5 ~ 9, T
2represent pixel grey scale mean value in window, T
4t
2with the mean value of global threshold T.
Further, the symbol detection idiographic flow in step 5 is as follows:
Utilize Gauss-Laplace detected image code element, for two-dimensional Gaussian function:
Wherein, σ is width parameter and the characteristic dimension of function, and for the radial effect scope of control function, the radial direction of the larger representative function of σ is wider, its similar code element is larger, the radial direction of the less representative function of σ is narrower, and its similar code element is less, x, y represents two-dimensional spatial location, g (x, y, σ) represents two-dimensional Gaussian function;
The Laplace transform of formula (1) is:
Wherein, Δ
2g represents the Laplace function of two-dimensional Gaussian function, Δ
2represent Second Order Differential Operator, g represents two-dimensional Gaussian function; Normalized Laplacian is transformed to:
In formula (3)
represent normalized Laplacian function, its variance is 0;
Normalized dimensional Gaussian Laplace function shown in formula (3) is function with circular symmetry, by changing the value of σ, detecting the Quick Response Code code element of different size, and asking for
pole value is equivalent to and asks for following formula:
Wherein,
represent normalized Laplacian function
ask the local derviation of σ,
represent and ask normalized Laplacian function
pole value;
That is:
r
2-2σ
2=0
Wherein r represents the radius of the circular code element of image in 2 D code binaryzation, at yardstick
time, Laplacian response reaches maximum, and in like manner, if the circular code element black and white in image is anti-phase, so, the Laplacian response of this code element at yardstick is
time reach minimum, the Laplacian yardstick σ value responded when reaching peak value is the characteristic dimension of symbol detection, calculate the discrete Laplce response of image under different scale after binaryzation, then each point in locational space is checked, if Laplce's response of this point is all greater than or less than the value of other cubic space neighborhood, so, this is selected is exactly the two-dimensional code data unit vegetarian refreshments be detected, above-mentioned searching locational space
and metric space
peak value by following function representation:
The while of this function representation, on locus and yardstick, Laplce's response reaches the value of the point of maximal value or minimum value, and this point is exactly the code element that will detect; Wherein, t represents scale-value, (x, y) representation space position, max min local
(x, y, t)() represents the maximal value of response function on space and dimension location or minimum value, and arg () represents the value of the variable of respective function value,
represent standard two-dimensional Laplace function under metric space.
Present invention also offers a kind of dot matrix DM image in 2 D code treating apparatus, comprising:
Image reading module, for reading dot matrix DM image in 2 D code, on the basis not changing initial point configuration DM image in 2 D code wide high proportion, utilizes arest neighbors interpolation algorithm or bilinear interpolation algorithm to carry out the unitized process of width;
Gradation conversion module, for being converted to gray-scale map by the image after uniform sizes;
Gaussian smoothing filter module, for carrying out Gaussian smoothing filter process to the image after gray processing, removing the tiny texture of image background, making the solid dot of dot matrix code element more level and smooth;
Binaryzation modular converter, for being converted into black white binarization image by the grayscale image after Gaussian smoothing filter;
Symbol detection module, for carrying out symbol detection to the image after binaryzation in binaryzation modular converter, obtains the diameter of dot matrix code element;
Dynamic mean filter and binaryzation modular converter, the size of average template is changed dynamically for the diameter of dot matrix code element that obtains according to symbol detection module, and then dynamic mean filter process is carried out to the gray-scale map that gradation conversion module obtains, the gray-scale map after dynamic mean filter is carried out again to the binary conversion treatment of the improvement that kittler algorithm combines with Bernsen algorithm;
Arithmetic operation module, the binary image for dynamic mean filter and binaryzation modular converter being obtained carries out morphologic opening operation and closed operation operation, obtains the dot matrix image after processing, wherein,
Opening operation following formula represents:
Closed operation following formula represents:
Wherein A is the bianry image of input; B is square structure element;
Standardized module, passes through medium filtering denoising for dot matrix image arithmetic operation module obtained, changes the standard DM image in 2 D code of discernible block structure into.
Further, the length of side of the square structure element B in the opening operation of described arithmetic operation module is preferably 1/3 of dot matrix code element diameter, and in closed operation, the length of side of square structure element B is preferably less than dot matrix code element diameter 1 to 5 display pixel point.
Further, the medium filtering denoising that standardized module uses realizes preferably by with under type:
The value of any in image is replaced with the Mesophyticum of each point value in a neighborhood of this point, allows the pixel value of surrounding close to actual value, thus eliminate isolated noise spot, wherein two dimension median filter is exported and is obtained by following formula:
g(x,y)=med{f(x-k,y-1),(k,1∈W)}
Wherein, med{} represents the intermediate value of getting array sequence; F (x, y), g (x, y) are respectively original image and the rear image of process; W is the two dimension pattern plate of 3 × 3 sizes; K, l are integer, the increment respectively on denotation coordination x, y direction.
Embodiment
Below in conjunction with the drawings and specific embodiments, the present invention is further detailed explanation, is not practical range of the present invention is confined to this.
As shown in Figure 1, dot matrix DM code (right side) and standard DM code (left side) have significant difference.
Because dot matrix DM code is made up of according to certain rule uniform round dot, carry out Fuzzy smooth and morphological change if conventionally direct to picture, effect is very undesirable, easily caused process and treatment effect not obvious.
[embodiment one]
Present embodiments provide a kind of dot matrix DM image in 2 D code treatment scheme and method, the method can be realized by computer program or be realized by hardware circuit, and idiographic flow is with reference to shown in Fig. 2.
(1) reading images uniform sizes
Conveniently process, first after reading images, the size of dot matrix two dimensional image is unitized, the basis not changing former figure wide high proportion utilizes arest neighbors interpolation algorithm or bilinear interpolation algorithm carry out width to unitize, showing to unitize through test to make identification more accurate.
(2) gray-scale map is converted to
Be positioned at and be convenient to process image, need the image of acquired original to be converted to gray level image.
(3) Gaussian smoothing filter process
Roughness due to bar code background affects identification accuracy, and the lattice module of dot matrix DM code is solid spot, smoothly little on solid dot impact, so, in order to remove the complex texture of picture, need to carry out Fuzzy smooth process.Dot matrix DM bar code does not need too high to the requirement of smoothing processing, the experiment converted by multiple smothing filtering is compared, and finds that dynamic mean filter and gaussian filtering all meet the demands.Therefore use Gaussian smoothing to obtain natural smooth effect in this step, be unlikely to too fuzzy, more precisely stablize to make the measurement of spot detection.
(4) binary conversion treatment
The binary conversion treatment of image is exactly by choosing suitable threshold value, grayscale image is converted into the black white binarization image that can reflect integral image structure and local feature.In dot matrix Data Matrix bar code image processing procedure, by carrying out corresponding computing to the image after binaryzation, the characteristic information such as border, position, size of target area can be obtained than being easier to, thus lay the foundation for the analysis of bar code image and identification.
First, obtain global threshold T with Kittler algorithm, the method calculating this global threshold T is as follows:
Wherein, f (x, y) is the original gray-scale map that step 2 obtains, e (x, y)=max{|e
x|, | e
y| i.e. maximum of gradients, e
x=f (x-1, y)-f (x+1, y) is the gradient in horizontal direction, e
y=f (x, y-1)-f (x, y+1) is the gradient in vertical direction;
Then, scan whole f (x, y) gray level image, then binaryzation result is:
Wherein b (x, y) is binaryzation result.
(5) spot detection
The principle of spot detection (i.e. dot matrix symbol detection) is as follows:
Utilize Laplacian (Laplace of Guassian, LoG) operator detected image code element, for two-dimensional Gaussian function:
Wherein, σ is width parameter and the characteristic dimension of function, and for the radial effect scope of control function, the radial direction of the larger representative function of σ is wider, its similar code element is larger, the radial direction of the less representative function of σ is narrower, and its similar code element is less, x, y represents two-dimensional spatial location, g (x, y, σ) represents two-dimensional Gaussian function;
The Laplace transform of formula (1) is:
Wherein, Δ
2g represents the Laplace function of two-dimensional Gaussian function, Δ
2represent Second Order Differential Operator, g represents two-dimensional Gaussian function;
Normalized Laplacian is transformed to:
In formula (3)
represent normalized Laplacian function, its variance is 0;
Normalized dimensional Gaussian Laplace function shown in formula (3) is function with circular symmetry, by changing the value of σ, detecting the Quick Response Code code element of different size, and asking for
pole value is equivalent to and asks for following formula:
Wherein,
represent normalized Laplacian function
ask the local derviation of σ,
represent and ask normalized Laplacian function
pole value;
That is:
r
2-2σ
2=0
Wherein r represents the radius of the circular code element of image in 2 D code binaryzation, at yardstick
time, Laplacian response reaches maximum, and in like manner, if the circular code element black and white in image is anti-phase, so, the Laplacian response of this code element at yardstick is
time reach minimum, the Laplacian yardstick σ value responded when reaching peak value is the characteristic dimension of symbol detection, calculate the discrete Laplce response of image under different scale after binaryzation, then each point in locational space is checked, if Laplce's response of this point is all greater than or less than the value of other cubic space neighborhood, so, this is selected is exactly the two-dimensional code data unit vegetarian refreshments be detected, above-mentioned searching locational space
and metric space
peak value by following function representation:
The while of this function representation, on locus and yardstick, Laplce's response reaches the value of the point of maximal value or minimum value, and this point is exactly the code element that will detect; Wherein, t represents scale-value, (x, y) representation space position, max min local
(x, y, t)() represents the maximal value of response function on space and dimension location or minimum value, and arg () represents the value of the variable of respective function value,
represent standard two-dimensional Laplace function under metric space.
According to above principle, the data element vegetarian refreshments of image in 2 D code and the size of each spot thereof can be detected well, see Fig. 3.
(6) binary conversion treatment of dynamic filter and improvement
First, dynamic filter process is carried out:
(1) template size is obtained by following formula:
wherein round represents floor operation;
(2) average filter template is calculated:
Wherein, k is the size of average template, and D is the diameter of dot matrix code element, and ε is average template;
(3) be averaged filtering according to the following formula:
I
1(x,y)=ε*I(x,y)
Wherein I (x, y) represents gray-scale map matrix, I
1(x, y) represents filtered image gray matrix;
Then, the binary conversion treatment improved is carried out:
The Binarization methods that the Binarization methods of this method has selected kittler algorithm to combine with the Bernsen algorithm of improvement, be directed to dot matrix Quick Response Code point module relative to smoothly, the feature that background texture is similar, unnecessary background detail can well be ignored, have good treatment effect to the picture that uneven illumination is even simultaneously.First the region of image generation uneven illumination is found according to the simple statistics algorithm of Kittler, the processing procedure then improving Bernsen algorithm, the artifact problem adjusting parameter, weaken former algorithm, and by the part of the algorithm process image irradiation inequality after improvement.This algorithm has good stability and adaptivity, can significantly improve binaryzation effect and the discrimination of two-dimensional bar code.
The binary processing method that kittler algorithm combines with the Bernsen algorithm of improvement is as follows:
Step (1) obtains global threshold T with Kittler algorithm, and the method calculating this global threshold T is as follows:
Wherein, f (x, y) is the original gray-scale map that step 2 obtains, e (x, y)=max{|e
x|, | e
y| i.e. maximum of gradients, e
x=f (x-1, y)-f (x+1, y) is the gradient in horizontal direction, e
y=f (x, y-1)-f (x, y+1) is the gradient in vertical direction;
Step (2) adopts Bernsen algorithm to process the interval of uneven illumination in image histogram, and the gray-scale value of this class interval concentrates near the global threshold T that step (1) obtains,
If T
3> D, D are the interval width of Bernsen algorithm process and the diameter of dot matrix code element
Then binaryzation result
If T
3< D, D are the interval width of Bernsen algorithm process and the diameter of dot matrix code element
Then binaryzation result
Wherein,
T
3be Threshold selection foundation and T
3(x, y)=max
s-min
s,
T
2(x,y)=0.5(max
d+min
d),
T
4(x,y)=0.5(T+T
2(x,y));
Wherein,
max
drepresent that pixel (x, y) is max pixel value in the window of 4w*4w in size;
represent that pixel (x, y) is minimum pixel value in the larger window of 4w*4w in size;
represent that pixel (x, y) is max pixel value in the comparatively wicket of 2w*2w in size;
represent that pixel (x, y) is minimum pixel value in the comparatively wicket of 2w*2w in size;
Max in above-mentioned formula represents the maximal value of getting pixel in window, and min represents the minimum value of getting pixel in window, k and l is integer, the increment respectively on denotation coordination x, y direction; W represents the window of local threshold computing, and w span is 5 ~ 9, T
2represent pixel grey scale mean value in window, T
4t
2with the mean value of global threshold T.
(7) carry out open and close operator, obtain dot matrix image
Dot matrix DM code is made up of point module, and in order to become discernible standard DM code, needing lattice module to become block structure, just having used open and close operator in morphological transformation, open and close operator is the array configuration of dilation and corrosion.
Wherein, A is expanded by B, is designated as
be defined as:
Wherein, A is corroded by B, is designated as A Θ B, is defined as:
AΘB={z|(B)
z∩A
c≠Φ}
A can be denoted as A ο B by the morphology opening operation of B, and this computing is the result carrying out dilation erosion after A is corroded by B again with B:
A can be denoted as AB by the closing operation of mathematical morphology of B, and this computing is the result of corroding expansion after A is expanded by B again with B:
In the method, A is the bianry image of input, and B is square structure element.
Opening operation can make the profile of image become smooth, and narrow connection can also be made to disconnect and eliminate burr, but unlike the profile that image is large, overall contraction not occurring with corrosion, object space any change does not occur yet.Closed operation can make profile become smooth equally, but contrary with opening operation, and it can make narrow interruption up usually, fills little cavity.As the schematic diagram that Fig. 4 is opening operation and closed operation.Therefore opening operation and closed operation are used in the standardization of DM Quick Response Code, the spuious point after binaryzation and some burrs can be removed.Great many of experiments sum up can obtain, the spot size (i.e. dot matrix code element diameter) obtained by spot detection 1/3rd square structure element carry out opening operation, remove spuious point and burr.Carry out closed operation with the square structure element being slightly smaller than spot size (i.e. dot matrix code element diameter) 1 to 5 display pixel point, make point module become block-shaped structure, make its " L " shape sharpness of border visible.
(8) carry out medium filtering process after open and close operator, be converted into standard two-dimensional code image
Medium filtering denoising realizes preferably by with under type:
The value of any in image is replaced with the Mesophyticum of each point value in a neighborhood of this point, allows the pixel value of surrounding close to actual value, thus eliminate isolated noise spot, wherein two dimension median filter is exported and is obtained by following formula:
g(x,y)=med{f(x-k,y-1),(k,l∈W)}
Wherein, med{} represents the intermediate value of getting array sequence; F (x, y), g (x, y) are respectively original image and the rear image of process; W is the two dimension pattern plate of 3 × 3 sizes; K, 1 is integer, the increment respectively on denotation coordination x, y direction.
Change the effect after standard DM image in 2 D code into as shown in Figure 5.
[embodiment two]
Present invention also offers a kind of software virtual device of functional module framework, it comprises following structure:
A kind of dot matrix DM image in 2 D code treating apparatus, comprising:
Image reading module, for reading dot matrix DM image in 2 D code, on the basis not changing initial point configuration DM image in 2 D code wide high proportion, utilizes arest neighbors interpolation algorithm or bilinear interpolation algorithm to carry out the unitized process of width;
Gradation conversion module, for being converted to gray-scale map by the image after uniform sizes;
Gaussian smoothing filter module, for carrying out Gaussian smoothing filter process to the image after gray processing, removing the tiny texture of image background, making the solid dot of dot matrix code element more level and smooth;
Binaryzation modular converter, for being converted into black white binarization image by the grayscale image after Gaussian smoothing filter;
Symbol detection module, for carrying out symbol detection to the image after binaryzation in binaryzation modular converter, obtains the diameter of dot matrix code element;
Dynamic mean filter and binaryzation modular converter, the size of average template is changed dynamically for the diameter of dot matrix code element that obtains according to symbol detection module, and then dynamic mean filter process is carried out to the gray-scale map that gradation conversion module obtains, the gray-scale map after dynamic mean filter is carried out again to the binary conversion treatment of the improvement that kittler algorithm combines with Bernsen algorithm:
Arithmetic operation module, the binary image for dynamic mean filter and binaryzation modular converter being obtained carries out morphologic opening operation and closed operation operation, obtains the dot matrix image after processing, wherein,
Opening operation following formula represents:
Closed operation following formula represents:
Wherein A is the bianry image of input; B is square structure element;
Standardized module, passes through medium filtering denoising for dot matrix image arithmetic operation module obtained, changes the standard DM image in 2 D code of discernible block structure into.
Certainly, the product of above-mentioned functions module architectures also realizes by real hardware circuit.
The dot matrix spot mentioned in the present invention is also referred to as dot matrix code element, and spot and code element belong to identical concept.
Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, belong to the scope of protection of the invention.