0% found this document useful (0 votes)
32 views10 pages

2022 Comparison of The Similarity Between Two Quantum Images

The document proposes three quantum algorithms for comparing the similarity between two quantum images represented using NEQR and NCQI. It summarizes the algorithms in three steps: 1) comparing corresponding qubits in the two images and generating auxiliary qubits, 2) applying quantum operations to the auxiliary qubits, and 3) measuring the auxiliary qubits to determine image similarity. The algorithms are applied to binary, grey, and color images, and experiments using IBMQ and simulations demonstrate the effectiveness of the approaches.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views10 pages

2022 Comparison of The Similarity Between Two Quantum Images

The document proposes three quantum algorithms for comparing the similarity between two quantum images represented using NEQR and NCQI. It summarizes the algorithms in three steps: 1) comparing corresponding qubits in the two images and generating auxiliary qubits, 2) applying quantum operations to the auxiliary qubits, and 3) measuring the auxiliary qubits to determine image similarity. The algorithms are applied to binary, grey, and color images, and experiments using IBMQ and simulations demonstrate the effectiveness of the approaches.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

www.nature.

com/scientificreports

OPEN Comparison of the similarity


between two quantum images
You‑hang Liu*, Zai‑dong Qi & Qiang Liu

Comparing the similarity between digital images is an important subroutine in various image
processing algorithms. In this study, we present three quantum algorithms for comparing the
similarity between two quantum images. These algorithms are applied to binary, grey and color
images for the first time. Without considering the image preparation, the proposed algorithms achieve
exponential acceleration than the existing quantum and classical methods in all three cases. At the
end of this paper, an experiment based on the real quantum computer of IBMQ and simulations verify
the effectiveness of the algorithms.

After Google realizing “quantum supremacy” in 2­ 0191, quantum computing has aroused the great interest of
the public. Exploiting quantum mechanics such as superposition and entanglement, quantum computing shows
an overwhelming computing power advantage in some certain problems. Nonetheless, on account of the few
quantum algorithms, these problems were extremely limited for more than a decade after the concept of the
quantum computer was first proposed by Richard Feynman in 1­ 9822. Nowadays, after decades of development,
both quantum computer hardware and architecture have got some revolutionary ­breakthrough3–6, and quantum
computing has entered a new era called “Noisy Intermediate-Scale Quantum (NISQ)”7. Researches on quantum
algorithms also obtained some remarkable r­ esults8–12. Thanks to increasing demand for efficient image processing
algorithms, quantum image processing (QImP) is one of the hot topics.
For QImP, the first issue to be addressed is how to represent an image in a quantum computer. In recent years,
a variety of quantum image representation (QImR) methods have been developed, such as quantum l­attice13,
entangled ­image14, flexible representation of quantum images (FRQI)15, a novel enhanced quantum representation
of digital images (NEQR)16 and their ­variants17,18. The former two QImR methods were proposed in an early stage
and did not benefit from quantum speed-up19. Compared with FRQI, NEQR and its variants have advantages in
both image preparation and color ­processing16,20, which is vital in today’s computer vision technology.
Based on different QImR methods, various QImP algorithms were proposed to solve problems in different
fields of image processing, e.g. edge d ­ etection19,21, image w­ atermarking22–25, image s­ caling26,27, and etc. As for
assessing the similarity between two quantum images, most researches were based on FRQI and its v­ ariants28–31.
There was a research comparing images based on NEQR and its variant, a novel quantum representation of
color digital images (NCQI), by using quantum amplitude amplifier and estimation in ­201920. Nevertheless, the
main component of quantum amplitude amplifier, an oracle which only flips the amplitude sign of the searched
input, still needs to be given as a black box to the ­algorithm32,33. In addition, the binarization of grey and color
images ­in20 is slightly deficient due to the lack of available quantum circuits. In this paper, we present three novel
algorithms on comparing the similarity between two quantum images based on NEQR and its variants. Our
algorithms consist entirely of general quantum gate set, benefit from additional quantum accelerations, and are
readily applicable on binary, grey, and color quantum images.
In the rest of this paper, we briefly described the representation methods based on NEQR and NCQI in
“NEQR and NCQI” section. The proposed algorithms were presented in “Compare the similarity between two
quantum images” section. In “Algorithm complexity” section, we analyzed the time complexity of our algorithms
and gave a comparison with classical image processing and existing quantum methods. Finally, several experi-
ment results were given in “Calculation results” section to illustrate the validity of the algorithms.

NEQR and NCQI


In this research, the representation of binary and grey images is based on NEQR, and the representation of color
images is based on NCQI.

NEQR. Supposing an image is composed of 2n × 2n pixels and has a grey range of 2q, it can be represented
­as16:

Quantum Computing Research Department, Inspur Academy of Science and Technology, Jinan 250014, China.
*
email: [email protected]

Scientific Reports | (2022) 12:7776 | https://doi.org/10.1038/s41598-022-11863-9 1

