859

Sensors and Materials, Vol. 31, No. 3 (2019) 859–871
MYU Tokyo
S & M 1820

Quick Response Code Binary Research
Based on Basic Image Processing
Yun Wu,1 Shaoyong Yu,2* and Mei Yang2¹College of Computer and Information Engineering, Xiamen University of Technology, Xiamen 361024, China²School of Mathematics and Information Engineering, Longyan University, Longyan City 364012, China(Received October 15, 2018; accepted February 8, 2019)

Keywords: QR code, binarization, block truncation coding

The goal of this paper is to binarize quick response (QR) codes with basic image processing
methods, so that they can be well recognized in extreme cases. In this paper, we avoid thecomplex computation that comes from sophisticated algorithms, and employ block truncation
coding (BTC) to simplify the computation to make processing fast. The final results show thatcomplex algorithms are not required in QR code binarization, and the basic image processing
algorithm can achieve faster and better processing results.

1.

Introduction

At present, the applications of quick response (QR) codes are booming. Phone numbers,
web addresses or postal addresses can be converted into QR codes for mobile devices to read.
However, changes in light and shadow in the external environment during image captureoften result in undeciphered or uninterpreted QR codes, such as insufficient or uneven light.
Therefore, various methods have been proposed to solve this problem, and these methods arenothing more than the methods put together by more complex algorithms such as the grayestimation formula or the Otsu method. Their computation is large and the program code iscomplex, which cannot meet modern people’s requirement of high processing speed. Thus, we
propose to replace the complicated algorithms with the basic image processing technique. The
following is a paper selected for comparison.(1)The global threshold method is a common and relatively simple binarization method, suchas the Otsu and histogram bimodal methods. However, these algorithms can only produce a
global threshold, and when the whole image is binarized, it may produce an all-black or allwhite image, which cannot be adjusted. The above problems can be effectively solved by thebinarization method based on the background grayscale.
Background grayscale binarization is effective in the image processing of nonuniform
brightness. However, the expansion of the background grayscale matrix requires a great deal ofcomputation and reduces the efficiency of binarization. In Fig. 1, the steps after modification
are as follows:*

Corresponding author: e-mail: 82018007@lyun.edu.cn
https://doi.org/10.18494/SAM.2019.2165
ISSN 0914-4935 © MYU K.K.
https://myukk.org/

860

Sensors and Materials, Vol. 31, No. 3 (2019)

Fig. 1.

Process flow diagram.

(1) Divide the block according to the original image.
(2) Calculate the value of each block through grayscale estimation.
(3) Follow the combined image interpolation method to generate adjustable backgroundgrayscale images and make them as large as the original image.
(4) By replacing the original image with an adjustable background grayscale image, thenoise can be removed, and the image can be enhanced. Overcome the shortcomings ofthreshold selection and image brightness inequality.
(5) Binarize using the Otsu method.
The grayscale matrix of the image is divided into the matrix set, and matrix B is one of
the submatrices, as shown in Eq. (1). The size of the submatrix should preserve details andsuppress noise. According to the experiment, select l = 1/16, where M and N are the width andheight of the original image, respectively, and l is the number of submatrices.

Sensors and Materials, Vol. 31, No. 3 (2019)861

 B11 … B1n 
Bm∗n =  … … …  Bm1 … Bmn 
i=

M
, j=
m

(1)

N
, l= i∗ jn

In Eq. (2), the background gray level of each block is calculated, where u is the averagegrayscale value of the original image, u′ is the average grayscale value of each block of theimage, and k is the standard deviation of each block of the image.
t = u′ − u + kσ

(2)

Finally, the size of the grayscale matrix is selected using the gray order value of each block,and k is the adjustment coefficient, from 0 to 1. In the experimental analysis, k = 0.3 is the mostappropriate.
t11 … t1 j Ri∗ j = … … … t … t 
ij 
 i1

(3)

If the block is low in brightness or in background, the values of u and c will be small, while
the background grayscale t will be smaller. In contrast, if the block is high in brightness and thebackground is excessive, the values of u and c will be large, and the background grayscale t will
be larger.
1.1

Increase in the combined interpolation of background grayscale

The original image is divided into different regions, which use different interpolation
algorithms to achieve the image quality maintained after magnification, while reducing
the purpose of the calculation. The general method of region segmentation requires image
segmentation. Considering the complexity of image segmentation, there is no uniform
algorithm for all images. In this paper, the first segmentation image is avoided, but in theoriginal image, the variance of the pixel value adjacent to the interpolation point is calculated
for the first time. If the variance is less than the threshold value T, the average of the four-point
pixel values, E, is directly used as the pixel value for interpolation calculation. In contrast, thecalculation is based on bicubic interpolation. The variance Var is calculated as
2

2

2

2

