1 Introduction

Quantum computers theoretically have the ability to perform computations much faster than classical computers [14], which causes people’s interest to study quantum image processing (QIP) [3, 5, 6].

At present, QIP has three main directions: (1) the representation of quantum images; (2) the development of efficient quantum image transformations; (3) the quantum watermarking algorithms.

The first task of QIP is to represent quantum images. Recently, a few representing methods have been proposed such as Qubit Lattice [7, 8], Real Ket [9], FRQI [10] and NEQR [11]. The Hilbert quantum circuits proposed in this paper are based on FRQI.

It also has been proven that there are quantum processing transformations more efficient than their classical versions: quantum Fourier transform [3], quantum wavelet transform [12] and the quantum discrete cosine transform [13, 14]. In addition, there are some classical image processing operations that can not be applied on quantum images, for example convolution and correlation [15], because all operations in quantum computation must be invertible.

Watermarking is different from cryptography. It aims at guard against image abuse by embedding invisible signal (watermark) carrying information about the copyright owner into multimedia data (carrier, such as audio, video and image). The watermarked carriers are still readable. Several quantum images watermarking methods have been proposed [1618].

In this paper we address the second problem. The basic transformation we focused on is image scrambling. We provide quantum circuits for computing the Hilbert image scrambling.

Image scrambling, which transforms a meaningful image into a meaningless or disordered image, has been widely used in the area of digital image transmission, the confidentiality storage, digital image watermarking etc... [1923]. The popular image scrambling algorithms include Hilbert transform, Arnold transform, Fibonacci transform, Magic Square transform etc... [19, 20, 2427]. Among them is the Hilbert scrambling algorithm, which uses the Hilbert scanning matrix [28] formed by Hilbert Curve. This is the most commonly used transformer and so we used quantum circuits to achieve the Hilbert image scrambling.

Because it is at the very start of the research, only a few papers focus the realization of image scrambling on quantum computers.

The first quantum image scrambling circuit is proposed in [29]. The circuits that achieve geometric transformations including two-point swapping, flip, coordinate swapping, orthogonal rotations and their variants on N -sized quantum images are proposed based on the basic quantum gates: NOT, CNOT and Toffoli gates. Nevertheless, it is only a “semi-scrambling” method because it focuses on geometric transformations, which just provide a realization method for scrambling.

In [16, 17], Zhang and et al. presented an image scrambling method and its quantum circuit as one step in quantum image watermarking algorithms. The key to the scrambling method is made up of two parts: two random permutations M and N, sized m and n, where m and n are the sizes of the watermark image. Assume that M(i), N(j) are the ith and jth numbers of M, N respectively, the pixel (M(i), N(j)) of the original watermark image replaces the pixel at position (i, j) of the scrambled watermark image. The quantum circuit can easily recognize this method. However, because M and N are given artificially, the scrambling uniformity and the scrambling degree cannot be guaranteed.

Jiang and et al. proposed the Arnold and Fibonacci scrambling quantum circuits based on FRQI [30]. The circuits take advantage of the plain adder and adder modulo N by modifying its input and output in order to scramble the images. The Hilbert scrambling quantum circuit is much more complex and cannot be simplified for use in the addition operation as well as other simple operations.

In this paper we study the quantum realization of Hilbert image scrambling using Hilbert Scanning Matrix.

The rest of the paper is organized as follows. A brief background on the FRQI representation, Hilbert image-scrambling and quantum gates used in this paper is presented in Section 2. A new recursive generation algorithm for Hilbert Scanning Matrix is presented in Section 3. A quantum circuit to realize the algorithm is presented in Section 4. This is followed in Section 5 by the theoretical analysis of circuits complexity. Finally, a short conclusion is given in Section 6.

2 Preliminaries

2.1 The Flexible Representation for Quantum Images (FRQI)

In order to represent images on quantum computers, the flexible representation for quantum images (FRQI) was proposed in [10, 29]. According to the FRQI, a quantum image can be written as the form shown below.

$$|I(\theta)\rangle=\frac{1}{2^{n}}\sum\limits_{i=0}^{2^{2n}-1}|c_{i}\rangle\otimes|i\rangle$$
$$|c_{i}\rangle=\cos\theta_{i}|0\rangle+\sin\theta_{i}|1\rangle, \theta_{i}\in\left[0, \frac{2}{\pi}\right], i=0, 1, \cdots, 2^{2n}-1$$

where |0〉, |1〉 are 2 dimension computational basis quantum states, \((\hat \theta _{0},\theta _{1},\cdots , \theta _{2^{2n}-1})\) is the vector of angles encoding colors, |i〉, for i = 0, 1, ⋯ , 22n − 1 dimension computational basis quantum states, and the Kronecker product denoted by ⊗ . There are two parts in the FRQI of an image: |c i 〉 and |i〉, which encode information about the colors and their corresponding positions in the image, respectively. The size of the quantum image is 2n × 2n.

The location information encoded in the position qubit |i〉 includes two parts: the vertical and horizontal coordinates.

$$|i\rangle = |y\rangle |x\rangle = |y_{n-1}y_{n-2}\cdots y_{0}\rangle|x_{n-1}x_{n-2}\cdots x_{0}\rangle$$

where |y i 〉|x i 〉∈0, 1, i = 0, 1, ⋯ , n − 1. For every i = 0, 1, ⋯ , n − 1, encodes the first n-qubit y n − 1 y n − 2y 0 along the vertical location and the second n-qubit x n − 1 x n − 2x 0 along the horizontal axis. An example of a 2 × 2 FRQI image is shown in Fig. 1. Its FRQI representation is shown below. In this example, n = 1.