Vol.:(0123456789)
www.nature.com/scientificreports/

Figure 1.  Three steps in comparing the similarity between two quantum images. Different colors represent
qubits carrying different functions. The dot on endpoint indicates a multi qubits string. M represents
measurement operation.

2n −1 2n −1
1   q−1 i
|Imagegrey >= n ⊗ |CYX > |YX > (1)
2
Y =0 X=0 i = 0

|CYX > encodes the grey-scale value and |YX > encodes the pixel positions. The length of |CYX > is q for rep-
resenting a grey range of 2q . Binary images can be regarded as a special case taking q = 1. After converting to
binary format, the length of |YX > is 2n.

NCQI. Supposing a RGB color image is composed of 2n × 2n pixels and every RGB component has a range of
2q, then it can be represented ­as17:
2n −1 2n −1
1   q−1 i i i
|Imagecolor >= n ⊗ |RYX GYX BYX > |YX > (2)
2
Y =0 X=0 i = 0

|YX > encodes the pixel positions and |RYX >, |GYX >, |BYX > encodes the red-scale, green-scale, and blue-
scale value respectively. The length of |RYX GYX BYX > is 3q, indicating that the range of red, green and blue is 2q
respectively. After converting to binary format, the length of |YX > is 2n.

Compare the similarity between two quantum images


After preparing two quantum images into qubits 1 (img-qubits1) and qubits 2 (img-qubits2) based on NEQR or
NCQI, similarity assessment between these two images is summarized into three steps, as shown in Fig. 1. In the
following, we present the detailed information for the applications on binary, grey, and color images.

Binary images.

Algorithm 1 Compare the similarity between two binary images.

Step 1: Compare all qubits in img-qubits1 and img-qubits2 one by one and generate auxiliary qubits 1
(AuxBit1);
Step 2: Compress all-1 qubit strings |11 . . . 11 > of AuxBit1 into |1 > of a single qubit (AuxBit2);
Step 3: Measure AuxBit2 and calculate the similarity s with s = p × 22n, where p is the probability of getting
|1 > and 22n is the size of images.

Binary images have only two pixel values, namely 0 and 1, which could be regarded as a special case of NEQR.
Thus, when comparing two pixels, there are only two results, totally the same and completely different.
As pixel values are represented using binary qubits in NEQR, it’s intuitive to think of comparing the pixel
value qubits and the position qubits simultaneously. Only candidates having totally identical qubit strings have
a contribution to the final result. The step 1 is to compare all qubits in img-qubits1 and img-qubits2 one by one
and generate auxiliary qubits 1 (AuxBit1). Focusing on comparison between two qubits (one from imag-qubits1,
and the other from the same site of imag-qubits2), if qubits for comparing are identical, the auxiliary qubit is
set to 1; if different, the auxiliary qubit is set to 0, as shown in the truth table (Table 1). This operation is realized
with two Control-Not (C-Not) gates and one NOT (X) gate, as shown in Fig. 2a.
It can be proved that the probability of getting all-1 qubit string (the following is written as |11 . . . 11 >
for simplification) in measuring Auxbit1 equals 22n s
, where 22n is the total number of pixels in a single image.
Please refer to supplementary information for the detailed process. However, because of the ineluctable errors
included in a real quantum computer, there may exist 22n+1 possible results maximally in measuring AuxBit1,
and |11 . . . 11 > is only one of them. Precise measurement of so numerous qubits is technically difficult and may
introduce non-ignorable readout e­ rror34.

Scientific Reports | (2022) 12:7776 | https://doi.org/10.1038/s41598-022-11863-9 2

Vol:.(1234567890)
www.nature.com/scientificreports/

img-qubits1[i] img-qubits2[i] AuxBit1[i]


0 0 1
0 1 0
1 0 0
1 1 1

Table 1.  Truth table for comparing two qubits. The value of AuxBit1[i] would be set to 1 only if the values of
img-qubits1[i] and img-qubits2[i] are the same.

Figure 2.  (a) The quantum circuit for comparing qubits from img-qubits1 and img-qubits2. This circuit
defines the mapping between two NEQR image strings and AuxBit1. The output is XNOR of two input. (b) The
quantum circuit that compresses |11…11 > to |1 > and the other states to |0 > . This circuit equals the Control-Not
gate conditioning on the whole AuxBit1. The qubits with the same color as in Fig. 1 have the same function.

