Quantum Image Edge Detection PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/329218670

Demonstration of Quantum Image Representation, Transformation and Edge


Detection in IBM Quantum Computer

Preprint · November 2018


DOI: 10.13140/RG.2.2.25057.35685

CITATION READS

1 628

4 authors:

Aniket Malakar Manmohan Hansda


Indian Institute of Science Education and Research Kolkata Indian Institute of Science Education and Research Kolkata
1 PUBLICATION   1 CITATION    1 PUBLICATION   1 CITATION   

SEE PROFILE SEE PROFILE

Bikash K. Behera Prasanta K. Panigrahi


Bikash's Quantum (OPC) Pvt. Ltd. Indian Institute of Science Education and Research Kolkata
141 PUBLICATIONS   768 CITATIONS    588 PUBLICATIONS   4,956 CITATIONS   

SEE PROFILE SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Quantum Experiments View project

Quantum Chess View project

All content following this page was uploaded by Bikash K. Behera on 27 November 2018.

The user has requested enhancement of the downloaded file.


Demonstration of Quantum Image Representation, Transformation and Edge
Detection in IBM Quantum Computer
Aniket Malakar,1, ∗ Manmohan Hansda,1, † Bikash K. Behera,1, ‡ and Prasanta K. Panigrahi1, §
1
Department of Physical Sciences,
Indian Institute of Science Education and Research Kolkata, Mohanpur 741246, West Bengal, India
Digital image processing is continuously gaining attraction with tremendous demands on data
storage, processing and transmission. By encoding the image information in quantum mechanical
systems and using the quantum principles such as superposition and entanglement the above can
be fulfilled with a few quantum resources. Here we demonstrate the framework of quantum image
representation, transformation and edge detection of an image. We propose new methods for en-
coding an image and provide optimized quantum circuits for image representation, transformation
and edge detection processes. We use IBM’s 5-qubit quantum processor to execute the quantum
circuits and carry out the experimental procedures. The use of superconducting quantum computer
here explores new opportunities for processing of large size images.
Keywords: Quantum Image Processing (QImP), Image Edge Detection, IBM Quantum Experience

I. INTRODUCTION The paper is organized as follows. In Sec. II, we


propose two new ways of quantum image representation
Obtaining and analyzing visual information is one of and illustrate its experimental verification. In Sec. III,
the most important functions of our human brain [1]. we apply Haar, Hadamard and Fourier transformation
The analysis of these information by machines enables to an image and present the respective quantum cir-
to directly process and analyze the information stored in cuits designed in IBM quantum experience platform. We
the image [2–4]. Though classical machines have been then elucidate quantum image edge detection in Sec. IV
developed to efficiently perform information processing through execution of quantum circuits in the quantum
tasks, some of them are time and memory consuming. processor.
Hence, the unique quantum-mechanical phenomena such
as quantum entanglement and quantum superposition [5–
7], can be used in faster data processing. Quantum Infor- II. QUANTUM IMAGE REPRESENTATION
mation Processing (QIP) exploits quantum-mechanical
phenomena [8–14] and allows one to surpass the restric- Encoding a 2D image data into a quantum-mechanical
tion over classical computation and achieve maximum system is termed as QImR. Existing QImR models vary
computational speed for certain problems like factoring in respect of performance and efficiency. Here, we take
large numbers [15, 16], quantum simulation [17–23], solv- an image and encode it in two different ways with the
ing hard problems [24], and solving big data problems help of QImR where their pixel values and pixel posi-
[25, 26]. Quantum image representation (QImR), plays tions are seeded in probability amplitudes and quantum
a key role in quantum image processing, as it determines states respectively. Let us consider a 2D image which
the performance and processing of the image [27]. A can be described by the matrix, M = (Mij )R×C where
number of schemes have been proposed for QImR [28–31]. Mij represents a pixel value at position (i, j), i = 1,...,R
Image transformation is extensively used in signal pro- and j = 1,...,C. Two vectors v~1 and v~2 with RC elements
cessing and digital media for numerous purposes such as can be formed by considering the following two cases. In
data enhancement, compression, extraction, representa- the first case, the matrix row elements are arranged one
tion and pattern recognition etc. [2]. 2D discrete wavelet by one in a column vector. The second case arranges
transform is used for compression of images [32]. Here we the matrix row elements in forward and backward order
encode an image by proposing two new methods for im- consecutively:
age representation circuit, and then transform the image
by Haar, Fourier and Hadamard transformation [33, 34],
by experimentally applying a 2-D transformation in pro- v~1 = vec(M )
cessing of the image and further use the image for edge = (M11 , M12 , M13 ..., M1C , M21 , ...Mij , ...MRC )T (1)
detection process [27].
v~2 = vec(M )
= (M11 , ..., M1C , M2C , ..., M21 , M31 , ...MRC )T (2)