$$|I\rangle=\frac{1}{2}[(\cos\theta_{0}|0\rangle+\sin\theta_{0}|1\rangle)\otimes|00\rangle+(\cos\theta_{1}|0\rangle+\sin\theta_{1}|1\rangle)\otimes|01\rangle$$
$$+(\cos\theta_{2}|0\rangle+\sin\theta_{2}|1\rangle)\otimes|10\rangle+(\cos\theta_{3}|0\rangle+\sin\theta_{3}|1\rangle)\otimes|11\rangle]$$
Fig. 1
figure 1

A simple image and its FRQI state

2.2 Hilbert Image Scrambling

In 1890, Italian mathematician G. Peano presented a family of curves which pass through all points in a space [31]. Since this publication, many researchers have worked on this problem. Among them, Hilbert [32] found one of the simplest curves in two-dimensional (2-D) space, which is now called the Hilbert curve [33]. Along the Hilbert curve, an image can be scrambled very effectively.

2.2.1 Hilbert Scanning Matrix and Hilbert Curve

An 2n × 2n original image can be considered as a matrix. We call this matrix the Start matrix (or the Original matrix) S n and use 1 to 22n to code all the pixels.

$$S_{n} = \left( \begin{array}{ccccc} 1 & 2 & 3 & \cdots & 2^{n} \\ 2^{n}+1 & 2^{n}+2 & 2^{n}+3 & \cdots & 2^{n+1} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ 2^{2n-1}+1 & 2^{2n-1}+2 & 2^{2n-1}+3 & \cdots & 2^{2n} \end{array} \right)$$

For example, S 0 = (1), \(S_{1} = \left ( \begin {array}{cc} 1 & 2 \\ 3 & 4 \end {array} \right ) \), \(S_{2} = \left ( \begin {array}{cccc} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \\ 13 & 14 & 15 & 16 \end {array} \right ) \).

The Hilbert scanning matrix H n is a permutation of S n . For example, \(H_{0}= \left ( \begin {array}{c} 1 \end {array} \right ) \), \(H_{1}= \left ( \begin {array}{cc} 1 & 2 \\ 4 & 3 \end {array} \right ) \), \(H_{2}= \left ( \begin {array}{cccc} 1 & 2 & 15 & 16 \\ 4 & 3 & 14 & 13 \\ 5 & 8 & 9 & 12 \\ 6 & 7 & 10 & 11 \end {array} \right ) \), and so on. The position (i, j) of the Hilbert scanning matrix H n accommodates the pixel H n (i, j) of the Start matrix S n .

Along H n , the Hilbert curve (see Fig. 2) and scramble images can be obtained (see Fig. 3).

Fig. 2
figure 2

Hilbert curve

Fig. 3
figure 3

The results of Hilbert image scrambling. The image size is 128 × 128, i.e., n = 7

2.2.2 Generation of Hilbert Scanning Matrix

According to 2.2.1, the Hilbert scanning matrix is important to the Hilbert image scrambling. Reference [28] gives a recursive generation algorithm for generating the Hilbert scanning matrix. The algorithm uses several matrix operations. We first introduce them.

If A is a matrix, A T is the transpose of A, A ud is the up-down reversal of A, A lr is the left-right reversal of A, A pp is the central rotation of A. That is to say, if

$$A =\left( \begin{array}{cccc} a_{1, 1} & a_{1, 2} & \cdots & a_{1, m} \\ a_{2, 1} & a_{2, 2} & \cdots & a_{2, m} \\ \vdots & \vdots & \vdots & \vdots \\ a_{m, 1} & a_{m, 2} & \cdots & a_{m, m} \end{array} \right),$$

then,

$$A^{\mathrm{T}} =\left( \begin{array}{cccc} a_{1, 1} & a_{2, 1} & \cdots & a_{m, 1} \\ a_{1, 2} & a_{2, 2} & \cdots & a_{m, 2} \\ \vdots & \vdots & \vdots & \vdots \\ a_{1, m} & a_{2, m} & \cdots & a_{m, m} \end{array} \right), A^{\text{lr}} =\left( \begin{array}{cccc} a_{1, m} & \cdots & a_{1, 2} & a_{1, 1} \\ a_{2, m} & \cdots & a_{2, 2} & a_{2, 1} \\ \vdots & \vdots & \vdots & \vdots \\ a_{m, m} & \cdots & a_{m, 2} & a_{m, 1} \end{array} \right),$$
$$A^{\text{ud}} =\left( \begin{array}{cccc} a_{m, 1} & a_{m, 2} & \cdots & a_{m, m} \\ \vdots & \vdots & \vdots & \vdots \\ a_{2, 1} & a_{2, 2} & \cdots & a_{2, m} \\ a_{1, 1} & a_{1, 2} & \cdots & a_{1, m} \end{array} \right), A^{\text{pp}} =\left( \begin{array}{cccc} a_{m, m} & \cdots & a_{m, 2} & a_{m, 1} \\ \vdots & \vdots & \vdots & \vdots \\ a_{2, m} & \cdots & a_{2, 2} & a_{2, 1} \\ a_{1, m} & \cdots & a_{1, 2} & a_{1, 1} \end{array} \right).$$

The recursive generation algorithm is cited with corrections from [28].