As the only state we focus on is |11 . . . 11 > in measuring AuxBit1, the other results just offer some redundant
information. Thus, we could design a quantum circuit which compresses |11 . . . 11 > to |1 > and the other states
to |0 >.
The step 2 is to propagate the probability of getting |11 . . . 11 > in measuring AuxBit1 to the probability of
getting |1 > in another single qubit measurement. This operation can be achieved by using the Control-Not gate
that takes multi qubits as its control condition, which reverses the target qubit only if all control qubits are in
|1 >. Construction of such multi-qubits controlled operation using general quantum gate set is introduced ­in35.
Generally, defining a controlled operation C a (U) acting on a + 1 qubits, it can be written as:
C a (U)|x1 x2 x3 . . . xa−1 xa xa+1 >= |x1 x2 x3 . . . xa−1 xa > U x1 x2 x3 ...xa−1 xa |xa+1 > (3)
2b, where auxiliary qubits 3 (AuxBits3) have a length of 2n and auxiliary qubit 2 (AuxBit2) is the target single
qubit we finally wanted.
After obtaining the probability of getting |1 > in measuring Auxbit2, we can get the similarity between two
binary images by multiplying this probability with 22n . The factor of 22n comes from operations on quantum
superposition states. Expanding the comparison to the whole Hilbert space means we compare each of the bases
in img-qubits1 with all the bases in img-qubits2, which results in the numerator being the number of identical
pixels, but the denominator being square of the number of total pixels.

Grey images.

Algorithm 2 Compare the similarity between two grey quantum images with a grey range of
2q.

Step 1: Compare the former b pixel value qubits and all pixel position qubits of img-qubits1 and img-qubits2
one by one, where b is an integer less than q, and generate auxiliary qubits 4 (AuxBit4);
Step 2: Compress all-1 qubit strings |11 . . . 11 > of AuxBit4 into |1 > of a single qubit (AuxBit5);

Scientific Reports | (2022) 12:7776 | https://doi.org/10.1038/s41598-022-11863-9 3

Vol.:(0123456789)
www.nature.com/scientificreports/

Figure 3.  (a) The 16 possible states of pixel value qubits under the condition of q = 4. (b–e) Selecting the former
4,3,2,1 qubits for comparison. The qubit strings in the same red rectangle are considered identical.

Step 3: Measure AuxBit5 and calculate the similarity s with s = p × 22n, where p is the probability of getting
|1 > and 22n is the size of images.

Grey images have a much wider application than binary images in classical image processing. In this part, an
algorithm for comparing the similarity between two grey quantum images is given. The algorithm is similar to
the processing of binary images, except that pixel value qubits compared in step 1 need to be selected.
For illustration, we will take q = 4 at first, and then move on to a more general case. After preparing two
grey images in a quantum computer, the quantum state for representing these two images could be written as:
n n −1
1 
2 −1 2 q−1
⊗ |CYi 1 X1 CYi 2 X2 > |Y1 X1 Y2 X2 > (4)
22n i=0
Y1 Y2 =0 X1 X2 =0

where |CY1 X1 > and |CY2 X2 > has 16 possible states respectively for q = 4, as shown in Fig. 3a.
A vital point for comparing the similarity between grey quantum images is to select proper pixel value qubits
of img-qubits1 and img-qubits2 for comparison. Nevertheless, there may exist some drawbacks if inappropri-
ate qubits are selected. For instance, if we compare all qubits of img-qubits1 and img-qubits2, pixels have no
contribution to the similarity even if they are only slightly different; if we compare the second and the forth
pixel value qubits, states like |0000 > and |1010 > are considered identical even if their grey values vary greatly.
A qubits selection strategy is presented to avoid these drawbacks. The strategy is to select the former b qubits
of |CY1 X1 > and |CY2 X2 > for comparison. As shown in Fig. 3b–e, if the former 4, 3, 2, 1 qubits are compared,
pixels are considered identical if they are in the same red rectangle. For a smaller b, each red rectangle contains
more similar pixels. The qubits used for comparison are underlined for clarity.
As for the common grey quantum images having a grey range of 2q , the selection of the former b pixel
value qubits indicates a preset of the threshold of 2q−b . From 0 to 2q , every 2q−b pixel values are consid-
ered identical. That is to say, the 2q grey range is divided into 2b groups, and all pixel values in the range of
[k2q−b , (k + 1)2q−b − 1], where k = 0, 1, 2 . . . 2b − 1, are considered identical in comparison.
After step 1, the AuxBit4 was generated based on the quantum state in (4). AuxBit4 has an all-1 qubit string
only if the pixel positions are the same and the pixel values are in the same group. Based on the similar analysis
in supplement information, the probability of getting the all-1 qubit string in measuring AuxBit4 is equal to
s
22n
, where s is the similarity between two grey images. After step 2, we propagate this intermediate result to the
probability of getting |1 > in measuring AuxBit5, and the similarity can be calculated by multiplying this prob-
ability with 22n.

Color images.

Algorithm 3 Compare the similarity between two color quantum images with the RGB com‑
ponent range of 2q.

Scientific Reports | (2022) 12:7776 | https://doi.org/10.1038/s41598-022-11863-9 4

Vol:.(1234567890)
www.nature.com/scientificreports/

Step 1: Compare the former bR , bG , bB (bR , bG , bB are integers less than q) RGB component qubits and all pixel
position qubits of img-qubits1 and img-qubits2 one by one, and generate auxiliary qubits 6 (AuxBit6);
Step 2: Compress all-1 qubit strings |11 . . . 11 > of AuxBit6 into |1 > of a single qubit (AuxBit7);
Step 3: Measure AuxBit7 and calculate the similarity s with s = p × 22n, where p is the probability of getting
|1 > and 22n is the size of images.