∗ am17ms131@iiserkol.ac.in These vectors can be mapped into quantum states as


P2n −1 P2n −1
† mh17ms165@iiserkol.ac.in |v1 i= l=0 al |li and |v2 i= m=0 am |mi of n qubits,
‡ bkb13ms061@iiserkol.ac.in where n = log2 (RC). Here, |li and |mi encode the
§ pprasanta@iiserkol.ac.in pixel positions (i, j) in computational basis and the coef-
2

ficients, al and am encode the pixel values of correspond-


ing pixel positions.
P 2 The values of al P
and am are given
1
2 12
as, al =Mij /( Mij ) 2 and am =Mij /( Mij ) for l, m
< RC and al , am = 0 for l, m ≥ RC. It is to be noted
that the coefficients al ’s and am ’s are scaled such that
the quantum states |v1 i and |v2 i are normalized,

1 0 1 0
 
1 0 1 0 1
M1 = √ 
2 2 1 0 1 0
0 1 0 1

For explicitness, Let us consider an image of 4 × 4


chessboard pattern represented by the matrix M1 . The
image is encoded in the quantum states |v1 i and |v2 i of
four qubits given by the following Eqs. (3) & (4).
|v1 i = |0000i + |0010i + |0101i + |0111i
+ |1000i + |1010i + |1101i + |1111i (3) FIG. 1. Encoding of Image Representation for a 4 ×
|v2 i = |0000i + |0010i + |0100i + |0110i 4 Chessboard. (A): Quantum circuit encoding the image in
the quantum state |v1 i. (B): Quantum circuit encoding the
+ |1000i + |1010i + |1100i + |1110i (4) image represented by the quantum state |v2 i.
The quantum state |v1 i is an equal superposition of
eight quantum states; |0000i, |0010i, |0101i, |0111i,
|1000i, |1010i, |1101i and |1111i. The above state is pre-
pared by applying Hadamard and CNOT gates on the
initial state |0000i. The quantum circuit for preparing
the state, |v1 i is given in Fig. 1 (A). The image is rep-
resented in the form of 3D bar graph as depicted in Fig.
2 (A). Similarly, the quantum state |v2 i is prepared by
using Hadamard gate, phase gates (T, S, T† , S† ) and
CNOT gate as illustrated in Fig. 1 (B). The 3D bar
graphs for the above state are shown in Fig. 2 (B). A
comparison of simulated and run result for encoding the
image in the quantum states |v1 i and |v2 i are shown in
Fig. 2.

III. QUANTUM IMAGE TRANSFORM

All image operations on a quantum computer are linear


in nature, e.g., unitary transformation of an image can FIG. 2. 3D Bar Graphs for Encoded Image. (A) Result
be performed by applying an unitary operator Û on the for the image encoded in |v1 i state. (B) Result for the image
quantum image state, |wi i = Û |vi i, where |vi i and |wi i encoded in |v2 i state. The left and right columns represent the
are the input and output states of the image respectively. theoretical and run results of the quantum states respectively.
Fourier, Hadamard and Haar wavelet transforms are the
basic image transforms that are most commonly used in
the image transform process. The process in general can out is not necessary; it takes O(2n ) operations to perform
be expressed as, W=PVQ, where W is the transformed this task. However, for some cases, where the encoded in-
image, P and Q are row and column transformation ma- formation is a binary result, the order can be drastically
trices respectively. Hence the unitary operator N can be reduced [35].
written by the following expression, Û = QT P [2]. If We now discuss some basic 2D transforms in the frame-
we consider an image of N=RC=2r × 2c =2n pixel size, work of QIP, such as the Fourier, Hadamard, and Haar
then the unitary operation Û on n qubits can be decom- wavelet transforms [33, 34]. 1D Hadamard and Haar
posed as direct product of two operations, one acting on wavelet transform take polynomial time order O[poly(m)]
the first c = log2 C qubits and the other one acting on the in the number of qubits m, whereas, classical versions
last r = log2 R qubits. After the transformation process, take time order of O(m2m ) which clearly shows the un-
it is important to readout the states, though explicit read tapped potential of quantum image transforms. It has
3