$$ H_{n+1}=\left\{ \begin{array}{ll} \left( \begin{array}{cc} H_{n} & \ \ 4^{n}E_{n}+H_{n}^{\mathrm{T}} \\ (4^{n+1} + 1)E_{n}-H_{n}^{\text{ud}} & \ \ (3 \times 4^{n} + 1)E_{n}-(H_{n}^{\text{lr}})^{\mathrm{T}} \end{array} \right), \ n\ is\ even. \\ \left( \begin{array}{cc} H_{n} & \ \ (4^{n+1} + 1)E_{n}-H_{n}^{\text{lr}} \\ 4^{n}E_{n}+H_{n}^{\mathrm{T}} & \ \ (3 \times 4^{n} + 1)E_{n}-(H_{n}^{\mathrm{T}})^{\text{lr}} \end{array} \right), \ n\ is\ odd. \end{array} \right.$$
(1)

where, n is a positive integer, the initial matrix is \(H_{1}= \left ( \begin {array}{cc} 1 & 2 \\ 4 & 3 \end {array} \right )\) and \(E_{n}= \left ( \begin {array}{cccc} 1 & 1 & \cdots & 1 \\ 1 & 1 & \cdots & 1 \\ \vdots & \vdots & \vdots & \vdots \\ 1 & 1 & \cdots & 1 \end {array} \right )\).

2.3 Quantum Gates used

In this paper, we need a number of basic quantum gates [3, 4] which are all unitary.

  • NOT gate. This is a single qubit gate, which inverts the content of the qubit that it operates upon.

  • Controlled-NOT or C-NOT gate. It is a two-qubit gate and the content of the target qubit is inverted if and only if the control qubit is 1.

  • Swap gate. It is a two-qubit gate swapping two qubits.

  • Toffoli gate. This is a controlled-CNOT gate, thus, making it a three-qubit gate comprising two controls and a single target qubit. The target qubit is inverted only if both control qubits are 1.

  • CSWAP gate (Fredkin gate). CSWAP gate is a 3-bit gate that performs a controlled swap, comprising a control and two target qubits. The two target qubits are swapped only if control qubit is 1.

  • 01-NOT gate. This is a 01-controlled-CNOT gate, thus, making it a three-qubit gate comprising two controls and a single target qubit. The target qubit is inverted only if a control qubit is 1 and the other control qubit is 0.

The notation for these quantum gates are shown in Fig. 4.

Fig. 4
figure 4

Notations for quantum gates

3 The Modified Recursive Generation Algorithm for Hilbert Scanning Matrix

Equation (1), which gives the generation algorithm of Hilbert scanning Matrix, needs to be modified because we find out that it is difficult to give the quantum circuits according to it directly.

3.1 Properties of Matrix Transformations

The modifications are based on the theorem and the lemmas proposed in this section.

Theorem 1

Assume that A, B, C, D are four m × m matrixes, then

  1. 1.

    (A+B)pp = App+Bpp;

  2. 2.

    (A+B)lr = Alr+Blr;

  3. 3.

    (A+B)ud = Aud+Bud;

  4. 4.

    \(\left (\begin {array}{cc}A & B \\ C & D \end {array}\right )^{\text {lr}}=\left (\begin {array}{cc} B^{\text {lr}} & A^{\text {lr}} \\ D^{\text {lr}} & C^{\text {lr}} \end {array}\right )\);

  5. 5.

    \(\left ( \begin {array}{cc} A & B \\ C & D \end {array} \right )^{\text {ud}}=\left ( \begin {array}{cc} C^{\text {ud}} & D^{\text {ud}} \\ A^{\text {ud}} & B^{\text {ud}} \end {array} \right )\);

  6. 6.

    \(\left ( \begin {array}{cc} A & B \\ C & D \end {array} \right )^{\text {pp}}=\left ( \begin {array}{cc} D^{\text {pp}} & C^{\text {pp}} \\ B^{\text {pp}} & A^{\text {pp}} \end {array} \right )\);

  7. 7.

    \(\left ( \begin {array}{c} A^{\mathrm {T}} \end {array} \right )^{\text {ud}}=\left ( \begin {array}{c} A^{\text {lr}} \end {array} \right )^{\mathrm {T}}\);

  8. 8.

    Aud = [(AT)lr]T;

  9. 9.

    (Aud)pp = (App)ud = Alr, (Alr)pp = (App)lr = Aud

where, m is a positive integer.

Proof

Omitted.

Lemma 1

If n is an even number and n > 0,

$$H_{n}+H_{n}^{\text{lr}}=(4^{n} + 1)E_{n}.$$

Proof

Use mathematical induction.

  1. (1)

    When n = 2, \(H_{2}=\left ( \begin {array}{cccc} 1 & 2 & 15 & 16 \\ 4 & 3 & 14 & 13 \\ 5 & 8 & 9 & 12 \\ 6 & 7 & 10 & 11 \end {array} \right ) \), obviously \(H_{2}+H_{2}^{\text {lr}}=(4^{2} + 1)E_{2}\).

  2. (2)

    Assume that when \(n=k, \ H_{k}+H_{k}^{\text {lr}}=(4^{k} + 1)E_{k}\), where k is an even number. According to (1), we have

    $$H_{k+1}=\left( \begin{array}{cc} H_{k} & 4^{k}E_{k}+H_{k}^{\mathrm{T}} \\ (4^{k+1} + 1)E_{k}-H_{k}^{\text{ud}} & (3 \times 4^{k} + 1)E_{k}-(H_{k}^{\text{lr}})^{\mathrm{T}} \end{array} \right)$$
    $$H_{k+2}=\left( \begin{array}{cc} H_{k+1} & (4^{k+2} + 1)E_{k+1}-H_{k+1}^{\text{lr}} \\ 4^{k+1}E_{k+1}+H_{k+1}^{\mathrm{T}} & (3 \times 4^{k} + 1)E_{k+1}-\left(H_{k+1}^{\mathrm{T}}\right)^{\text{lr}} \end{array} \right)$$

    Then, introducing H k+1 into H k+2 and according to Theorem 1, we have

    $$H_{k+2}\, =\, \left( \begin{array}{cccc} H_{k} & 4^{k}E_{k}+H_{k}^{\mathrm{T}} & (15 \times 4^{k} + 1)E_{k}-\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}} & (16 \times 4^{k} + 1)E_{k}-H_{k}^{\text{lr}} \\ (4^{k+1} + 1)E_{k}-H_{k}^{\text{ud}} & (3 \times 4^{k} + 1)E_{k}-\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}} & 13 \times 4^{k}E_{k}-\left[\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}}\right]^{\text{lr}} & 12 \times 4^{k}E_{k}+\left(H_{k}^{\text{ud}}\right)^{\text{lr}} \\ 4^{k+1}E_{k}-H_{k}^{\mathrm{T}} & (8 \times 4^{k} + 1)E_{k}-\left(H_{k}^{\text{ud}}\right)^{\mathrm{T}} & 8 \times 4^{k}E_{k}+\left[\left(H_{k}^{\text{ud}}\right)^{\mathrm{T}}\right]^{\text{lr}} & (12 \times 4^{k} + 1)E_{k}-\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}} \\ (11 \times 4^{k} + 1)E_{k}-H_{k} & 9 \times 4^{k}E_{k}+H_{k}^{\text{lr}} & (7 \times 4^{k} + 1)E_{k}-H_{k} & 5 \times 4^{k}E_{k}+H_{k}^{\text{lr}} \end{array} \right)$$
    $$H_{k+2}^{\text{lr}}\, =\, \left( \begin{array}{cccc} (16 \times 4^{k} + 1)E_{k}-H_{k} & (15 \times 4^{k} + 1)E_{k}-H_{k}^{\mathrm{T}} & 4^{k}E_{k}+(H_{k}^{\mathrm{T}})^{\text{lr}} & H_{k}^{\mathrm{T}} \\ 12 \times 4^{k}E_{k}+H_{k}^{\text{ud}} & 13 \times 4^{k}E_{k}-(H_{k}^{\text{lr}})^{\mathrm{T}} & (3 \times 4^{k} + 1)E_{k}-[(H_{k}^{\text{lr}})^{\mathrm{T}}]^{\text{lr}} & (4^{k+1} + 1)E_{k}-(H_{k}^{\text{ud}})^{\text{lr}} \\ (12 \times 4^{k} + 1)E_{k}-H_{k}^{\mathrm{T}} & 8 \times 4^{k}E_{k}+(H_{k}^{\text{ud}})^{\mathrm{T}} & (8 \times 4^{k} + 1)E_{k}-[(H_{k}^{\text{ud}})^{\mathrm{T}}]^{\text{lr}} & 4^{k+1}E_{k}-(H_{k}^{\mathrm{T}})^{\text{lr}} \\ 5 \times 4^{k}E_{k}+H_{k} & (7 \times 4^{k} + 1)E_{k}-H_{k}^{\text{lr}} & 9 \times 4^{k}E_{k}+H_{k} & (11 \times 4^{k} + 1)E_{k}-H_{k}^{\text{lr}} \end{array} \right)$$

    Obviously \(H_{k+2}+H_{k+2}^{\text {lr}}=(4^{k+2} + 1)E_{k+2}\).

  3. (3)

    Based on the above two points, Lemma 1 holds.