Color images could convey more information and are much more common in our daily life than binary and
grey images. In this subsection, an algorithm for comparing the similarity between two color images is given. The
algorithm is similar to Algorithm 2, except that instead of selecting the former b pixel value qubits of |CY1 X1 >
and |CY2 X2 >, we proposed to select the former bR , bG , bB qubits of |RY1 X1 >, |GY1 X1 >, |BY1 X1 > and |RY2 X2 >,
|GY2 X2 >, |BY2 X2 > for comparison.
After preparing two color images in a quantum computer, the quantum state for representing these two
images could be written as:
n n −1
1 
2 −1 2 q−1
2n
⊗ |RYi 1 X1 GYi 1 X1 BYi 1 X1 RYi 2 X2 GYi 2 X2 BYi 2 X2 > |Y1 X1 Y2 X2 > (5)
2 i=0
Y1 Y2 =0 X1 X2 =0

|RY1 X1 GY1 X1 BY1 X1 RY2 X2 GY2 X2 BY2 X2 > has a length of 6q and |Y1 X1 Y2 X2 > has a length of 4n.
Based on the similar analysis in “Grey images” section, as for the color image having the RGB compo-
nent range of 2q , the selection of the former bR , bG , bB RGB component qubits for comparison indicates a
preset of the threshold of 2q−bR , 2q−bG , 2q−bB . By setting these thresholds, the red, green, blue ranges are
divided into 2bR , 2bG , 2bB groups, and all RGB component qubits in the range of [kR 2q−bR , (kR + 1)2q−bR − 1],
[kG 2q−bG , (kG + 1)2q−bG − 1 ] , [kB 2q−bB , (kB + 1)2q−bB − 1 ] , where kR = 0, 1, 2 . . . 2bR − 1 ,
kG = 0, 1, 2 . . . 2 G − 1, kB = 0, 1, 2 . . . 2 B − 1, are considered identical in comparison.
b b
After step 1, the AuxBit6 was generated based on the quantum state in (5). AuxBit6 has an all-1 qubit string
only if the pixel positions are the same and the RGB component values are in the same group respectively. Based
on the similar analysis in supplement information, the probability of getting the all-1 qubit string in measur-
ing AuxBit6 is equal to 22n s
, where s is the similarity between two color images. After step 2, we propagate this
intermediate result to the probability of getting |1 > in measuring AuxBit7, and the similarity can be calculated
by multiplying this probability with 22n.

Algorithm complexity
The following discussion of complexity is based on two 2n × 2n binary images, two 2n × 2n grey images with
grey range of 2q, and two 2n × 2n color images with RGB component range of 2q. Intuitively, the classical way to
calculate the number of identical pixels is to compare every pixel at the same position. As the comparison must
be taken one pixel by one pixel, it would take no more than O(22n ) complexity to complete the calculation for
two classical images.
The complexity of a quantum algorithm is usually defined as the number of universal gates used to accom-
plish the ­function20,36. As shown in Fig. 2a, comparing two single qubits in step 1 costs two CNOT gates and
one X gate. Since the comparison is acted on 2 + 4n qubits for Algorithm 1, the number of basic gates costed in
step 1 is no more than 3 × (2+4n)2 = 3 + 6n. As shown in Fig. 2b, step 2 needs 2n Toffoli gates and one CNOT
gate. Since Toffoli gate can be constructed with six CNOT gates and ten single ­gates35, the number of basic gates
costed in step 2 is no more than 1 + 32n . Thus, we need (3 + 6n) + (1 + 32n) = 4 + 38n gates maximally to
complete Algorithm 1. Taking into account the complexity of two binary  images
 p ­ reparation20, the complexity
of comparing the similarity between two binary quantum images is O 2n22n + O(38n).
For Algorithm 2, the comparison is acted on 2b + 4n qubits in step 1. Therefore, the number of basic gates
costed in step 1 is no more than 3b + 6n , and the number of basic gates costed in step 2 is no more than
16 × (b + 2n − 1) + 1 = 16b + 32n − 15 . Thus, we need (3b + 6n) + (16b + 32n − 15) = 19b + 38n − 15
gates maximally to complete Algorithm 2. Taking into account the complexity of two grey images ­ reparation20,
p
the complexity of comparing the similarity between two grey quantum images is O 2qn22n + O(19b + 38n).


For Algorithm 3, the comparison is acted on 2bR + 2bG + 2bB + 4n qubits in step 1. There-
fore, the number of basic gates costed in step 1 is no more than 3bR + 3bG + 3bB + 6n , and the
number of basic gates costed in step 2 is no more than 16bR + 16bG + 16bB + 32n − 15 . Thus, we
n e e d ( 3bR +3bG +3bB +6n)+(16bR + 16bG + 16bB + 32n − 15) = 19bR +19bG +19bB +38n−15
gates maximally to complete Algorithm 3. Taking into account the complexity of two color images
17
­p reparation , the complexity of comparing the similarity between two color quantum images is
O 6q + 4n + 12qn22n + O(19bR + 19bG + 19bB + 38n).
 