been observed that when the process of input data en-


coding and output result extraction require no greater
than polynomial order O[poly(n)] steps, transformations
of 2D Fourier, Hadamard, and Haar wavelet, can achieve
exponential speedup over the existing classical ones. For
a 4 × 4 image size, the three image transformation op-
erators for Fourier, Hadamard and Haar operators are
given in the following expressions.

N
2
ÛF ourier = QF T4 ,
N
ÛHadamard = H 4 ,
N
2
ÛHaar = A4 (5)

where QF T4 , H, and A4 are respectively given as,

1 1 1 1
 
1 1 i −1 −i 
QF T4 = 
2 1 −1 1 −1

1 −i −1 i
FIG. 3. Optimized quantum circuit for transformation

1 1 1
 of image. (A) Haar transform (B) Fourier transform (C)
H=√ Hadamard Transform. Here we take q[4], q[2], q[1] and q[0]
2 1 −1 as the 1st, 2nd, 3rd and 4th qubit respectively.

 
1 1 1 1
1√1 1
√ −1 −i 
A4 =  
2 2 − 2 1 −1
1 −i −1 i

For the Haar transform, at first we take the initial state


|0000i, then we apply single-qubit and two-qubit opera- an image. The boundaries can be defined as the line or
tions given in the quantum circuit as shown in Fig. 3 edge which separates two adjacent regions of an image by
(A). After the application of the operations, we have five their intensity. This is important for processing a digital
outcomes |0000i with 0.5 probability, and other four out- image as well as for brain processing visual information
comes |1010i, |1011i, |1110i and |1111i with each 0.125 [37], since brain processes visual information by identify-
probability. The experimental results for the outcomes ing the lines or edges. Here the given algorithm is found
are presented in the form of 3D bar graphs as shown in to provide exponential speed up over classical algorithms
Fig. 4 (B). For Fourier transform, the quantum gates in that have computational complexity of order O(2n ). This
the quantum circuit depicted in Fig. 3 (B) are applied is a better version as compared to the existing algorithm
to the initial state |0000i. After the operations, we have proposed by Zhang et al. [31]. The given algorithm finds
only two states |0000i and |1010i with each probability the edge or boundaries between two regions of an im-
0.5. The 3D bar graphs of the run and simulated re- age in order of O(1) time complexity. The process is
sults are presented in Fig. 4 (C). Finally, for Hadamard carried out by applying √ a Hadamard gate H that √ con-
transform, we design the quantum circuit as depicted in verts |0i to (|0i + |1i)/ 2 and |1i to (|0i − |1i)/ 2. As
Fig. 3 (D), and have the outcomes |0000i and |1010i with mentioned earlier, the positions of any pair of neighbor-
each 0.5 probability. The results of the outcomes due to ing pixel values in an image are represented by the se-
Hadamard transform are illustrated in Fig. 4 (D). It is quence of a1 a2 a3 ...an−1 0 and a1 a2 a3 ...an−1 1 where ai are
to be noted that the first and second rows represent the 0 or 1. The pixel values of corresponding positions are
simulated and run results for the input encoded image given as the coefficients ba1 a2 a3..an−1 0 and ba1 a2 a3..an−1 1
and its transformations. of respective computational basis states. After the appli-
cation of Hadamard operation, the coefficients become
ba1 a2 a3..an−1 0 ± ba1 a2 a3..an−1 1 . Let us take an n-qubit in-
IV. QUANTUM IMAGE EDGE DETECTION
P2n −1
put image state, |vi= l=0 al |li, whose output image
state can be written as, |wi = (I2n−1 ⊗ H)|vi. The pro-
The task of quantum image edge detection is to de- cess is more elaborately explained by the following Haar
termine boundaries between two adjacent regions [36] of transform operation;
4

FIG. 4. Experimental results of quantum image transforms. Simulated and run pixel 3D view of (A) Input chessboard
image (B) Haar transform (C) Fourier transform (D) Hadamard Transform.

1 1 0 0 ··· 0 0
 
 1 −1 0  0 ··· 0 0