Lemma 2

If n is an odd number and n > 0,

$$H_{n}+H_{n}^{\text{ud}}=(4^{n} + 1)E_{n}.$$

Proof

Use mathematical induction.

  1. (1)

    When n = 1, \(H_{1}=\left ( \begin {array}{cccc} 1 & 2\\ 4 & 3 \end {array} \right ) \), obviously \(H_{1}+H_{1}^{\text {ud}}=(4^{1} + 1)E_{1}\).

  2. (2)

    Assume that when \(n=k, \ H_{k}+H_{k}^{\text {ud}}=(4^{k} + 1)E_{k}\), where k is an odd number. According to (1),

    $$H_{k+1}=\left( \begin{array}{cc} H_{k} & (4^{k+1} + 1)E_{k}+H_{k}^{\text{lr}} \\ 4^{k}E_{k}-H_{k}^{\mathrm{T}} & (3 \times 4^{k} + 1)E_{k}-\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}} \end{array} \right)$$
    $$H_{k+2}=\left( \begin{array}{cc} H_{k+1} & 4^{k+1}E_{k+1}+H_{k+1}^{\mathrm{T}} \\ (4^{k+2} + 1)E_{k+1}-H_{k+1}^{\text{ud}} & (3 \times 4^{k+1} + 1)E_{k+1}-\left(H_{k+1}^{\text{lr}}\right)^{\mathrm{T}} \end{array} \right)$$

    Then, introducing H k+1 into H k+2 and according to Theorem 1,

    $$H_{k+2}\, =\, \left( \begin{array}{cccc} H_{k} & (4^{k+1} + 1)E_{k}+H_{k}^{\text{lr}} & 4^{k+1}E_{k}+H_{k}^{\mathrm{T}} & 5 \times 4^{k}E_{k}+H_{k} \\ 4^{k}E_{k}+H_{k}^{\mathrm{T}} & (3 \times 4^{k} + 1)E_{k}-\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}} & (8 \times 4^{k} + 1)E_{k}-\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}} & (7 \times 4^{k} + 1)E_{k}-\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}} \\ (15 \times 4^{k} + 1)E_{k}-\left(H_{k}^{\mathrm{T}}\right)^{\text{ud}} & 13 \times 4^{k}E_{k}+\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\text{ud}} & 8 \times 4^{k}E_{k}+H_{k}^{\mathrm{T}} & 9 \times 4^{k}E_{k}+H_{k} \\ (16 \times 4^{k} + 1)E_{k}-H_{k}^{\text{ud}} & 12 \times 4^{k}E_{k}+\left(H_{k}^{\text{lr}}\right)^{\text{ud}} & (12 \times 4^{k} + 1)E_{k}-\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}} & (11 \times 4^{k} + 1)E_{k}-\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}} \end{array} \right)$$
    $$H_{k+2}^{\text{ud}}\, =\, \left(\!\! \begin{array}{cccc} (16 \times 4^{k} + 1)E_{k}-H_{k} & 12 \times 4^{k}E_{k}+H_{k}^{\text{lr}} & (12 \times 4^{k} + 1)E_{k}-\left[\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}}\right]^{\text{ud}} & (11 \times 4^{k} + 1)E_{k}-\left(\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}}\right)^{\text{ud}} \\ (15 \times 4^{k} + 1)E_{k}-H_{k}^{\mathrm{T}} & 13 \times 4^{k}E_{k}+\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}} & 8 \times 4^{k}E_{k}+\left(H_{k}^{\mathrm{T}}\right)^{\text{ud}} & 9 \times 4^{k}E_{k}+H_{k}^{\text{ud}} \\ 4^{k}E_{k}+\left(H_{k}^{\mathrm{T}}\right)^{\text{ud}} & (3 \times 4^{k} + 1)E_{k}-\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\text{ud}} & 8 \times 4^{k}E_{k}+H_{k}^{\mathrm{T}} & (7 \times 4^{k} + 1)E_{k}-\left(\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}}\right)^{\text{ud}} \\ H_{k}^{\text{ud}} & (4^{k+1} + 1)E_{k}+\left(H_{k}^{\text{lr}}\right)^{\text{ud}} & 4^{k+1}E_{k}+\left(H_{k}^{\mathrm{T}}\right)^{\text{ud}} & 5 \times 4^{k}E_{k}+H_{k}^{\text{ud}} \end{array}\!\!\! \right)$$

    Then,

    $$H_{k+2}+H_{k+2}^{\text{ud}}=(4^{k+2} + 1)E_{k+2}+\left( \begin{array}{cccc} \textbf{0} & \textbf{0} & H_{k}^{\mathrm{T}}-\left[\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}}\right]^{\text{ud}} & H_{k}-\left(\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}}\right)^{\text{ud}} \\ \textbf{0} & \textbf{0} & \left(H_{k}^{\mathrm{T}}\right)^{\text{ud}}-\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}} & H_{k}^{\text{ud}}-\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}} \\ \textbf{0} & \textbf{0} & H_{k}^{\mathrm{T}}-\left[\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}}\right]^{\text{ud}} & H_{k}-\left(\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}}\right)^{\text{ud}} \\ \textbf{0} & \textbf{0} & \left(H_{k}^{\mathrm{T}}\right)^{\text{ud}}-\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}} & H_{k}^{\text{ud}}-\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}} \\ \end{array} \right)$$

    According to Theorem 1,

    $$\left(H_{k}^{\mathrm{T}}\right)^{\text{ud}}=\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}} \Leftrightarrow \left(H_{k}^{\mathrm{T}}\right)^{\text{ud}}-\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}} = \textbf{0} \Leftrightarrow H_{k}^{\mathrm{T}}-\left[\left(H_{k}^{\text{lr}}\right)^{\mathrm{T}}\right]^{\text{ud}} = \textbf{0}$$

    and

    $$H_{k}^{\text{ud}}=\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}} \Leftrightarrow H_{k}^{\text{ud}}-\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}}=\textbf{0} \Leftrightarrow H_{k}-\left\{\left[\left(H_{k}^{\mathrm{T}}\right)^{\text{lr}}\right]^{\mathrm{T}}\right\}^{\text{ud}}=\textbf{0}$$

    Hence, \(H_{k+2}+H_{k+2}^{\text {ud}}=(4^{k+2} + 1)E_{k+2}\).

  3. (3)

    Based on the above two points, Lemma 2 holds.