The time complexity of previous quantum algorithms that compare the similarity between two quantum
images based on NEQR or NCQI is given in Table 2. In order to reflect the advantage of the proposed algorithms,
the data in Table 2 don’t contain the complexity of image preparation as this process is constant in almost all
QImP algorithms. The complexity of SAB_PV, SAG_SAB_PV, SAC_SAB_PV depends on the expectation of the
precision of results and the data in Table 2 are from an instance given i­ n20. In addition, because b, bR , bG , and bB
are integers less than q, the complexity of Algorithms 2 and 3 in Table 2 reflects the maximum complexity taking
b, bR , bG , bB = q. Even in this worst case (all pixel value qubits are compared), an exponential acceleration is still
achieved than the previous algorithms.

Scientific Reports | (2022) 12:7776 | https://doi.org/10.1038/s41598-022-11863-9 5

Vol.:(0123456789)
www.nature.com/scientificreports/

Algorithms Image style Complexity


Algorithm 1 Binary O(38n)
Algorithm 2 Grey O(19q + 38n)
Algorithm 3 Color O(57q + 34n)
Classical method Binary/grey/color O(22n )
20
SAB_PV
Binary O 64n23n
 
(t = n + 5)
20
SAG_SAB_PV
Grey O 2qn22n + O 48q2 + O 64n23n
     
(t = n + 5)
SAC_SAB_PV20
Color O 12qn22n + O 6q3 + O 64n23n
     
(t = n + 5)
Algorithm ­in37 Binary/grey O(28n22n )

Table 2.  Complexity of different quantum methods for comparing the similarity between two quantum
images based on NEQR and its variant. The complexity of image preparation is not contained in this table.

Figure 4.  Three binary images used for calculating similarity. The image representation states are shown below
the images. The pixel value qubits are underlined. Probability amplitudes are not given for simplification.

Figure 5.  Quantum circuit for comparing similarity between image a and b in Fig. 4.

Calculation results
In the following, some calculation results of binary, grey, and color images are given based on either real quantum
computer or simulations.

Experiment result of binary images. The best method for validating a quantum algorithm is to run it
on a real quantum computer. IBMQ Experience offers several real quantum computers which can be accessed by
public via cloud, and there have been demonstrations of various quantum algorithms based on these quantum
­computers38–40. The similarity between three binary images is calculated using IBM_Manila. IBM_Manila is a
real quantum computer with five qubits and 32 quantum v­ olume41. The average CNOT gate error of IBM_Manila
is 0.8106% and the average single qubit readout error of IBM_Manila is 2.102% (updated aperiodically)42.
Due to the limited qubits of IBM_Manila, we have to make some simplifications in order to apply Algorithm 1.
The simplifications include: the binary images for comparison have only 2 pixels, a pixel value qubit is reused as
part of Auxbit1, and the Auxbit1 is measured directly for calculating the similarity. The binary images used for
experiments are shown in Fig. 4.
A quantum circuit example is given in Fig. 5. Q0 and q1 are used for representing image a. Q2 and q3 are used
for representing image b. After images were prepared, q4 is used for comparing pixel value qubits of image a and

Scientific Reports | (2022) 12:7776 | https://doi.org/10.1038/s41598-022-11863-9 6

Vol:.(1234567890)
www.nature.com/scientificreports/

Figure 6.  Three grey images used for calculating similarities. The image representation states are shown below
the images. The pixel value qubits are underlined. Probability amplitudes are not given for simplification.

Figure 7.  Quantum circuit for preparing image d and e in Fig. 6. Q0 to q5 are qubits representing image d. Q8
to q13 are qubits representing image e. Other qubits are ancillary qubits used for helping preparation. The other
part of the algorithm is omitted for clarity.

b. Due to the lack of more qubits, q0 is reused for comparing pixel position qubits of image a and b. For the same
reason, q0 and q4 are measured directly for calculating the similarity between image a and b.
For IBM_Manila, the number of runs of circuits can be selected from 1 to 8192. In more runs, we can get
results closer to expectations. The circuit in Fig. 5 was run 8192 times on IBM_Manila, and the numbers of get-
ting |11 > in measuring q0 and q4 were counted. In an instance, the numbers of getting |11 > were 1810. Thus,
the similarity between image a and b was calculated as 1810
8192 × 2 = 44.19%. The similarity between image a and c,
image b and c was calculated similarly, and the results were 8.40% and 46.44%. There is a notable margin between
the calculation results and expectations. This is mainly because of the readout error and imperfect quantum gates.
In addition, the limitation of physical links between qubits on a real quantum chip also introduces additional
SWAP gates when compiling quantum c­ ircuits43.