0 0 1 1 ··· 0 0
 
 
1  0 0 1 −1 ··· 0 0
I2n−1 ⊗H = √  , (6)
2
 .. .. ..  .. .. .. ..
 . . .

 . . . .
 0 0 0 0 ··· 1 1 
0 0 0 0 · · · 1 −1
FIG. 5. Quantum Circuit for edge detection of chess-
where I2n−1 is the 2n−1 ×2n−1 unit matrix. The transfor- board image. Initially, a chessboard image with the state,
mation of pixel values after the above operation is given |vi is prepared. Then a Hadamard gate is applied on the
as last qubit (q[0]) converting the image to a 4 × 4 pixel image
pattern as shown in the Fig. 6.
b0 b0 + b1
   
 b1   b0 − b1 
 b2  b + b
   
1  2 3 
 b3  7→ √  b2 − b3 . (7)
  
 ···  2  ··· 
3/4, etc, we apply the n-qubit amplitude permutation
   
b n   b n +b n 
2 −2 2 −2 2 −1
b2n −1 b2n −2 − b2n −1 [34] to the input image, |vi, which converts to |v 0 i con-
taining even (odd) elements equal to the odd (even) el-
The even positions in the output state are the differ- ements of the state, |vi (i.e., b02l = b02l+1 , b02l+1 = b02l+2 ).
ences in the coefficients that determine the boundary be- At first, we have the input with |0000i state with prob-
tween the regions. If the difference vanishes, the two pix- ability 1, then we apply the quantum circuit as shown
els belong to the same region, whereas if the difference in Fig. 5. After preparing the state, |v1 i, we apply the
is nonvanishing, then it signifies a boundary region. The Hadamard operation on the last qubit (q[0]), then we will
edge information between the pixels can be extracted by have all the four-qubit computational basis state (|0000i,
measuring on the last qubit. If the measurement out- |0001i . . . |1111i) with equal probability amplitude. The
come is 1, i.e., the difference is nonvanishing, hence there 3D bar graph plot for the output state is shown in Fig.
are horizontal boundaries between the pixels at positions 6. It is clearly observed that there are no nonvanishing
0/1, 2/3, etc. However, to identify the boundaries be- terms in the state, which indicates all the pixels have
tween the other pairs, i.e., the pixels at positions, 1/2, boundaries adjacent to each other.
5

processing. New methods have been proposed to encode


a 4×4 chessboard image and optimized quantum circuits
are provided after realizing them in the IBM’s 5-qubit
quantum computer. The procedures used here are the
novel ones and outperform the existing algorithms. The
proposed algorithm is more quantum cost efficient and
reduces the required number of qubit resources. We dis-
cuss the application of QImP and experimentally observe
the usefulness of a number of fundamental quantum im-
age processing tasks such as 2D Fourier transform, the
FIG. 6. Simulated and run pixel 3D view of EDGE
detection. Here we have all the 4-qubit computational basis
Hadamard, and the Haar wavelet transform. A practical
states with equal probablity amplitudes. The left and right application and interesting thing, we present here and ex-
part represent run and simulated results respectively. perimentally realize a highly efficient quantum algorithm
for detection of quantum image edge, which needs only
one single-qubit Hadamard gate. The task is achieved
here for a 4 × 4 chessboard image with time order of O(1)
V. CONCLUSION
instead of order of O(2n ) that a classical computer takes.
Hence, quantum computers can have the profound appli-
We have demonstrated the capability of quantum cations in the area of digital image processing and our
image processing to overcome some of the challenges experimental study with a superconducting qubit-based
brought by the fastly increasing requirement of image IBM’s quantum computer is a proof of it.