Var = ( E − f11 ) + ( E − f12 ) + ( E − f 21 ) + ( E − f 22 ) ,(4)

where f11, f12, f21, and f22 are the pixel values of the neighboring point of the current interpolation
point in the original image. E denotes the average of the four-point pixel values. To calculate

862

Sensors and Materials, Vol. 31, No. 3 (2019)E, multiplication and division are required five and three times, respectively. To calculate thevariance, multiplication and division are required four and seven times, respectively. In total,
multiplication and division are required nine and ten times, respectively; this calculation method
is relatively simpler than the bicubic interpolation that requires multiplication and division 70
and 45 times, respectively. Although every point of the image should be calculated once inthis calculation method, compared with the calculation using the bicubic interpolation method,
the calculation complexity is much less. For more image smoothing areas, the reduction incomputation complexity is clearer. The following experimental results verify the effectivenessof the algorithm. Selecting the threshold T is the first step of the algorithm. If the thresholdvalue is small, fewer pixels avoid the bicubic interpolation, and the image quality is closer to theresult of bicubic interpolation, whereas the amount of calculation is still large. In contrast, thelarger the threshold, the larger the number of pixels will avoid the bicubic interpolation, which
reduces the amount of computation but makes the image blurred. Var reflects the smoothness ofneighboring pixels. It is difficult to define a uniform threshold for different images. In different
environments, the threshold value should be adjusted frequently to meet the actual application
requirements. The experimental experience suggests that the reductions in computational
complexity and image quality are reasonable at the threshold T = 20. In practice, the thresholdshould be adjusted to about 20 primarily to obtain the most reasonable image. In this paper, thethreshold T = 20 is selected in the experiment. The algorithm flow is illustrated in Fig. 2.
1.2

Adjustment of grayscale and binarization of the original image

The adjusted image grayscale matrix Ir is obtained by subtracting the background grayscale
matrix from the previous step by using the original image grayscale matrix Ig. Then, the part ofthe image that is very dark owing to subtraction is adjusted. Finally, the Otsu method is used tobinarize the adjusted image grayscale matrix.

Fig. 2.

Joint interpolation process.

Sensors and Materials, Vol. 31, No. 3 (2019)

863

The Otsu method(2) is the automatic threshold value determination principle that iscommonly employed to select the threshold value of image binarization. Undoubtedly, the useof the Otsu method is not limited to the image binarization. It can be used for all the selected
thresholds. Since Otsu is a threshold selection criterion, before using Otsu, we must obtain the
distribution of the state space that we want to segment with a threshold.
In the case of image binarization using Otsu, since pixel values are to be segmented, thedistribution of pixel values (i.e., histogram of pixels) should be obtained. The process of image
binarization using Otsu is as follows:
Step 1. Obtain the histogram of the video (Fig. 3).
Step 2. Find the optimal threshold value from the histogram using the Otsu method.
Step 3. Binarize the image with the threshold found (Fig. 4).
Otsu’s task is to find the optimal threshold from the state distribution, i.e., Step 2 (Fig. 5).

Fig. 3.

(Color online) Grayscale image and histogram.

Fig. 4. (Color online) Schematic diag ram notrepresenting the Otsu threshold position of thehistogram.

Fig. 5.

After Otsu-based binarization.

864

2.

Sensors and Materials, Vol. 31, No. 3 (2019)

Improved Method

In this paper, the basic image processing is used to make the QR code interpreted promptly
and correctly and to increase the interpretion rate. First, histogram equalization is used toenhance the image contrast to improve the later binarization. Subsequently, block truncation
coding (BTC) was used to divide the image into several small blocks for binarization. Finally,noise is removed to achieve a good QR code binarization image. The flow is shown in Fig. 6.

Fig. 6.

Process flow diagram.

Sensors and Materials, Vol. 31, No. 3 (2019)

2.1

865

Histogram equalization(3)Histogram equalization is an image processing program designed using statistical methods.
It helps to spread the color distribution of statistical histograms evenly in the histogram, i.e.,
to make the histogram distribution of a graph even. Likewise, a look-up table (LUT) is also
employed.
(a) is the original gray-level concentration histogram;(b) is a method of partially reinforcing contrast;(c) is a method of equalizing the entire image, as shown in Fig. 7.
Here, the (c) method is employed. After all, the whole picture is to be processed rather than
the small areas. The method is expressed as shown in Fig. 8.

(a) Original grayscale concentration bar graph
Number of pixels

The slash part is to enhance the contrast

Grayscale concentration maximum

Grayscale concentration

Number of pixels

Number of pixels

Grayscale concentration m inimum

Grayscale concentration

Grayscale concentration(b) Take out only the part that will enhance thecontrast and expand the grayscale diagram

Fig. 7.

( c ) Grayscale concentration straight bar
graph equalization processing

