Aesthetic QR Code On Modified Systematic Encoding
Aesthetic QR Code On Modified Systematic Encoding
1 JANUARY 2017
42
PAPER Special Section on Enriched Multimedia —New Technology Trends in Creation, Utilization and Protection of Multimedia Information—
SUMMARY Quick Response (QR) code is a two dimensional barcode drawback is that it sacrifices the readability of original QR
widely used in many applications. A standard QR code consists of black codes with small displayable size. The second class modi-
and white square modules, and it appears randomized patterns. By modify-
fies the size and color of modules according to the pixel of
ing the modules using certain rule, it is possible to display a logo image on
the QR code. Such a QR code is called an aesthetic QR code. In this paper, image. Visualead [7] and LogoQ [8] keep a concentric re-
we change the encoding method of the Reed-Solomon (RS) code to produce gion of modules untouched and uniformly blend the neigh-
an aesthetic QR code without sacrificing its error correcting capability. The boring regions with pixels of an image preserving the origi-
proposed method randomly produces candidates of RS blocks and finds the nal contrast. The third class changes the padding codewords
best one during encoding. Considering an image to be displayed, we also
introduce a weighting function during random selection that classifies the
to display an image on the QR code [9], [10]. The possi-
visually important regions in the image. We further investigate the shape of ble area on which the image is displayed is restricted due to
modules which represents the image and consider the trade-off between the the standardized structure of QR code. A free software of
visual quality and its readability. As a result, we can produce a beautiful the QR-JAM MAKER [11] is openly available. Its main re-
aesthetic QR code, which still can be decoded by standard QR code reader.
striction is the standardized structure of Reed-Solomon (RS)
key words: 2-dimensional code, aesthetic code, parity check matrix
code [12] employed in QR code.
Some other works studied combination of above
1. Introduction
classes and image processing techniques to effectively en-
hance the visual quality. Chu et al. [13] applied the half-
QR code is a two-dimensional code consisting of black toning technique for displaying image to produce an aes-
and white square modules. It is originally developed by thetic QR code. Fang et al. [14] considered the sampling
Denso Wave [1] as an effective way for accessing digital process and error correction to optimize the generation pro-
data by forming a machine-readable format. It can carry cedure. Zhang et al. [15] proposed two-stage approach that
more information than conventional barcodes and can be is a combination of module-based and pixel-based encod-
read very quickly by software installed in smart phones. The ings. Even though these methods can enhance the visual ap-
QR code was standardized as JIS (Japanese Industrial Stan- pearance, they try to reduce the noise-like appearance at the
dards) standard in 2004 (JIS X0510) [2] and ISO/IEC stan- center of image by using error correcting capability or shape
dard in 2000 (ISO/IEC 18004) [3]. of modules. The basic white/black patterns at the important
A standard QR code contains only black and white region of an image are not removed in a literature.
square modules and its appearance has noisy looks. There In this paper, we develop a fourth class for generating
are many approaches for producing aesthetic QR codes by an aesthetic QR code based on the encoding method of RS
displaying images on a QR code. For a given message code which allows us to select the display position without
and image, it is desirable to automatically generate such a sacrificing the error correcting capability. The preliminary
QR code because manually designed barcodes are too ex- version of such an encoding method was presented in [16]∗ .
pensive. It is also required that the aesthetic QR codes be As the RS code belongs to a family of linear code over a
readable by standardized decoders. The conventional ap- finite field [12], the set of RS blocks generated by using a
proaches satisfying these requirements can be categorized certain parity check matrix becomes just equal to the set of
into three classes. the RS blocks generated from the matrix which is calcu-
The first class globally transforms an input image, and lated by column operation of the parity check matrix. Even
superimposes it on part of the QR code [4]–[6]. It modifies though the correspondence between the information and RS
several modules of an original QR code within a possible er- block is different, the set of RS blocks are equal. Based on
ror correcting capability to display a small logo image. The this property, the positions of information symbols in a RS
Manuscript received March 21, 2016. block are changed in the proposed method. Since the stan-
Manuscript revised August 1, 2016. dard QR code reader only extract first successive symbols
Manuscript publicized October 7, 2016. in RS blocks, the proposed method fixes first such positions
†
The author is with the Graduate School of Natural Science and for representing data and controls the positions of the other
Technology, Okayama University, Okayama-shi, 700–8530 Japan.
††
The author is with the Graduate School of Engineering, Kobe
∗
University, Kobe-shi, 657–8501 Japan. At the early stage of this study, we regarded the method as
a) E-mail: kminoru@okayama-u.ac.jp non-systematic encoding, but as explained in Sect. 2.2 it is a kind
DOI: 10.1587/transinf.2016MUP0002 of systematic encoding by definition of error correcting code.
Copyright
c 2017 The Institute of Electronics, Information and Communication Engineers
KURIBAYASHI and MORII: AESTHETIC QR CODE BASED ON MODIFIED SYSTEMATIC ENCODING FUNCTION
43
the bits according to their coordinates in order to make the Let δ = (δ1 , . . . , δk ) be information symbols of length
QR code easily readable. During encoding, each element of k, Then, the parity symbols p = (p1 , . . . , pn−k ) is calculated
a selected mask pattern is XORed with a current module. from δ using a systematic encoding function enc(), and the
generated RS block c is represented by
2.2 Encoding of Reed-Solomon Code
c = enc(δ) = (c1 , . . . , ck , ck+1 , . . . , cn ) (5)
In a standard QR code, the systematic encoding method of = (δ1 , . . . , δk , p1 , . . . , pn−k ). (6)
RS code is employed to generate the RS block. The system-
atic encoding means that the information symbols appear The information symbols δ can be decoded by performing a
directly as part of the RS block. For the convenience, dur- decoder dec() from a distorted RS block c if the bit errors
ing decoding, the information appeares only at the first k are within an error correcting capability.
symbols of the RS block in the QR code.
The RS code is based on the polynomial g(x) = x8 + 3. Proposed Aesthetic QR Code
x + x3 + x2 + 1 over finite field GF(28 ), and the code is
4
punctured through the consistent deletion of parity coordi- In this section, we propose two encoding methods for gen-
nates from each RS block. As the RS code is maximum erating a better RS block in which binary string placed on
distance separable (MDS) code, the elimination of a coordi- a QR code is similar to the module patterns of logo image.
nate in a code can reduce the minimum distance of the code The best RS block can be found by an exhaustive search
by 1 with each successive puncturing operation. In the QR among candidates. However, the number of candidates is
code, the eliminated coordinate of parity check matrix is the extremely large, it is computationally difficult. Instead, the
first 255 − n rows out of 255. When the minimum distance proposed method randomly and uniformly selects the candi-
is d and the root of the polynomial g(x) is α, the punctured dates and checks the similarity with the module pattern, and
parity check matrix H is given by it is called as “random method”. The other method consid-
ers the local characteristics of a logo image by calculating
⎡ ⎤
⎢⎢⎢ α0×(n−1) ... α0×0 ⎥⎥
⎥⎥⎥ weights in order to control the visual quality, and it is called
⎢⎢ .. .. ..
H = ⎢⎢⎢⎢ . . .
⎥⎥⎥ ,
⎥⎥ (1) as “weighting method”.
⎢⎣
(d−2)×0 ⎦
α(d−2)×(n−1)
... α
3.1 Basic Idea
where α = 1. Then, for any RS block c, the following
255
equation must be satisfied. As mentioned in Sect. 2.2, the code space generated from
H coincides with the code space generated from H (sys) . It
cH T = 0. (2) means that for a given δ, the RS block generated from H (sys)
is one of the RS blocks of H. Therefore, the code space is
Here, we suppose that a code space contains all RS same, but the assignment from information symbols is dif-
blocks generated from the matrix H. From the coding the- ferent if H (sys) is modified from H by using column opera-
ory, two codes that differ only in the arrangement of sym- tions. Even though the parity check matrix is different, the
bols have the same probability of error, namely the same encoding function based on the matrix generates a certain
error correcting property. Specifically, the matrix H can be systematic RS block. It implies that the information sym-
modified by the combination of column operations without bols appear not at the first k symbols of the RS block, but
changing the code space. It means that the RS block gener- at certain positions of the RS block. Such a systematic en-
ated from such a modified parity check matrix is one of the coding function can be designed by carefully selecting the
RS blocks generated from the matrix H. In this case, it is column operations to the parity check matrix.
possible to use the same decoder for a given RS block, but Let C be the group of all RS blocks generated by enc(),
the decoded information is different. Based on such a prop- namely, ∀c ∈ C. Then, the RS blocks c encoded by a cer-
erty, the systematic encoding method prepares the following tain systematic encoding method satisfies ∀c ∈ C. Thus,
matrix H (sys) : we can obtain certain information symbols from dec(c ). If
H (sys) = − PT In−k , (3) no error occurrs, then the first k symbols of the RS block
c is decoded as information symbols. For a given index
where, P is a k × (n − k) matrix, In−k is an (n − k) × (n − k) θ = (θ1 , θ2 , . . . , θk ), the k symbols of the RS block c is rep-
identify matrix, and T stands for a transposition. The gen- resented by
erator matrix G(sys) can be easily calculated from the matrix
H (sys) . cθi = δi , (1 ≤ i ≤ k), (7)
G(sys) = Ik P (4) where 1 ≤ θi ≤ n and θi θ j for i j. The other n − k
symbols are calculated according to these k symbols using
By multiplying the matrix G(sys) with a vector of informa- the employed systematic encoding function encθ ().
tion symbols, the systematic RS block is obtained. For con- Suppose that the first k̂ (< k) symbols are used to rep-
venience, such an encoding function is denoted by enc(). resent a data to be encoded and the remain k − k̂ symbols are
KURIBAYASHI and MORII: AESTHETIC QR CODE BASED ON MODIFIED SYSTEMATIC ENCODING FUNCTION
45
regarded as padding codewords. In such a case, it is possible from the pixel values of logo image to be displayed.
to use the following index.
3.3 Color Translation
θ k̂ = (1, 2, . . . , k̂, θk̂+1 , . . . , θk ) (8)
According to the standardized format of QR code, each
It means that there are C(n− k̂, k− k̂) candidates for the index
module is basically represented by black and white. Nev-
θ k̂ , where C(a, b) stands for the number of b-combinations
ertheless, it is possible to use color for modules because of
from a given set of a elements. In short, we can freely select
the following reason. When a QR code is taken by a certain
the positions for padding codewords within the range [k̂ +
camera device, the brightness of each module is first calcu-
1, n] at the RS block.
lated in the decoding algorithm, and then, the color space
is translated into luminance component. As the translation
3.2 Random Method algorithm is not defined in the specification of QR code de-
coder, there may be some methods to determine the black
When the amount of encoding data is small, the designable and white. In the proposed method, we heuristically ex-
area becomes large in the method. If a QR code has m RS amine the decodability of color space by using some smart
blocks whose information symbols are kt , (1 ≤ t ≤ m) bytes phones and develop the following color translation proce-
and the data to be encoded is σ bytes, then the size of des- dure at the production of aesthetic QR code.
ignable area is ( m t=1 kt ) − σ bytes. Suppose that an image is square size with L × L pix-
Without loss of generality, the data to be encoded is els and each pixel is represented by RGB color components.
composed of σ bytes and it is partitioned into m segment Using a certain conversion algorithm equipped at a QR code
of length k̂t , (1 ≤ t ≤ m), namely m t=1 k̂t = σ. For each reader, a binary matrix Bi, j , (1 ≤ i, j ≤ 17 + 4v) is calculated
segment, the RS block ct is calculated by the systematic from the input image for the given version v of QR code. In
encoding function encθ k̂ t . our method, the following algorithm is used as the conver-
First, each pixel of an image is regarded as a module sion.
of ideal aesthetic QR code except for the function patterns.
Step 1 The scale of the input image is changed to be the
The pixel values are classified into black/white module at
same size of the given version v of QR code.
the encoding, and the binarized pixels are produced. The bi-
Step 2 The RGB color components are translated into YUV
narized pixels may not coincide with the binary represention
color components, and the luminance (Y) components
of RS blocks. Allowing some errors, we generate several RS
Yi, j , (1 ≤ i, j ≤ 17 + 4v) are obtained.
blocks by changing θ k̂ t and choose the best one whose Ham-
Step 3 The average Ȳ of the values at its center square,
ming distance is minimum. The procedure to make aesthetic
which size is the quarter of the original image size, is
QR codes is described as follows.
calculated.
Step 1 Assign pixels of an image to modules of a QR code, 3L 3L
4 4
and binarize the modules with the threshold determined 4
Ȳ = 2 Yi, j (9)
by the average of all RGB values. L
i= L4 j= L4
Step 2 Operate a predetermined masking pattern to the bi-
nary matrix, and replace σ symbols of the masked Step 4 The binary matrix Bi, j is determined by the follow-
image with information symbols, which are never ing rule:
changed in the following steps.
Step 3 Partition the masked image into m sequences which 1 if Yi, j > Ȳ
Bi, j = (10)
are corresponding to the RS blocks placed on the QR 0 otherwise
code in an interleaved order. We denote the m se-
Although the binarization of the reduced-size image is
quences by η t , (1 ≤ t ≤ m).
slightly varied according to the resizing algorithm, the im-
Step 4 For 1 ≤ t ≤ m, find the best RS block ċt , whose
pact on the produced aesthetic QR code is small because of
Hamming distance from η t becomes minimum, by
the low resolution. In case of scaling-up, the visual quality
changing the index θ k̂ t .
is strongly affected by the resizing alrogithm. In practical,
Step 5 Replace the best RS block ċt with η t for 1 ≤ t ≤ m.
however, an input image is usually larger than a QR code.
Step 6 Operate the predetermined masking pattern again to
Notice that the binarized ideal QR code is composed of
cancel the masking operation at step2.
the binary matrix Bi, j except for the function patterns. At the
There are C(n − k̂t , kt − k̂t ) candidates for the index θ k̂ t Step 3 in the random method, the sequences η t are extracted
for (1 ≤ t ≤ m). It is computationally difficult to check from the binary matrix Bi, j . After the determination of RS
all candidates for the search in Step 4. In the above pro- blocks ċt , each module of QR code is modified according to
cedure, the index θ k̂ t are randomly and uniformly selected the original RGB color components in order not to change
from all possible candidates, and the trial is bounded to N the color balance. Let βi, j , (1 ≤ i, j ≤ 17 + 4v) be the binary
times. Among N candidates of QR codes, we select the best represented RS blocks placed on the matrix of QR code. It
one which has the minimum number of modules different is noted that βi, j must satisfy the black and white function
IEICE TRANS. INF. & SYST., VOL.E100–D, NO.1 JANUARY 2017
46
patterns at the corresponding positions. We finally generate η t . By changing the index θ k̂ t under the constraint of such a
a QR code involving a given image as follows. rule, the best RS blocks ċt are selected under the measure-
If βi, j = 1, then ment of Hamming distance.
Among kt information symbols in t-th RS block, the
Yi, j if Yi, j > Ȳ +
Yi, j = , (11) first k̂t symbols are fixed to represent data and the remain
Ȳi, j + otherwise kt − k̂t symbols are assumed to be padding codewords. The
otherwise, weight sequence indicates the priority for the selection of
kt − k̂t symbols from n − kt symbols. If we choose kt − k̂t
Yi, j if Yi, j < Ȳ − symbols which have highest kt − k̂t weights in w t , the cor-
Yi, j = , (12)
Ȳi, j − otherwise responding RS block can be calculated. However, in such
a case, the Hamming distance is not always small. In or-
where is a threshold for ensuring the readability. The RGB der to find the best RS block which has minimum Hamming
color components are translated from the modified lumi- distance among some candidates, we choose symbols which
nance components Y as well as the original U and V com- have highest kt − k̂t + α weights, where α = 1, 2, · · ·. By
ponents, and the color QR code is finally obtained. increasing α, the number of candidates is exponentially in-
creased. For a given number N, α is adjusted in the proposed
3.4 Weighting Method
method. For example, when the version of QR code is 5L,
k = 108 and n = 134. In case of k̂ = 50, the number of
In the random method, the index θ k̂ t is randomly generated
candidates is C(59, 58) = C(59, 1) = 59 if α = 1, and it is
without any strategies. Considering the characteristics of an
C(60, 58) = C(60, 2) = 1770 if α = 2. When N = 500, we
image to be displayed, we introduce a weighting function to
determine α = 2, and generate 500 candidates by randomly
classify perceptually important regions with the others.
choosing kt − k̂t = 58 symbols among 60 symbols which
It is widely recognized that noisy regions of an image
have highest 60 weights. Finally we determine the best RS
are less sensitive to modification than flat regions. It is also
block among 500 candidates.
reasonable to assume that the center region of an image is
much more important than its surroundings. Based upon the
3.5 Numerical Evaluation
characteristics, we calculate weights for modules.
After the color translation, the Laplacian filter LF() is
In order to evaluate the performance, we implement two pro-
operated to the matrix Bi, j , which discrete convolution ker-
posed methods and an original method for generating RS
nel is given by
block using a same color translation algorithm. Here, the
⎡ ⎤
⎢⎢⎢ −1 −1 −1 ⎥⎥⎥ original method changes the padding codewords to display
⎢⎢⎢ −1 8 −1 ⎥⎥⎥ . an image on the QR code such as QR-JAM and [9], [10].
⎢⎣ ⎥⎦
−1 −1 −1 For convenience, the method explained in Sect. 3.2 is called
“Prop.I” and the method in Sect. 3.4 is called “Prop.II”.
The weight matrix Wi, j is calculated by We use four RGB color images of different size, which
Wi, j = |LF(Bi, j )|, (13) are shown in Fig. 2. We use the OpenCV library [18] for
resizing an input image. The encoding data is the URL:
where |a| returns the absolute value of a. It is noticed that http://www.okayama-u.ac.jp, which is represented by
0 ≤ Wi, j ≤ 8 because Bi, j ∈ {0, 1}. At the γ-th outer end of
the matrix for 0 ≤ γ ≤ 7, if Wi, j < 8 − γ, then the value is
replaced as Wi, j = 8 − γ.
The coordinate of the matrix Wi, j is corresponding to
that of QR code. As the symbols of t-th RS block η t are
placed on the matrix of QR code in an interleaved order, the
symbols of the weight sequence w t is also placed on the ma-
trix Wi, j . Namely, w t is selected from the matrix Wi, j in the
same rule as the placement of RS block in the matrix of QR
code. Remember that the symbols of RS block employed in
a QR code are not binary, and represented by 8 bits. In addi-
tion, 8 modules are placed on a certain neighboring modules
which positions depend on the version v. Considering such
neighboring positions and their values w t , the index θ k̂ t is
determined to mainly select flat regions at the center of QR
code for the assignment of as many as possible information
symbols. It is worth-mentioning that the modules at noisy
regions and the outer end of the QR code tend to be the par-
ity symbols of RS block, and their values may differ from Fig. 2 Original images for displaying on a QR code.
KURIBAYASHI and MORII: AESTHETIC QR CODE BASED ON MODIFIED SYSTEMATIC ENCODING FUNCTION
47
Fig. 3 Comparison of the visual appearance of aesthetic QR codes when the version is 10M, where
(a)–(e) are produced by the Prop.I method and (f)–(j) are by the Prop.II method.
Fig. 4 Comparison of the visual appearance of aesthetic QR codes, where (a)–(e) are version 10L and
(f)–(j) are version 10M.
do is the modification of module shape as well as the color resolution of the obtained QR code is improved. For conve-
according to a logo image, such a method is equivalent to nience, such an operation is denoted by M1 . For ensuring
the conventional methods like Visualead [7], [8]. the readability, however, is uniformly added to these sub-
modules. In case of βi, j = Bi, j , the original luminance value
4. Enrichment of Visual Quality Yi, j basically judges correct value by itself. Therefore, the
value of can be decreased without seriously degrading the
Although the visual quality is improved by the introduc- readabiliy. As the center sub-module is important for most
tion of weight matrix at the encoding of RS block, the readers to determine black/white, is introduced only for
low resolution of the displayed image still reduces its ben- such a sub-module in the operation M2 . These operations
efit. The reason is due to use of one pixel for representing M1 and M2 can be represented by the following matrices.
one module. The resolution of the displayed logo image is ⎧⎡ ⎤ ⎡ ⎤⎫
(17 + 4v) × (17 + 4v) pixels (e.g. only 37 × 37 pixels for ⎪
⎪ ⎢ 1 1 1 ⎥⎥⎥ ⎢⎢⎢ 1 1 1 ⎥⎥⎥⎪ ⎪
⎨⎢⎢⎢⎢
⎪ ⎪
⎬
version 5). The square shape of modules also degrades the M1 = ⎪⎪ ⎢⎣ 1 1 1 ⎥⎥⎥⎥⎦ , ⎢⎢⎢⎢⎣ 1 1 1 ⎥⎥⎥⎥⎦⎪
⎢ ⎪
⎪
⎩ 1 1 1 ⎪
visual appearance. 1 1 1 ⎭
One simple method to increase the resolution is to use ⎧⎡ ⎤ ⎡ ⎤⎫
⎪
⎪ ⎢ 0 0 0 ⎥⎥⎥ ⎢⎢⎢ 1 1 1 ⎥⎥⎥⎪ ⎪
higher version of QR code. However, higher the version of ⎨⎢⎢⎢⎢
⎪ ⎥⎥⎥ , ⎢⎢⎢ 1 ⎥⎥⎥⎪⎬
QR code becomes, the more difficult it is to read by an op- M2 = ⎪
⎪ ⎢⎢ 0 1 0 ⎥⎦ ⎢⎣ 1 1 ⎥⎦⎪
⎪
⎩⎣ 0
⎪
0 0 1 1 1
⎪
⎭
tical device as the module size becomes small under a con-
stant size of QR code. In addition, most modules become
padding codewords wasting a space. The left matrix is used for the modules satisfying Bi, j = βi, j ,
Our idea is to assign 3 × 3 sub-modules for each mod- where “1” stands for the sub-module that is modified ac-
ule except for the finder pattern modules placed at corners cording to Eq. (11) and Eq. (12), and “0” is the sub-module
of QR code. The QR code reader estimates the module size that uses the original luminance value Yi, j . The right matrix
from the finder pattern, the module shape is not modified. It is the modules that become Bi, j βi, j .
is possible to only change the center of 3 × 3 sub-modules if In case of βi, j Bi, j , it is also possible change the strat-
necessary to generate the aesthetic QR code because most of egy for performing Eq. (11) and Eq. (12) to sub-modules. As
QR code readers check the center region of module to deter- mentioned above, the center sub-module is the most impor-
mine black/white. However, depending on the performance tant one among 9 sub-modules. Considering the symmetric
of optical device, the readability must be degraded. On the structure, the following methods M3 and M4 can be good
other hand, if the luminance values of 3 × 3 sub-modules are candidates.
⎧⎡ ⎤ ⎡ ⎤⎫
uniformly represented by the luminance value of the module ⎪
⎪ ⎢ 0 0 0 ⎥⎥⎥ ⎢⎢⎢ 0 1 0 ⎥⎥⎥⎪ ⎪
⎨⎢⎢⎢⎢
⎪ ⎪
⎥⎥⎥⎥ , ⎢⎢⎢⎢ 1 1 1 ⎥⎥⎥⎥⎬
Yi, j and are modified by using Eqs. (11) and (12), the visual M3 = ⎪⎪ ⎢
⎢
⎣
0 1 0
⎦ ⎣ ⎦⎪
⎪
⎪
⎩ 0 0 0 ⎪
quality is still low. Considering the characteristics of popu- 0 1 0 ⎭
lar QR code readers, we examine some types of sub-module
⎧⎡ ⎤ ⎡ ⎤⎫
representation method. ⎪
⎪ ⎢ 0 0 0 ⎥⎥⎥ ⎢⎢⎢ 0 0 0 ⎥⎥⎥⎪ ⎪
⎨⎢⎢⎢⎢
⎪ ⎥⎥⎥ , ⎢⎢⎢ 0 ⎥⎥⎥⎪⎬
Suppose that the luminance values of sub-modules M4 = ⎪
⎪ ⎢⎢ 0 1 0 ⎥⎦ ⎢⎣ 1 0 ⎥⎦⎪
⎪
are respectively derived from a given logo image, and the ⎩⎣ 0
⎪
0 0 0 0 0
⎪
⎭
Eqs. (11) and (12) are applied respectively for each sub-
module to generate an aesthetic QR code. In such a case, the
KURIBAYASHI and MORII: AESTHETIC QR CODE BASED ON MODIFIED SYSTEMATIC ENCODING FUNCTION
49