Simulation result of grey images. On account of the limited qubits and fidelities, it is unlikely to run a
complex quantum circuit on the real quantum computer and obtain a satisfied result presently. IBMQ Experi-
ence also offers several simulators that have been frequently used for demonstration of quantum a­ lgorithms44–46.
IBMQ_qasm_simulator is a general-purpose simulator for simulating quantum circuits both ideally and subject
­ odeling42.
to noise m
Similarities between three grey quantum images (Fig. 6) are calculated using IBMQ_qasm_simulator. The
example of preparing image d and e is given in Fig. 7. The other part of the algorithm can be generated with
reference to Fig. 2 and is omitted in Fig. 7 for clarity. For IBMQ_qasm_simulator, the number of runs of circuits
can be selected from 1 to 8192. In order to get results closer to expectations, the quantum circuits were run 8192
times. The similarity results are shown in Table 3. If all pixel value qubits are compared, there is not so significant
difference between the three similarity results. By selecting the first pixel value qubit for comparison, we can get
an obvious maximum similarity when comparing image d and e, which is consistent with expectation as they

Scientific Reports | (2022) 12:7776 | https://doi.org/10.1038/s41598-022-11863-9 7

Vol.:(0123456789)
www.nature.com/scientificreports/

All pixel value qubits are compared


Similarity between image d and e 53.13%
Similarity between image e and f 40.23%
Similarity between image d and f 41.02%
The first pixel value qubit is compared
Similarity between image d and e 86.13%
Similarity between image e and f 54.30%
Similarity between image d and f 54.69%

Table 3.  Similarities between three sample grey images.

Figure 8.  Four color images used for calculating similarities.

bR = 1, bG = 1, bB = 1
g and h g and i g and j h and i h and j i and j
85.27% 14.90% 16.58% 14.73% 16.37% 53.42%
bR = 1, bG = 2, bB = 1
g and h g and i g and j h and i h and j i and j
81.60% 12.65% 13.57% 12.37% 13.42% 49.09%
bR = 1, bG = 1, bB = 2
g and h g and i g and j h and i h and j i and j
78.87% 10.49% 11.40% 10.23% 10.98% 30.87%

Table 4.  Similarities between Four color images.

both look like number “0” but image f looks like number “2”. Other similarity results also have an increment by
transforming the comparison on all pixel value qubits to on the first pixel value qubit.

Simulation result of color images. Color images used for experiments are 8-bits per RGB channel and
composed of 128 × 128 pixels (Fig. 8). Thus, it needs (8 × 3 + 7 × 2) × 2 = 76 qubits for representing two
images. Even if only Auxbit6 is included, the Algorithm 3 needs 114 qubits at least to be simulated. Such quan-
tum system has exceeded the capability of gate-based simulators.
In order to simulate the evolution of quantum states in the algorithm, some simplifications have to be made
from Algorithm 3. Firstly, in step1, instead of multiplying the bases with unitary matrices which have the enor-
mous dimensions, the Auxbit6 was generated directly according to its truth table (Table 1). Secondly, the number
of Auxbit6 being |11 . . . 11 > was counted for statistical analysis of the expected probability of getting |11 . . . 11 >
in measuring Auxbit6. Finally, instead of step3, this probability was used for calculating the similarities. Similar
simplifications are also used ­in20.
The simulation was carried out on a laptop with Core i7-8565U CPU and 16 GB RAM. The pixel values and
positions of sample images were extracted using the open-source software OpenCv. The subsequent calculations
were based on the array computing package NumPy with python. The calculation results for three different
selections of bR , bG , and bB are given in Table 4. In all cases, image g and h have the largest similarity, which is
consistent with prediction as they look the most similar visually. Image i and j also have a similarity more than
50% when bR , bG , bB = 1. This similarity has a rapid decrease when bB is increased to 2. However, it doesn’t fall

Scientific Reports | (2022) 12:7776 | https://doi.org/10.1038/s41598-022-11863-9 8

Vol:.(1234567890)
www.nature.com/scientificreports/

so quickly when bG is increased to 2. We suppose that this is due to the large proportion of blue part in image i
and j resulting in the great impact of blue components on similarity.

Conclusion
In this study, three novel algorithms are proposed to compare the similarity between two quantum images.
The algorithms are suitable for binary, grey, and color images respectively. Compared with existing methods,
especially with the algorithms also based on NEQR and ­NCQI20,37, our work has the following contributions.
Firstly, under the condition that the image preparation is not included, the proposed algorithms can achieve
exponential acceleration than the previous and classical methods.
Secondly, the binarization of grey and color images ­in20 is slightly deficient due to the lack of available quan-
tum circuits. Our study introduces a novel method for comparing the similarity between two binary, grey or color
images, which not only benefits from extra acceleration, but also makes a progress in assessing the similarity of
grey and color images based on NEQR and NCQI.
Finally, although it is a primitive demonstration with binary images that have only two pixels, this is the first
time to compare the similarity between two quantum images on a real quantum computer to the best of our
knowledge.
This study is a preliminary attempt of the practical application of quantum computing in the image processing
field. Experiment and simulation results have indicated the effectiveness of the algorithms. However, circuit depth
and connectivity limit the application of our algorithms on a near-term quantum computer. As shown in Table 4,
an inappropriate selection of pixel value qubits in comparing color images may also cause a significant decrease
of results. A qubits selection strategy with a circuit optimization remains to be developed for future studies.