Method of equalization.

GrayscaleClass
Number of pixels ineach layer of the original
image
Starting from the height of the graylevel, a unique group of every 5 pixels,
assigned to the new gray level inorder.
Number of pixels of eachlevel after equalization

Fig. 8.

Method of image processing.

866

Sensors and Materials, Vol. 31, No. 3 (2019)

2.2

Dynamic critical binarization(3)According to the results of the original image equalization, if all the blocks are binarizedwith a single critical value, the data that we want may be eliminated and the amount of data that
we do not need will be increased instead. Therefore, we use different thresholds for each block.
The procedure of the dynamic critical value method is to change the critical value of eachpixel. As shown in Fig. 9, the image is first divided into blocks, and the critical value is selected
at each grid point. Second, as shown in Fig. 10, the critical value of each grid point is used
to perform quadratic linear interpolation calculation to obtain the critical value of each pixel.
The critical value t(x,y) of each pixel is equal to four grid points around the pixel (x,y) to be
calculated, which is calculated using Eq. (5) according to the corresponding distance ratio.
t ( x, y ) = (1 − q ){(1 − p ) ∗ t ( u , v ) + p ∗ t ( u + 1, v )} + q {(1 − p ) ∗ t ( u , v + 1) + p ∗ t ( u + 1, v + 1)} (5)Zone(0,0) Zone(1,0)
Grid(0,0)Zone(DIV-1,0)
Grid(DIV-1,0)

Grid(1,0)
Grid(u,v)

Zone(u,v)
Grid(0,DIV-1)

Grid(DIV-1,DIV-1)

Zone(0,DIV-1)

Zone(DIV-1,DIV-1)

Fig. 9.

The critical value t(u,v) of Grid(u,v)

Dynamic critical value method.

The critical value t(u+1,v) of Grid(u+1,v)

The critical value of the pixel to be calculated.

The critical value t(u,v+1) of Grid(u,v+1)

The critical value t(u+1,v+1) of Grid(u+1,v+1)

Fig. 10. Quadratic linear interpolation.

Sensors and Materials, Vol. 31, No. 3 (2019)

2.3

867

Erosion and expansion(3)From the image after equalization binarization, we can find a lot of noise around the image.
Most of these noises are small noises with only a few pixels together. Therefore, we use
expansion and erosion to remove the small noises and make the whole image cleaner. Expansion
refers to the point at which one of the 8 neighboring pixels around a pixel is 1, and the pixel is
set to 1 and the others to 0. Erosion refers to the point at which one of the 8 neighboring pixels
around a pixel is 0, and the pixel is set to 0 and the others to 1. As shown in Fig. 11, when theimage undertakes the processing from expansion to erosion, black noise is eliminated in the
expansion. As shown in Fig. 12, white noise is eliminated during erosion when the image
undertakes the processing from erosion to expansion.

3.

Experimental Results and Analysis

To verify the necessity of our proposed method, we use the 8-megapixel lens commonly usedon ordinary phones. We take 4 images of QR codes in a low light source and an uneven lightsource for the comparison of the results. The size of the original video is 512 × 512 overall.
During BTC processing, since we do not know which block size is the most appropriate result,
we conduct a processing for different block sizes to find the most suitable size.(4–7)

Expansion

Fig. 11. (Color online) Diagram of expansion.

ErosionFig. 12. (Color online) Diagram of erosion.

868

3.1

Sensors and Materials, Vol. 31, No. 3 (2019)

Full dark image

We take 4 images of QR codes in the low light source for the comparison of the results.
Figures 13–16 show four images of test processes.
3.2

Semidark image

We take 4 images of QR codes in the uneven light source for the comparison of the results.
Figures 17–20 show four images of test processes. In Table 1, we compare the time spent.
According to the full shadow image, the processing range is too large or too small, whichmakes the noise even louder. The smaller the scale, the less the data will be lost. The Otsu
method has no way of accurately finding the foreground and background in processing
semidark images. However, the quality of images processed by the Otsu method is much higher.
Although the image sizes of 6 × 16 and 32 × 32 can be fully interpreted, the image informationof 32 × 32 will be more damaged. Although the APP can be successfully interpreted faster than
16 × 16, we will choose 16 × 16 as the final result.

(a) Original Image(b) Equalization(c) Block Size 16(a) Original Image(b) Equalization(c) Block Size 16(d) Block Size 32(e) Block Size 64(f) Block Size 128(d) Block Size 32(e) Block Size 64(f) Block Size 128(g) Block Size 256(h) Block Size 512(i) Method of Literature(g) Block Size 256(h) Block Size 512(i) Method of Literature

Fig. 13. (Color online) Full dark QR code image test 1.

Fig. 14. (Color online) Full dark QR code image test 2.