[1] D. Marr, Vision: A Computational Investigation into [18] R. Gerritsma, G. Kirchmair, F. Zahringer, E. Solano, R.
the Human Representation and Processing of Visual In- Blatt and C. F. Roos, Nature 463, 68–71 (2010).
formation (W. H. Freeman and Company, San Francisco, [19] M. Kapil, B. K. Behera, and P. K. Panigrahi,
1982). arXiv:1807.00521.
[2] R. C. Gonzalez and R. E. Woods, Digital Image Process- [20] Y. Mohanta, D. S. Abhishikth, K. Pruthvi, V. Kumar,
ing (Prentice-Hall, London, 2007). B. K. Behera, and P. K. Panigrahi, arXiv:1807.00323.
[3] B. M. Lake, R. Salakhutdinov, and J. B. Tenenbaum, [21] Manabputra, B. K. Behera, and P. K. Panigrahi,
Science 350, 1332 (2015). arXiv:1806.10229.
[4] N. Jean, M. Burke, M. Xie, W. M. Davis, D. B. Lobell, [22] D. Aggarwal, S. Raj, B. K. Behera, and P. K. Panigrahi,
and S. Ermon, Science 353, 790 (2016). arXiv:1806.00781.
[5] R. Horodecki, P. Horodecki, M. Horodecki, and K. [23] N. N. Hegade, B. K. Behera, and P. K. Panigrahi,
Horodecki, Rev. Mod. Phys. 81, 865 (2009). arXiv:1712.07326.
[6] S. Lloyd, M. Mohseni, and P. Rebentrost, Nat. Phys. 10, [24] K. Srinivasan, S. Satyajit, B. K. Behera, P. K. Panigrahi,
631 (2014). arXiv:1805.10928.
[7] N. Wiebe, D. Braun, and S. Lloyd, Phys. Rev. Lett. 109, [25] P. W. Shor, in Proceedings of the 35th Annual Sympo-
050505 (2012). sium on Foundations of Computer Science(IEEE Com-
[8] D. Deutsch, Proc. R. Soc. A 400, 97 (1985). puter Society Press, New York, 1994), pp. 124-134.
[9] D. Aasen, M. Hell, R. V. Mishmash, A. Higginbotham, [26] X. H. Peng, Z. Y. Liao, N. Xu, G. in, X. Zhou, D. Suter,
J. Danon, M. Leijnse, T. S. Jespersen, J. A. Folk, and J. Du, Phys. Rev. Lett. 101, 220405 (2008).
C. M.Marcus, K. Flensberg, and J. Alicea, Phys. Rev [27] X.-W. Yao, H. Wang, Z. Liao, M.-C. Chen, J. Pan, J. Li,
X 6, 031016 (2016). K. Zhang, X. Lin, Z. Wang, Z. Luo, W. Zheng, J. Li, M.
[10] S. K. Liao et al., Nature (London) 549, 43 (2017). Zhao, X. Peng, and D. Suter, Phys. Rev. X 7, 031041
[11] J. G. Ren et al., Nature (London) 549, 70 (2017). (2017).
[12] D. E. Browne and T. Rudolph, Phys. Rev. Lett. 95, [28] F. Yan, A. M. Iliyasu, and S. E. Venegas-Andraca, Quan-
010501 (2005). tum. Inf. Process. 15, 1 (2016).
[13] X. L. Wang, X. D. Cai, Z. E. Su, M. C. Chen, D. Wu, L. [29] S. E. Venegas-Andraca and S. Bose, Proc. SPIE Int. Soc.
Li, N. L. Liu, C. Y. Lu, and J. W. Pan, Nature (London) Opt. Eng. 5105, 137 (2003).
518, 516 (2015). [30] P. Le, F. Dong, and K. Hirota, Quantum Inf. Process.
[14] D. Suter and G. A. Alvarez, Rev. Mod. Phys. 88, 041001 10, 63 (2011).
(2016). [31] Y. Zhang, K. Lu, Y. Gao, and M. Wang, Quantum Inf.
[15] L. M. K. Vandersypen, M. Steffen, G. Breyta, C. S. Yan- Process. 12, 2833 (2013).
noni, M. H. Sherwood, and I. L. Chuang, Nature 414, [32] S. P. Nanavati and P. K. Panigrahi, Reson. 10, 52 (2005).
883—887 (2001). [33] P. Hoyer, arXiv:quant-ph/9702028.
[16] A. Dash, D. Sarmah, B. K. Behera, and P. K. Panigrahi, [34] A. Fijany and C. Williams, in Proceedings of the 1st
arXiv:1805.10478. NASA International Conference on Quantum Computing
[17] K. Halder, N. N. Hegade, B. K. Behera, and P. K. Pani- and Quantum Communications (Springer, Berlin, 1998),
grahi, arXiv:1808.00021. pp.10-33.
6

[35] H. Buhrman, R. Cleve, J. Watrous, and R. de Wolf, Phys. [37] D. Hubel, Eye, Brain and Vision (Scientific American
Rev. Lett. 87, 167902 (2001). Press, New York, 1995).
[36] D. Marr and E. Hildreth, Proc. R. Soc. B 207, 187
(1980).

View publication stats

You might also like