3.2 The Modified Recursive Algorithm for Generating Hilbert Scanning Matrix

In order to realize the Hilbert image scrambling in quantum computer, the recursive generation algorithm was modified for the Hilbert scanning matrix, i.e., (1).

Theorem 2

$$ H_{n+1}=\left\{ \begin{array}{cc} \left( \begin{array}{cc} H_{n} & \ \ \left(H_{n}+4^{n}E_{n}\right)^{\mathrm{T}} \\ \left(H_{n}+3 \times 4^{n}E_{n}\right)^{\text{pp}} & \ \ \left(H_{n}+2 \times 4^{n}E_{n}\right)^{\mathrm{T}} \end{array} \right), \ n\ is\ even. \\ \left( \begin{array}{cc} H_{n} & \ \ \left(H_{n}+3 \times 4^{n}E_{n}\right)^{\text{pp}} \\ \left(H_{n}+4^{n}E_{n}\right)^{\mathrm{T}} & \ \ \left(H_{n}+2 \times 4^{n}E_{n}\right)^{\mathrm{T}} \end{array} \right), \ n\ is\ odd. \end{array} \right.$$
(2)

where, n is a positive integer, the initial matrix is \(H_{1}= \left ( \begin {array}{cc} 1 & 2 \\ 4 & 3 \end {array} \right )\) and \(E_{n}= \left ( \begin {array}{cccc} 1 & 1 & \cdots & 1 \\ 1 & 1 & \cdots & 1 \\ \vdots & \vdots & \vdots & \vdots \\ 1 & 1 & \cdots & 1 \end {array} \right )\).

Proof

What needs to do is to prove that (1) and (2) are equivalent. Note that, (1) or (2) and no matter n is even or odd, H n+1 is divided into 4 parts; the 4 parts in (2) are equal to the 4 parts in (1) needs to be proven.

  1. (1)

    When n is an even number, the following 4 issues needs to be proven:

    1. (i)

      H n = H n

    2. (ii)

      \(4^{n}E_{n}+H_{n}^{\mathrm {T}}=\left (H_{n}+4^{n}E_{n}\right )^{\mathrm {T}}\)

    3. (iii)

      \((4^{n+1} + 1)E_{n}-H_{n}^{\text {ud}}=\left (H_{n}+3 \times 4^{n}E_{n}\right )^{\text {pp}}\)

    4. (iv)

      \((3 \times 4^{n} + 1)E_{n}-\left (H_{n}^{\text {lr}}\right )^{\mathrm {T}}=\left (H_{n}+2 \times 4^{n}E_{n}\right )^{\mathrm {T}}\)

For (i) and (ii)

They are obviously correct.

For (iii)

According to Lemma 1 and Theorem 1,

$$ \begin{array}{ll} &\ \ \ \ \ H_{n}+H_{n}^{\text{lr}}=(4^{n} + 1)E_{n}\\ &\Rightarrow \left(H_{n}+H_{n}^{\text{lr}}\right)^{\text{pp}} = H_{n}^{\text{pp}}+H_{n}^{\text{ud}} = \left[(4^{n} + 1)E_{n}\right]^{\text{pp}} = (4^{n} + 1)E_{n}\\ &\Rightarrow (4^{n} + 1)E_{n}-H_{n}^{\text{ud}}=H_{n}^{\text{pp}}\\ &\Rightarrow (4^{n} + 1)E_{n}-H_{n}^{\text{ud}}+3 \times 4^{n}E_{n} = H_{n}^{\text{pp}}+3 \times 4^{n}E_{n}\\ &\Rightarrow (4^{n+1} + 1)E_{n}-H_{n}^{\text{ud}} = \left(H_{n}+3 \times 4^{n}E_{n}\right)^{\text{pp}}\\ \end{array}$$

For (iv)

According to Lemma 1 and Theorem 1,

$$ \begin{array}{ll} &\ \ \ \ \ H_{n}+H_{n}^{\text{lr}}=(4^{n} + 1)E_{n}\\ &\Rightarrow \left(H_{n}+H_{n}^{\text{lr}}\right)^{\mathrm{T}} = H_{n}^{\mathrm{T}}+\left(H_{n}^{\text{lr}}\right)^{\mathrm{T}} = \left[(4^{n} + 1)E_{n}\right]^{\mathrm{T}} = (4^{n} + 1)E_{n}\\ &\Rightarrow (4^{n} + 1)E_{n}-\left(H_{n}^{\text{lr}}\right)^{\mathrm{T}}=H_{n}^{\mathrm{T}}\\ &\Rightarrow (4^{n} + 1)E_{n}-\left(H_{n}^{\text{lr}}\right)^{\mathrm{T}}+2 \times 4^{n}E_{n} = H_{n}^{\mathrm{T}}+2 \times 4^{n}E_{n}\\ &\Rightarrow (3 \times 4^{n} + 1)E_{n}-\left(H_{n}^{\text{lr}}\right)^{\mathrm{T}} = \left(H_{n}+2 \times 4^{n}E_{n}\right)^{\mathrm{T}}\\ \end{array}$$

Hence, when n is an even number,

$$H_{n+1}=\left( \begin{array}{cc} H_{n} & \ \ \left(H_{n}+4^{n}E_{n}\right)^{\mathrm{T}} \\ \left(H_{n}+3 \times 4^{n}E_{n}\right)^{\text{pp}} & \ \ \left(H_{n}+2 \times 4^{n}E_{n}\right)^{\mathrm{T}} \end{array} \right)$$
  1. (2)

    When n is an odd number, the following 4 issues needs to be proven:

    1. (i)

      H n = H n

    2. (ii)

      \((4^{n+1} + 1)E_{n}-H_{n}^{\text {lr}}=\left (H_{n}+3 \times 4^{n}E_{n}\right )^{\text {pp}}\)

    3. (iii)

      \(4^{n}E_{n}+H_{n}^{\mathrm {T}}=\left (H_{n}+4^{n}E_{n}\right )^{\mathrm {T}}\)

    4. (iv)

      \((3 \times 4^{n} + 1)E_{n}-\left (H_{n}^{\mathrm {T}}\right )^{\text {lr}}=\left (H_{n}+2 \times 4^{n}E_{n}\right )^{\mathrm {T}}\)

For (i) and (iii)

They are obviously correct.

For (ii)

According to Lemma 2 and Theorem 1,

$$ \begin{array}{ll} &\ \ \ \ \ H_{n}+H_{n}^{\text{ud}}=(4^{n} + 1)E_{n}\\ &\Rightarrow \left(H_{n}+H_{n}^{\text{ud}}\right)^{\text{pp}} = H_{n}^{\text{pp}}+H_{n}^{\text{lr}} = \left[(4^{n} + 1)E_{n}\right]^{\text{pp}} = (4^{n} + 1)E_{n}\\ &\Rightarrow (4^{n} + 1)E_{n}-H_{n}^{\text{lr}}=H_{n}^{\text{pp}}\\ &\Rightarrow (4^{n} + 1)E_{n}-H_{n}^{\text{lr}}+3 \times 4^{n}E_{n} = H_{n}^{\text{pp}}+3 \times 4^{n}E_{n}\\ &\Rightarrow (4^{n+1} + 1)E_{n}-H_{n}^{\text{lr}} = \left(H_{n}+3 \times 4^{n}E_{n}\right)^{\text{pp}}\\ \end{array}$$

For (iv)

According to Lemma 2 and Theorem 1,

$$ \begin{array}{ll} &\ \ \ \ \ H_{n}+H_{n}^{\text{ud}}=(4^{n} + 1)E_{n}\\ &\Rightarrow \left(H_{n}+H_{n}^{\text{ud}}\right)^{\mathrm{T}} = H_{n}^{\mathrm{T}}+\left(H_{n}^{\mathrm{T}}\right)^{\text{lr}} = \left[(4^{n} + 1)E_{n}\right]^{\mathrm{T}} = (4^{n} + 1)E_{n}\\ &\Rightarrow (4^{n} + 1)E_{n}-\left(H_{n}^{\mathrm{T}}\right)^{\text{lr}}=H_{n}^{\mathrm{T}}\\ &\Rightarrow (4^{n} + 1)E_{n}-\left(H_{n}^{\mathrm{T}}\right)^{\text{lr}}+2 \times 4^{n}E_{n} = H_{n}^{\mathrm{T}}+2 \times 4^{n}E_{n}\\ &\Rightarrow (3 \times 4^{n} + 1)E_{n}-\left(H_{n}^{\mathrm{T}}\right)^{\text{lr}} = \left(H_{n}+2 \times 4^{n}E_{n}\right)^{\mathrm{T}}\\ \end{array}$$

Hence, when n is an odd number,

$$H_{n+1}=\left( \begin{array}{cc} H_{n} & \ \ \left(H_{n}+3 \times 4^{n}E_{n}\right)^{\text{pp}} \\ \left(H_{n}+4^{n}E_{n}\right)^{\mathrm{T}} & \ \ \left(H_{n}+2 \times 4^{n}E_{n}\right)^{\mathrm{T}} \end{array} \right)$$

According to the above two points, Theorem 2 is proved.

In the following, the quantum Hilbert image scrambling is based on Theorem 2 (or 2)).