Received: 20 December 2021; Accepted: 28 April 2022

References
1. Frank, A. et al. Quantum supremacy using a programmable superconducting processor. Nature 574, 505–510 (2019).
2. Feynman, R. P. Simulating physics with computers. Int. J. Theor. Phys. 21(6), 467–488 (1982).
3. Gyongyosi, L. & Imre, S. Scalable distributed gate-model quantum computers. Sci. Rep. 11, 5172 (2021).
4. Gyongyosi, L. & Imre, S. Circuit depth reduction for gate-model quantum computers. Sci. Rep. 10, 11229 (2020).
5. Yulin, W. et al. Strong quantum computational advantage using a superconducting quantum processor. Phys. Rev. Lett. 127, 180501
(2021).
6. Gyongyosi, L. & Imre, S. Dense quantum measurement theory. Sci. Rep. 9, 6755 (2019).
7. Preskill, J. Quantum computing in the NISQ era and beyond. Quantum 2, 79 (2018).
8. Farhi, E. & Harrow, A. W. Quantum supremacy through the quantum approximate optimization algorithm. In APS March Meeting
2017. APS Meeting Abstracts (2016).
9. Farhi, E. & Neven, H. Classification with Quantum Neural Networks on Near Term Processors. arXiv:​1802.​06002 (2018)
10. Harrow, A. W., Hassidim, A. & Lloyd, S. Quantum algorithm for linear systems of equations. Phys. Rev. Lett. 103, 150502 (2009).
11. Kempe, J. Quantum random walks—An introductory overview. Contemp. Phys. 44(4), 307–327 (2003).
12. Kandala, A. et al. Hardware-efficient variational quantum eigensolver for small molecules and quantum magnets. Nature 549(7671),
242–246 (2017).
13. Venegas-Andraca, S. E. & Bose, S. Storing, processing and retrieving an image using quantum mechanics. In Proceeding of the
SPIE Conference Quantum Information and Computation 137–147 (2003)
14. Venegas-Andraca, S. E., Ball, J. L., Burnett, K. & Bose, S. Processing images in entangled quantum systems. Quantum Inf. Process.
9, 1–11 (2010).
15. Le, P. Q., Dong, F. & Hirota, K. A flexible representation of quantum images for polynomial preparation, image compression and
processing operations. Quantum Inf. Process. 10(1), 63–84 (2011).
16. Zhang, Y., Lu, K., Gao, Y. H. & Wang, M. NEQR: A novel enhanced quantum representation of digital images. Quantum Inf. Process.
12(12), 2833–2860 (2013).
17. Sang, J. Z., Wang, S. & Li, Q. A novel quantum representation of color digital images. Quantum Inf. Process. 16, 42–56 (2017).
18. Li, H. S., Zhu, Q. X., Zhou, R. G., Song, L. & Yang, X. J. Multi-dimensional color image storage and retrieval for a normal arbitrary
quantum superposition state. Quantum Inf. Process. 13, 991–1011 (2014).
19. Xi-Wei, Y. et al. Quantum image processing and its application to edge detection: Theory and experiment. Phys. rev. x. 7(3), 031041
(2017).
20. Xing-Ao, L. et al. Similarity assessment of quantum images. Quantum Inf. Process. 18(8), 244 (2019).
21. Yuan, S. et al. Quantum image edge detection algorithm. Int. J. Theor. Phys. 58(3), 2823–2833 (2019).
22. Iliyasu, A. M., Le, P. Q., Dong, F. Y. & Hirota, K. Watermarking and authentication of quantum images based on restricted geometric
transformations. Inf. Sci. 186, 126–149 (2012).
23. Yang, Y. G., Xu, P., Tian, J. & Zhang, H. Analysis and improvement of the dynamic watermarking scheme for quantum images
using quantum wavelet transform. Quantum Inf. Process. 13, 1931–1936 (2014).
24. Song, X. H., Wang, S., El-Latif, A. A. & Niu, X. M. Dynamic watermarking scheme for quantum images based on Hadamard
transform. Multimed. Syst. 20, 379–388 (2014).
25. Naseri, M. et al. A new secure quantum watermarking scheme. Optik 139, 77–86 (2017).
26. Jiang, N., Wang, J. & Mu, Y. Quantum image scaling up based on nearest-neighbor interpolation with integer scaling ratio. Quantum
Inf. Process. 14, 4001–4026 (2015).
27. Zhou, R. G., Hu, W. W., Fan, P. & Hou, I. Quantum realization of the bilinear interpolation method for NEQR. Sci. Rep. 7, 1–17
(2017).
28. Fei, Y. et al. Assessing the similarity of quantum images based on probability measurements. In IEEE Congress on Evolutionary
Computation (CEC) (IEEE, 2012).
29. Fei, Y. et al. A parallel comparison of multiple pairs of images on quantum computers. Int. J. Innovative Comput. Appl. 5(4), 199
(2013).
30. Iliyasu, A. M., Abuhasel, K. A. & Yan, F. A quantum-based image fidelity metric. In Science and Information Conference (SAI)
(IEEE, 2015).
31. Abdullah, I., Fei, Y. & Kaoru, H. Metric for estimating congruity between quantum images. Entropy 18(10), 360 (2016).