Sensors and Materials, Vol. 31, No. 3 (2019)869(a) Original Image(b) Equalization(c) Block Size 16(a) Original Image(b) Equalization(c) Block Size 16(d) Block Size 32(e) Block Size 64(f) Block Size 128(d) Block Size 32(e) Block Size 64(f) Block Size 128(g) Block Size 256(h) Block Size 512(i) Method of Literature(g) Block Size 256(h) Block Size 512(i) Method of Literature

Fig. 15. (Color online) Full dark QR code image test 3.

Fig. 16. (Color online) Full dark QR code image test 4.

(a) Original Image(b) Equalization(c) Block Size 16(a) Original Image(b) Equalization(c) Block Size 16(d) Block Size 32(e) Block Size 64(f) Block Size 128(d) Block Size 32(e) Block Size 64(f) Block Size 128(g) Block Size 256(h) Block Size 512(i) Method of Literature(g) Block Size 256(h) Block Size 512(i) Method of Literature

Fig. 17. (Color online) Semidark QR code image test 1.

Fig. 18. (Color online) Semidark QR code image test 2.

870

Sensors and Materials, Vol. 31, No. 3 (2019)(a) Original Image(b) Equalization(c) Block Size 16(a) Original Image(b) Equalization(c) Block Size 16(d) Block Size 32(e) Block Size 64(f) Block Size 128(d) Block Size 32(e) Block Size 64(f) Block Size 128(g) Block Size 256(h) Block Size 512(i) Method of Literature(g) Block Size 256(h) Block Size 512(i) Method of Literature

Fig. 19. (Color online) Semidark QR code image test 3.

Fig. 20. (Color online) Semidark QR code image test 4.

Table 1
4 QR code images in full dark and semidark with processing time.
(1)
Otsu(2)16
32
64
Full dark image (ms)Fig. 13
208
74
93
88
82
Fig. 14
207
68
94
88
83
Fig. 15
208
69
94
88
82
Fig. 16
210
69
94
88
83
Correct rate
75%
75%
100%
100%
100%
Semidark image (ms)Fig. 17
208
66
90
84
84
Fig. 18
207
74
91
82
80
Fig. 19
212
71
92
82
81
Fig. 20
212
72
91
80
76
Correct rate
0%
0%
100%
100%
0%

4.

128

256

512

83
81
84
82
100%

81
83
83
82
100%

83
84
83
82
0%

83
78
80
77
0%

84
81
75
75
0%

83
82
82
75
0%

Conclusion

The speed and image quality of QR code binarization based on the basic image processing
algorithm are not inferior to those of the complex algorithm. If you want to improve the speed
further, you may need to do some processing on the hardware side. There should not be muchroom for improvement on the algorithmic instruction cycle. Therefore, in the next stage,
research on hardware should be of greater significance.

Sensors and Materials, Vol. 31, No. 3 (2019)871

Acknowledgments
This work was supported by the National Science Foundation of Fujian Province of China (No.
2018J01575) and the Project of Scientific Climbing Plan by Xiamen University of Technology
No. XPDKQ18015.

References
1 Y. Zhang, T. Gao, D. Li, and H. Lin, 2012 2nd Int. Conf. Consumer Electronics, Communications andNetworks (CECNet) (IEEE, 2012) 21–23.
2 Otsu Function Introduction: http://www.dotblogs.com.tw/dragon229/archive/2012/12/28/86092.aspx
3 S. Inoue and N. Yagi: C Language Digital Image Processing (2010) 27.
4 Z. Xiong, H. Cuiqun, L. Guodong, and L. Zhijun: 2nd Int. Conf. Signal Processing Systems (ICSPS) 3 (IEEE,
2010) 317–320.
5 J. Zhou, Y. Liu, and P. Li: Int. Conf. Multimedia Technology (ICMT) (IEEE, 2010) 1–4.
6 J. Bernsen: Proc. 8th Int. Conf. Pattern Recognition (IEEE, 1986) 1251–1255.
7 Bicubic interpolation and matlab design: http://wenku.baidu.com/view/34dea625192e45361166f504.html

About the Authors
Yun Wu received her Ph.D. degree from Xiamen University in 2007. Her
research interests are in the areas of artificial intelligence and big data. Her
scientific contribution to AI has more to do with soft computing andclustering algorithms. (ywu@xmut.edu.cn)

Shaoyong Yu received his Ph.D. degree from Xiamen University in 2017. He
is also an associate professor in the School of Mathematics and Information
Engineering of Longyan University. His research interests are in the areas ofcomputer vision and deep learning. (82018007@lyun.edu.cn)

		

Mei Yang is a lecturer and teacher in the School of Mathematics andInformation Engineering of Longyan University. Her research interests are in
the areas of software development and artificial intelligence.
(wulv07@163.com)