4 Quantum Circuits for Hilbert Image Scrambling

In this section, a quantum circuit will be given in order to scramble a quantum image. Its input is the 2n × 2n original quantum image and its output is the Hilbert scrambled quantum image. The images are represented using FRQI.

4.1 The Circuit Flow

According to (2), as n increases, the recursive generation algorithm can be divided into three basic operations: initialization, odd and even. Being aware of the fact that even and odd are carried out alternately. The process can be described in Fig. 5.

Fig. 5
figure 5

The recursive generation algorithm flowchart

Accordingly, the quantum circuit can be composed of three basic circuits. We also call them Initialization, Even and Odd.

However, the equation and the circuits have two key differences.

  1. 1.

    The result of (2) is the Hilbert scanning matrix H n . It needs an extra step – put the pixel (⌊(H n (i, j) − 1)/2n⌋, (H n (i, j) − 1)mod2n) of the original image into the position (i, j) in the scrambled image – to scramble images. But in circuits, the output is the scrambled image directly.

  2. 2.

    In (2), the size of the Hilbert scanning matrix H n increases gradually: from 2 × 2 to 4 × 4, to 8 × 8, to 16 × 16 and so on. But in circuits, the sizes of the input image and the output image are all 2n × 2n. We can not and should not change the size of the image in the circuits.