Scientific Reports | (2022) 12:7776 | https://doi.org/10.1038/s41598-022-11863-9 9

Vol.:(0123456789)
www.nature.com/scientificreports/

32. Brassard, G., Høyer, P. & Mosca, M. Quantum amplitude amplification and estimation. Quantum Comput. Inf. 5494, 53–74 (2000).
33. Dawid, K. Quantum machine learning for data scientists. arXiv:​1804.​10068 (2018).
34. Heinsoo, J. et al. Rapid high-fidelity multiplexed readout of superconducting qubits. Phys. Rev. Appl. 10(3), 034040 (2018).
35. Nielson, M. A. & Chuang, I. L. Quantum Computation and Quantum Information (Cambridge University Press, 2000).
36. Hu, W. W., Zhou, R. G., Luo, J. & Liu, B. Y. LSBs-based quantum color images watermarking algorithm in edge region. Quantum
Inf. Process. 18, 16–43 (2019).
37. Yang, Y. G., Zhao, Q. Q. & Sun, S. J. Novel quantum gray-scale image matching. Optik 126, 3340–3343 (2015).
38. Gangopadhyay, S., Behera, B. K. & Panigrahi, P. K. Generalization and demonstration of an entanglement-based Deutsch-Jozsa-
like algorithm using a 5-qubit quantum computer. Quantum Inf. Process. 17, 160 (2018).
39. Ghosh, D., Agarwal, P., Pandey, P., Behera, B. K. & Panigrahi, P. K. Automated error correction in IBM quantum computer and
explicit generalization. Quantum Inf. Process. 17, 153 (2018).
40. Alvarez-Rodriguez, U., Sanz, M., Lamata, L. & Solano, E. Quantum artificial life in an IBM quantum computer. Sci. Rep. 8, 14793
(2018).
41. Andrew, W. C., Lev, S. B., Sarah, S., Paul, D. N. & Jay, M. G. Validating quantum computers using randomized model circuits. Phys.
Rev. A. 100, 032328 (2019).
42. IBMQ Experience. https://​quant​umexp​erien​ce.​ng.​bluem​ix.​net/​qx/​exper​ience.
43. Shafaei A., Saeedi M. & Pedram M. Optimization of quantum circuits for interaction distance in linear nearest neighbor architec-
tures. In Design Automation Conference (DAC), 2013 50th ACM/EDAC/IEEE (ACM, 2013).
44. Shenoy, K. S. et al. Demonstration of a measurement-based adaptation protocol with quantum reinforcement learning on the IBM
Q experience platform. Quantum Inf. Process. 19(5), 1–13 (2020).
45. Srinivasan, K. et al. Efficient quantum algorithm for solving travelling salesman problem: An IBM quantum experience. arXiv:​
1805.​10928​v1 (2018)
46. Mahanti, S., Das, S., Behera, B. K. & Panigrahi, P. K. Quantum robots can fly; play games: An IBM quantum experience. Quantum
Inf. Process. 18, 219 (2019).

Acknowledgements
We would like to acknowledge IBMQ Experience for offering experiment platform.

Author contributions
Y.L. is responsible for designing the algorithms, programming software, writing the original draft and preparing
all figures and tables. Z.Q. and Y.L. are responsible for validating the effectiveness of the algorithms. All authors
reviewed the manuscript.

Competing interests
The authors declare no competing interests.

Additional information
Supplementary Information The online version contains supplementary material available at https://​doi.​org/​
10.​1038/​s41598-​022-​11863-9.
Correspondence and requests for materials should be addressed to Y.L.
Reprints and permissions information is available at www.nature.com/reprints.
Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and
institutional affiliations.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International
License, which permits use, sharing, adaptation, distribution and reproduction in any medium or
format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the
Creative Commons licence, and indicate if changes were made. The images or other third party material in this
article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line to the
material. If material is not included in the article’s Creative Commons licence and your intended use is not
permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from
the copyright holder. To view a copy of this licence, visit http://​creat​iveco​mmons.​org/​licen​ses/​by/4.​0/.

© The Author(s) 2022

Scientific Reports | (2022) 12:7776 | https://doi.org/10.1038/s41598-022-11863-9 10

Vol:.(1234567890)

You might also like