The method to solve the first problem is to operate the image directly instead of the Hilbert scanning matrix. The countermeasure to the second problem is to partition the image into blocks and operate each block according to (2). Note that the partition operation needs to be operated many times:

  • The 1st time it partition the image into 2n − 1 × 2n − 1 blocks sized 2 × 2;

  • The 2nd time it partition the image into 2n − 2 × 2n − 2 blocks sized 4 × 4;

  • The 3rd time it partition the image into 2n − 3 × 2n − 3 blocks sized 8 × 8;

  • ⋯;

  • The nth time it partition the image into 1 block sized 2n × 2n.

They correspond to the gradually increasing size of the Hilbert scanning matrix H n .

Hence, the three basic circuits Initialization, Even and Odd are also compositive. We call the three parts composing the three basic circuits as the three circuit modules.

4.2 The Three Circuit Modules

In this section, k is an integer and 0 ≤ kn − 1.

4.2.1 Module PARTITION(k)

The PARTITION(k) module can divide the 2n × 2n input image into 2nk − 1 × 2nk − 1 blocks sized 2k+1 × 2k+1.

The PARTITION(k) quantum circuit is

  1. (1)

    Swap x k+1 and x k+2, x k+2 and x k+3, ⋯ , x n − 2 and x n − 1.

  2. (2)

    Swap x n − 1 and y k .

As shown in Fig. 6. Because we need not to change the pixels’ color, the inputs of the circuit only include the location information |i〉=|y〉|x〉 as shown in Section 2.1 (the same as following circuits).

Fig. 6
figure 6

PARTITION(k)

For example, assume n = 3, the input of PARTITION(k) is S 3, the function of quantum circuit PARTITION( 0) and PARTITION( 1) is shown in Fig. 7.

Fig. 7
figure 7

Two examples for PARTITION(k)

4.2.2 Module O(k)

Assume A, B, C, D are matrixes sized 2k − 1 × 2k − 1, the function of O(k) is that transform \(\left ( \begin {array}{cc} A & B\\ C & D \end {array} \right )\) into \(\left ( \begin {array}{cc} A & \ \ D^{\text {pp}} \\ B^{\mathrm {T}} & \ \ C^{\mathrm {T}} \end {array} \right )\) which is similar to the form in (2) when n is odd number.

The O(k) (k is odd) quantum circuit is

  1. (1)

    Swap x k and y k . Add a C-NOT Gate, and set x k as as control qubit, y k as target qubit.

  2. (2)

    Add CSWAP Gates whose control qubit is y k to swap x 0 and y 0, x 1 and y 1, ⋯ , and x k − 1 and y k − 1.

  3. (3)

    Add 01-NOT Gates whose 0-control qubit is y k and 1-control qubit is x k to reverse x k − 1, x k − 2, ⋯ , x 0, y k − 1, y k − 2, ⋯ , y 0.

As shown in Fig. 8.

Fig. 8
figure 8

O(k)

The result of every step is shown in Fig. 9.

Fig. 9
figure 9

The function of O(k)

4.2.3 Module E(k)

The function of E(k) is that transform \(\left ( \begin {array}{cc} A & B\\ C & D \end {array} \right )\)into \(\left ( \begin {array}{cc} A & \ \ B^{\mathrm {T}} \\ D^{\text {pp}} & \ \ C^{\mathrm {T}} \end {array} \right )\) which is similar to the form in (2) when n is even number.

The E(k) (k is even) quantum circuit is

  1. (1)

    Add a C-NOT Gate, and set y k as as control qubit, x k as target qubit.

  2. (2)

    Add CSWAP Gates whose control qubit is x k to swap x 0 and y 0, x 1 and y 1, ⋯, and x k − 1 and y k − 1.

  3. (3)

    Add 01-NOT Gates whose 0-control qubit is x k and 1-control qubit is y k to reverse x k − 1, x k − 2, ⋯ , x 0, y k − 1, y k − 2, ⋯ , y 0.

As shown in Fig. 10.

Fig. 10
figure 10

E(k)

The result of every step is shown in Fig. 11.

Fig. 11
figure 11

The function of E(k)

The unitarity of the three circuit modules roots in the unitarity of basic quantum gates showed in Section 2.3.

4.3 The Three Basic Circuits

The three basic circuits Initialization, Odd and Even are composed of the three circuit modules.

4.3.1 Initialization

The Initialization quantum circuit shown in Fig. 12 is used to generate the initial matrix \(H_{1}=\left ( \begin {array}{cc} 1 & 2\\ 4 & 3 \end {array} \right )\) as mentioned in Theorem 2. PARTITION(0) divides the 2n × 2n input image into 2n − 1 × 2n − 1 blocks sized 2 × 2. Then, for each block \(\left (\mathrm {denoted as} \left ( \begin {array}{cc} a & \ \ b \\ c & \ \ d \end {array} \right )\right )\), when y 0 = 1, x 0 is reversed and c and d swaped. The initialized block \(\left ( \begin {array}{cc} a & \ \ b \\ d & \ \ c \end {array} \right )\)is corresponding to the initial matrix \(H_{1}=\left ( \begin {array}{cc} 1 & \ \ 2 \\ 4 & \ \ 3 \end {array} \right )\) in Theorem 2.

Fig. 12
figure 12

The Initialization quantum circuit

4.3.2 Odd(k)

The Odd(k) (k is an odd number and 1 ≤ kn − 1) quantum circuit is shown in Fig. 13. Note that when k = n, the PARTITION module disappears and Odd(k) becomes O(k).

Fig. 13
figure 13

The Odd(k) quantum circuit

The PARTITION(k) module divide the input image into blocks and the O(k) module change every block into the form of \(\left ( \begin {array}{cc} A & \ \ D^{\text {pp}} \\ B^{\mathrm {T}} & \ \ C^{\mathrm {T}} \end {array} \right )\) respectively.

4.3.3 Even(k)

The Even(k) (k is an even number and 2 ≤ kn − 1) quantum circuit is shown in Fig. 14. Note that when k = n, the PARTITION module disappears and Even(k) becomes E(k).

Fig. 14
figure 14

The Even(k) quantum circuit

The PARTITION(k) module divide the input image into blocks and the E(k) module change every block into the form of \(\left ( \begin {array}{cc} A & \ \ B^{\mathrm {T}} \\ D^{\text {pp}} & \ \ C^{\mathrm {T}} \end {array} \right )\) respectively.

4.4 The Integrated Hilbert Image Scrambling Quantum Circuit

According to (2) and Fig. 5, the integrated Hilbert image scrambling quantum circuit is shown in Fig. 15. The meaning of the final basic circuit Even(n − 1)/Odd(n − 1) is that if n − 1 is an even number, the final basic circuit is Even(n − 1); otherwise, it is Odd(n − 1).

Fig. 15
figure 15

The integrated Hilbert image scrambling quantum circuit

4.5 The Inverse Circuit

Because the quantum gates are unitary and no information is lost, the integrated Hilbert image scrambling quantum circuit is unitary. If we reverse the action of it (i.e., if we apply each gate of the circuit in the reversed order) with the scrambled image as input, the output will produce the rebuild image.

4.6 A Simple Example

Assume that n = 3, the Hilbert image-scrambling circuit is shown in Fig. 16.

Fig. 16
figure 16

The quantum circuits for the simple example

The image has 23 × 23 = 64 pixels. If the pixel values of the original image are “1, 2, 3, ⋯ , 63, 64”, the image processing procedure can be shown in Fig. 17. PARTITION(0) blocks the image into 2 × 2 subimages which is \(\left ( \begin {array}{cc} i & i+1 \\ i+2 & i+3 \end {array} \right )\). The C-NOT gate swaps the last two pixel of every subimage. PARTITION(1) blocks the image into 4 × 4 subimages. O(1) and E(2) complete the scrambling.

Fig. 17
figure 17

The image processing procedure for the simple example

If we input the scrambled image from the right of the circuit shown in Fig. 16, the original image will be got from the left.

5 Circuit Complexity

The network complexity depends very much on what is considered to be an elementary gate. In this section, we choose the Control-NOT to be our basic unit, then the Swap gate can be simulated by 3 Control-NOT gates, the Toffoli gate can be simulated by 6 Control-NOT gates, the CSWAP gate can be simulated by 18 Control-NOT gates, and the 01-NOT gate can be simulated by 8 Control-NOT gates [1].

According to Figs. 68, and 10, the numbers of elementary gates in PARTITION(k) is 3 × (nk − 1) = 3n − 3k − 3, O(k) is 3+1+18 × k+8 × 2k = 34k+4, and E(k) is 1+18 × k+8 × 2k = 34k+1 respectively.

Consequently, according to Figs. 1214, the complexity of Initialization is (3n − 3) + 1 = 3n − 2, Odd(k) is (3n − 3k − 3) + (34k+4) = 3n+31k+1, and Even(k) is (3n − 3k − 3) + (34k + 1) = 3n+31k − 2.

Therefore, according to Fig. 15, the whole circuit complexity is \((3n-2) + \sum _{k\textrm { is odd}}(3n+31k + 1) + \sum _{k\textrm { is even}}(3n+31k-2)\approx 18n^{2}+18n-2\). It scales squarely with the size of the circuit’s input n.

6 Conclusion

A Hilbert image scrambling strategy for quantum images is proposed in this paper. The scheme was based on the modified recursive generation algorithm for Hilbert scanning matrix in order to transform images into Hilbert scrambled version by quantum circuits. The circuits can be divided into three basic circuits: Initialization, Odd and Even. The realization of them in quantum computers can promote QIP. The complexity of the networks is square.