1 Introduction

Owing to recent advances in quantum information theory, especially its applications in media processing, quantum image processing (QImP) has been considered noticeably, receiving more and more attention than ever before. QImP can be defined as utilizing quantum computation to store, manipulate and recover digital images, meaning that to have a better performance and greater efficiency, digital image information is turned into a quantum representation with the aim of faster processing [1]. As regards prior investigations pertained to quantum image representations, they can be briefly given as follows.

Venegas-Andraca and Bose suggested the qubit lattice for encoding digital images in 2003, storing color information in qubits by translating the related frequencies to quantum states [2]. Subsequently, in 2005, RealKet representation was introduced by Latorre [3]. After that, a useful method named flexible representation for quantum images (FRQI) was investigated by Phuc Le et al. [4], by which the color information and corresponding position information can be united into a quantum state. Fundamentally, inspired by the mentioned representations, many researches have been done in order to initialize a digital image in a quantum state such as multi-channel representation for quantum images (MCQI) [5], novel enhanced quantum representation of digital images (NEQR) [6], quantum image representation for log-polar images (QUALPI) [7], red–green–blue multi-channel quantum representation [8] and, last but not least, a novel quantum representation for color digital images named NCQI [9]. Having defined different quantum representations, researchers then started studying and proposing quantum algorithms in this area of study, meaning that in recent years, quantum image processing (QImP) has been explored by different research groups tremendously [10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27].

Used for further statistical analysis, in 2013, a novel quantum image representation was proposed by Zhang et al. [28] by which the volumes of corresponding histogram can be stored simultaneously. However, it was not a universal approach for the other quantum illustrations, needing storing both essential image information (i.e., color and position information) and histogram information. Accordingly, in this contribution, as one of the important statistical tools related to image processing, the image histogram plotting the number of pixels in an image (vertical axis) with a particular brightness value (horizontal) is considered to be turned into a quantum state, which can be useful for future quantum image analysis tasks. Quantum image histogram (QIH) manipulates two entangled qubit sequences in order to store volumes of the image histogram.

The rest of the paper is organized as follows. A brief introduction about digital image histogram and its invaluable applications is given in Sect. 2. Afterward, a new model for constructing image histogram in a superposition state is investigated, which is based on gray-tone NEQR and RGB NCQI images. Sect. 4 is dedicated to comparing the proposed method with the only work found in the literature. Subsequently, Sect. 5 shows a useful application of QIH practically. Finally, Sect. 6 is devoted to the conclusion.

2 Digital image histogram and its applications

Image histogram, which can be useful to depict image statistics in an easily interpreted results, to improve the visual appearance of an image, to distinguish a wide range of image drawbacks (such as saturation, spikes and gaps, impact of image compression) and, last but not least, to determine what type of processing has been applied to an image, shows the frequency of the intensity values that occurs in an image [29].

The histogram H of the image I with gray range \(2^{q}\) (\(2^{q}\) colors) can be expressed as follows.

$$\begin{aligned} H(c)=\{N_{c}|{ c }\in \{0,1,2,\ldots 2^{q}-2,2^{q}-1\} \}, \end{aligned}$$
(1)

where

  • c is the intensity value

  • \(N_{c}\) is the number of pixels having color value c in image I

A simple image histogram is given in Fig. 1, showing how it stores the pertinent information.

Fig. 1
figure 1

A simple image histogram

Providing a global description of image appearance, image histogram is able to acquire lots of useful information. Consequently, histogram processing techniques have many uses such as [29]:

  • Image analysis

  • Image enhancement

  • Brightness and contrast purposes

  • Image equalization

  • Histogram matching

  • Analyzing data hiding algorithms in which their cover is an image

  • Determining which type of transformation or enhancement algorithm is applied to the image and

  • Thresholding.

Regarding its practical applications, having a method to prepare the image histogram in a quantum state can be regarded as a new insight into QImP, most notably statistical analysis. Accordingly, the following sections are devoted to initializing quantum states so as to store image histogram information for not only grayscale images, but also RGB-colored ones, which are based on NEQR and NCQI in turn.

3 Quantum image histogram: QIH

3.1 QIH based on grayscale image

Figure 2 shows the image histogram of an image named ‘Lena,’ which is simulated in MATLAB environment by a classical computer. The primary goal of this section is introducing a quantum model for storing the useful information of such an image histogram, constructing it from a grayscale image based on quantum computation.

Fig. 2
figure 2

Image histogram diagram for a digital grayscale image named ‘Lena’

In QImP, to store the essential information of a grayscale image, a novel enhanced quantum representation of digital images named NEQR has been used widely. In 2013, Zhang et al. [6] introduced a new approach to encode a grayscale image in a quantum state. According to NEQR, a quantum \(2^{n}\times 2^{n}\) image can be demonstrated as the following equation:

$$\begin{aligned}&|\mathrm{neqr}\rangle =\frac{1}{2^{n}}\sum ^{2^{2n}-1}_{i=0} |\mathrm{gc}_{i}\rangle \otimes |i\rangle , \nonumber \\&\quad |\mathrm{gc}_{i}\rangle =|\mathrm{gc}^{q-1}_{i}\ldots \mathrm{gc}^{1}_{i}\mathrm{gc}^{0}_{i}\rangle ,\mathrm{gc}_{i}^{k}\in \{0,1\},k{=}q-1,\ldots ,1,0, i{=}0,1,\ldots ,2^{2n}{-}1,\nonumber \\ \end{aligned}$$
(2)

where \(|\mathrm{gc}_{i}\rangle \) and \(|i\rangle \) encode information about the color and their corresponding positions in the image simultaneously, and q is usually 8 owning to the fact that it can define 256 gray colors (0-255). Furthermore, \(|i\rangle \) is comprised of two bases: the vertical basis and the horizontal one.

$$\begin{aligned} |i\rangle =|y\rangle |x\rangle =|y_{n-1},y_{n-2}\ldots y_{0}\rangle |x_{n-1},x_{n-2}\ldots x_{0}\rangle , y_{j}x_{j}\in \{0,1\}, \end{aligned}$$
(3)

which encodes the first n qubits \(|y_{n-1}\rangle ,|y_{n-2}\rangle ,\ldots ,|y_{0}\rangle \) along the vertical location and the second n qubits \(|x_{n-1}\rangle , |x_{n-2}\rangle ,\ldots ,|x_{0}\rangle \) along the horizontal axis.

Having prepared a quantum gray-tone image, now, we are able to model QIH by counting the each color all over the image. In fact, similar colors in the image should be counted in order to form a comprehensive image histogram. QIH can be formulated as follows.

$$\begin{aligned} |\mathrm{QIH}\rangle= & {} \frac{1}{2^{q}}\sum ^{2^{q}-1}_{C=0}|C\rangle \otimes |N_{C}\rangle ,\nonumber \\ |C\rangle= & {} |C^{q-1}C^{q-2}\ldots C^{1}C^{0}\rangle , C^{i}\in {0,1}, i=(0,1,\ldots ,q-1), \nonumber \\ |N_{C}\rangle= & {} |N^{2n}_{C}N^{2n-1}_{C}\ldots N^{1}_{C}N^{0}_{C}\rangle , \end{aligned}$$
(4)

where \(|C\rangle \) is color information showing gray colors between 0 and \(2^{q}-1\) in a quantum superposition state; for example, if q equals 8, \(|C\rangle \) is able to demonstrate \(2^{8}=256\) gray colors between 0 and 255. Moreover, qubit sequence \(|N_{C}\rangle \) is the number of the corresponding gray color \(|C\rangle \) in the whole image, which is able to count \(2^{2n}\) pixels. Take a simple \(4\times 4\) gray image as an example. The QIH representation of this image is illustrated in Fig. 3.

Fig. 3
figure 3

Quantum image histogram (QIH) for a simple \(4\times 4\) gray image

Fig. 4
figure 4

Outline of QIH preparation procedure based on NEQR

3.1.1 QIH preparation procedure

A bare outline of our constructive polynomial preparation is illustrated in Fig. 4, providing a wider perspective on the procedure. As regards the number of required qubits, it can be taken into account as \((q+2n+1)\) for a \(2^{n}\times 2^{n}\) image with gray range \(2^{q}\); q is because of being able to show \(2^{q}\) colors, and \(2n+1\) is just due to being able to show the number of all related pixels.

The initial state \(|\varPhi \rangle _{0}\) is carried out by preparing \(q+2n+1\) qubits as well as setting all of them to \(|0\rangle \), which can be shown as follows.

$$\begin{aligned} |\varPhi \rangle _{0}=|0\rangle ^{\otimes q+2n+1}. \end{aligned}$$
(5)

Having prepared the required qubits, we should start the first step named intermediate state \(|\varPhi \rangle _{1}\), which is superposition of all color information. This state is formed by two single-qubit gates I and H.

$$\begin{aligned} H= & {} \frac{1}{\sqrt{2}} \left( \begin{array}{cc} 1 &{} 1 \\ 1 &{} -1 \\ \end{array} \right) , I=\left( \begin{array}{cc} 1 &{} 0 \\ 0 &{} 1 \\ \end{array} \right) \end{aligned}$$
(6)
$$\begin{aligned} \varGamma _{1}= & {} H^{\otimes q}\otimes I^{\otimes 2n+1}. \end{aligned}$$
(7)

\(\varGamma _{1}\) is used to transform the initial state \(|\varPhi \rangle _{0}\) to the intermediate state \(|\varPhi \rangle _{1}\), storing all possible colors in the QIH model as can be seen as follows.

$$\begin{aligned}&\varGamma _{1}\left( |\varPhi \rangle _{0}\right) = (H|0\rangle )^{q} \otimes (I|0\rangle )^{\otimes 2n+1} \nonumber \\&\quad \frac{1}{2^{q}}\sum ^{2^{q-1}}_{C=0}|C\rangle \otimes |0\rangle ^{\otimes 2n+1} = |\varPhi \rangle _{1}. \end{aligned}$$
(8)

To prepare QIH, setting the number of each color remains. In the intermediate state \(|\varPhi \rangle _{1}\), all color information has been stored into a superposition quantum state. Considering the NEQR image \(|neqr\rangle \), we must count and store the number of these colors as \(N_{C}\) in our proposed model, defining \(2^{2n}\) sub-operation to check all pixels in \(|\mathrm{neqr}\rangle \). Consequently, \(U_{i}\) is defined as follows.

$$\begin{aligned} U_{i}=\left( I\otimes \sum _{j=0,j\ne i}^{2^{2n}-1}|j\rangle \langle j| \right) + \varOmega _{i}\otimes |i\rangle \langle i|, \end{aligned}$$
(9)

where \(\varOmega _{i}\) is a quantum operation which is able to count the corresponding color value in position i in the NEQR image, storing the result in QIH model. So, the function of \(\varOmega _{i}\) can be shown as follows.

  • Apply \(\mathrm{Ctr}_{k}\) to \(|\mathrm{QIH}\rangle \), providing \(|C\rangle \) equals \(|\mathrm{gc}_{i}\rangle \).

\(\mathrm{Ctr}_{k}\) is a quantum operation used to store the result in qubit sequence \(|0\rangle ^{\otimes 2n+1}\) named \(N_{C}\).

$$\begin{aligned} \mathrm{Ctr}_{k}=\left( I\otimes \sum _{j=0,j\ne k}^{2^{q}-1}|j\rangle \langle j| \right) + \varOmega _{k}\otimes |k\rangle \langle k|, \\ \varOmega _{k}:|a\rangle \rightarrow |a\rangle (+)1, \hbox { (+) is a binary addition.}\nonumber \end{aligned}$$
(10)

To transform the intermediate state \(|\varPhi _{1}\rangle \) to the final stage, \(U_{i}\) must be applied to neqr, forming the corresponding QIH.

$$\begin{aligned} U_{i}\left( |\mathrm{neqr}\rangle \right)= & {} U_{i}\left( \frac{1}{2^{n}}\sum ^{2^{2n}-1}_{j=0}|\mathrm{gc}_{j}\rangle \otimes |j\rangle \right) \nonumber \\= & {} \frac{1}{2^{n}}U_{i}\left( \sum ^{2^{2n}-1}_{j=0,j\ne i}|\mathrm{gc}_{j}\rangle \otimes |j\rangle + |\mathrm{gc}_{i}\rangle \otimes |i\rangle \right) \nonumber \\= & {} \frac{1}{2^{n}}\left( \sum ^{2^{2n}-1}_{j=0,j\ne i}|\mathrm{gc}_{j}\rangle \otimes |j\rangle + \varOmega _{i}\left( |\mathrm{gc}_{i}\rangle \otimes |i\rangle \right) \right) . \nonumber \\ \hbox {If }|\mathrm{gc}_{i}\rangle= & {} |C\rangle ,\hbox { then } \mathrm{Ctr}_{k}(|\varPhi \rangle _{1}) . \end{aligned}$$
(11)

In order to make this comparison technically, values of \(|\mathrm{gc}_{i}\rangle \) and \(|C\rangle \) are regarded together, meaning that each pair is considered separately. Thus, another quantum operation named CMP is needed here, which can be defined as follows.

$$\begin{aligned} \hbox {CMP}= & {} \prod _{j=0}^{2^{2n}-1}\xi _{j} \nonumber \\ \xi _{j}= & {} C^{2q}\hbox {{Not}}. \end{aligned}$$
(12)

Note that both \(|\mathrm{gc}_{i}\rangle \) and \(|C\rangle \) comprise of q qubits; consequently, \(2^{q}\) CNot gates are required to be applied for making a decision on whether \(\mathrm{Ctr}_{k}\) should be applied or not. Moreover, each \(\xi _{j}\) follows the below rules:

  • \(\xi _{0}=\left( C_{0}C_{0}\ldots C_{0}C_{0})(C_{0}C_{0}\ldots C_{0}C_{0}\right) \)Not

  • \(\xi _{1}=\left( C_{0}C_{0}\ldots C_{0}C_{1})(C_{0}C_{0}\ldots C_{0}C_{1}\right) \)Not

  • \(\xi _{2}=\left( C_{0}C_{0}\ldots C_{1}C_{0})(C_{0}C_{0}\ldots C_{1}C_{0}\right) \)Not

  • \(\xi _{3}=\left( C_{0}C_{0}\ldots C_{1}C_{1})(C_{0}C_{0}\ldots C_{1}C_{1}\right) \)Not

  • .

  • .

  • .

  • \(\xi _{2^{q}-1}=\left( C_{1}C_{1}\ldots C_{1}C_{1})(C_{1}C_{1}\ldots C_{1}C_{1}\right) \)Not,

where \(C_{0}\) and \(C_{1}\) check the conditions 0 and 1 in turn. (Figure 5 provides an illustration of these explanations by quantum circuits.)

Finally, applying CMP to \(|gc_{i}\rangle |C\rangle \) brings about \(\mathrm{Ctr}_{k}\) is applied to \(|\varPhi \rangle _{1}\) (with the aim of using \(2+1\) ancillary qubits). The following indicate the next step.

$$\begin{aligned} \mathrm{Ctr}_{k}(|\varPhi \rangle _{1})= & {} \mathrm{Ctr}_{k}\left( \frac{1}{2^{q}}\sum ^{2^{q-1}}_{C=0}|C\rangle \otimes |0\rangle ^{\otimes 2n+1}\right) \end{aligned}$$
(13)
$$\begin{aligned} \nonumber= & {} \frac{1}{2^{q}}Ctr_{k}\left( \sum ^{2^{q-1}}_{C=0,C\ne k}|C \rangle \otimes |0\rangle ^{\otimes 2n+1}+|k\rangle \otimes |0\rangle ^{\otimes 2n+1}\right) \\= & {} \frac{1}{2^{q}}\left( \sum ^{2^{q-1}}_{C=0,C\ne k}|C\rangle \otimes |0\rangle ^{\otimes 2n+1}+\varOmega _{k}\left( |k\rangle \otimes |0 \rangle ^{\otimes 2n+1}\right) \right) \nonumber \\= & {} \frac{1}{2^{q}}\left( \sum ^{2^{q-1}}_{C=0,C\ne k}|C\rangle \otimes |0\rangle ^{\otimes 2n+1}+|k\rangle \otimes |N_{k}\rangle \right) . \end{aligned}$$
(14)

Regarding Eq. 13, it is explicit that every sub-operation \(U_{i}\) only sets the number of a specific gray color. Therefore, \(\varGamma _{2}\) is defined to set the number of all gray colors, which is shown in Eq. 14.

$$\begin{aligned} \varGamma _{2}=\prod _{i=0}^{2^{2n}-1}U_{i}. \end{aligned}$$
(15)

With respect to \(|\mathrm{QIH}\rangle \) shown in Eq. 4, it can be gained by applying \(\varGamma _{2}\) to our NEQR image \(|\mathrm{neqr}\rangle \). Finally, the quantum network required for preparing QIH for an NEQR image with size \(2^{n}\times 2^{n}\) and gray range \(q=8\) is given in Fig. 5, in which a quantum plain adder and subtracter introduced by Vedral et al. [30] is used to carry out the binary addition. The ancillary qubits \(|00\ldots 0\rangle \) in each quantum adder and subtracter account for that \(N_{c}\) increases by one or zero depending on the conditions. Before discussing the time complexity of our proposed model, it is worthwhile discussing a bit more about this quantum plain.

The provided quantum plain circuit consists of quantum logic gates whose computational steps are synchronized in time [30], where the binary inputs are encoded in the quantum computational basis which are often called quantum registers. The addition of two quantum registers \(|a\rangle \) and \(|b\rangle \) is written as \(|a,b\rangle \rightarrow |a,a+b\rangle \). Moreover, by reversing the quantum plain adder circuit, the quantum subtracter is realized. If one runs the quantum subtracter with the input (ab), the output will produce \((a,a-b)\) when \(a>b\). When \(a<b\), the output is \((a, 2^{n+1}-(b-a))\), where \(n+1\) is the size of the second register [30]. The operation of the quantum plain adder and subtracter is illustrated in Fig. 6.

Fig. 5
figure 5

Quantum image histogram circuit

Fig. 6
figure 6

Quantum plain adder and subtracter [30]

3.1.2 Time complexity

To begin with, the intermediate state \(|\varPhi \rangle _{1}\) is done by applying the quantum operation \(\varGamma _{1}\) to initial state \(|\varPhi \rangle _{0}\). Accordingly, the time complexity of \(|\varPhi \rangle _{1}\) depends on \(\varGamma _{1}\), which is \(O(q+2n+1)\) from Eq. 7. Despite this, the entire work of \(\varGamma _{2}\) belonged to the final step is significantly more complex than that of \(\varGamma _{1}\) owing to the fact that \(\varGamma _{2}\) consists of \(2^{2n}\) sub-operations named \((U_{i})\) to store the ultimate numbers in the QIH model. Thus, in the following section we will focus on the time complexity of \(U_{i}\).

Theorem 1

The quantum operation \(U_{i}\) costs no more than \(O({nq}2^{q})\) in case of using adequate ancillary qubits, when size of NEQR image is \(2^{n}\times 2^{n}\) with gray range \(2^{q}\) .

Proof

To calculate the time complexity of \(U_{i}\), \(\varOmega _{i}\) illustrated in Fig. 5 must be taken into account. \(\varOmega _{i}\) comprises of \(2^{q}\) 2q-CNot gates to increase \(N_{C}\) by 1. \(k-CNot\) gate can be decomposed into \((4k-8)\) \(2-CNot\) gates (which are called Toffoli gates [31], a simple and common quantum gate) when \(k-2\) extra ancillary qubits are used [32]. In fact, the time complexity of \(k-CNot\) gate is not more than O(k). Consequently, the time complexity of our Toffoli gates is less than \(O(q2^{q})\).

The next consideration is related to the quantum plain adder and subtracter, which consists of \((3h+3)\) CNot gates and \((2h+2)\) Toffoli gates, when its inputs include h qubits according to Fig. 6. Hence, the time complexity of this network is not more than O(h) [30], and due to the fact that our inputs in this network are \((2n+1)\) qubits in each qubit sequence, the time complexity of the quantum plain adder and subtracter in our proposed network is no more than O(n).

Finally, it is obvious that the time complexity of \(U_{i}\) is not more than \(O({nq}2^{q})\) with the help of enough ancillary qubits, when size of NEQR image is \(2^{n}\times 2^{n}\) with gray range \(2^{q}\). \(\square \)

Lemma 1

The time complexity of \(\varGamma _{2}\) is \(O(nq2^{2n+q})\) in case of using enough ancillary qubits, when size of NEQR image is \(2^{n}\times 2^{n}\) with gray range \(2^{q}\).

Proof

According to Theorem 1, each sub-operation \(U_{i}\) costs no more than \(O(nq2^{q})\) with adequate ancillary qubits. As the number of each gray color sets individually in the corresponding \(N_{C}\), the time complexity of entire \(\varGamma _{2}\) is no more than

$$\begin{aligned} O(nq2^{q}\times 2^{2n})=O(nq2^{2n+q}). \end{aligned}$$

\(\square \)

Theorem 2

The preparation of the proposed model named QIH, which is aimed at storing image histogram information in a quantum state, costs no more than \(O(nq2^{2n+q})\) for a \(2^{n}\times 2^{n}\) NEQR image with gray range \(2^{q}\).

Proof

Regarding the calculated time complexity of Lemma 1 related to \(\varGamma _{2}\) as well as the above discussion about \(\varGamma _{1}\), it is explicit that constructing an image histogram based on QIH model costs no more than maximum of the two, which is \(O(nq2^{2n+q})\). \(\square \)

3.2 QIH based on RGB image

The image histogram of a RGB image (Sailboat on lake) is demonstrated in Fig. 7, which is captured in MATLAB environment by a classical computer, showing how histogram information of a digital RGB image is plotted. Proposing a quantum model in order to store image histogram information in a quantum state based on RGB images is the primary purpose in this section.

Fig. 7
figure 7

Image histogram diagram for a digital RGB image named ‘Sailboat on lake’

Having investigated a model for storing essential information of RGB images in a quantum state, Sang et al. [9] introduced a quantum representation named NCQI in 2017. Inspired by novel enhanced quantum representation (NEQR) [6], NCQI stores and processes RGB-colored digital images on quantum computers, in which color information is encoded in three channels (red–green–blue: RGB). Employing two entangled qubit sequences, NCQI initializes the information of position and the corresponding color of each pixel simultaneously in a quantum state. The former is used to encode the red, green and blue values of the color related to each pixel, and the latter is devoted to the information belonged to the position of the pixel. Suppose that the range of each channel is \(2^{q}\). The presentation of a \(2^{n}\times 2^{n}\) RGB image can be depicted as:

$$\begin{aligned} |\mathrm{ncqi}\rangle =\frac{1}{2^{n}}\sum ^{2^{2n}-1}_{i=0}|C_{\mathrm{RGB}_{i}}\rangle \otimes |i\rangle , \end{aligned}$$
(16)

where \(\otimes \) represents the tensor product and the state \(|C_{\mathrm{RGB}_{i}}\rangle \) is used to encode the RGB information of the pixel i, which can be defined as follows:

$$\begin{aligned} |C_{\mathrm{RGB}_{i}}\rangle =|R_{i}\rangle |G_{i}\rangle |B_{i}\rangle . \end{aligned}$$
(17)

Here, \(|R_{i}\rangle \), \(|G_{i}\rangle \) and \(|B_{i}\rangle \) depict the information of the channels.

$$\begin{aligned} |R_{i}\rangle= & {} |r^{q-1}_{i}r^{q-2}_{i}\ldots r^{1}_{i}r^{0}_{i}\rangle , \\ |G_{i}\rangle= & {} |g^{q-1}_{i}g^{q-2}_{i}\ldots g^{1}_{i}g^{0}_{i}\rangle , \\ |B_{i}\rangle= & {} |b^{q-1}_{i}b^{q-2}_{i}\ldots b^{1}_{i}b^{0}_{i}\rangle , \\&\quad r_{i}^{k}, g_{i}^{k}, b_{i}^{k} \in \{0,1\}, \end{aligned}$$

and also, \(|i\rangle \) equals

$$\begin{aligned} |i\rangle =|y\rangle |x\rangle =|y_{n-1},y_{n-2}\ldots y_{0}\rangle |x_{n-1},x_{n-2}\ldots x_{0}\rangle , y_{j}x_{j}\in \{0,1\}, \end{aligned}$$
(18)

where \(|i\rangle \) encodes the first n qubits \(|y_{n-1}\rangle ,|y_{n-2}\rangle ,\ldots ,|y_{0}\rangle \) along the vertical location and the second n qubits \(|x_{n-1}\rangle , |x_{n-2}\rangle ,\ldots ,|x_{0}\rangle \) along the horizontal axis.

Having a quantum representation for digital RGB images, we are able to propose a new version of QIH model, extending its operation in such images. Similar to QIH for grayscale image, it is necessary to count the colors, but the minor difference is related to the color range due to having three channels here. Accordingly, three separate image histogram qubit sequences should be defined, meaning that the volume of each channel can be counted in entire image by an image histogram just like QIH for grayscale image with one channel discussed in Sect. 3. Hence, QIH for RGB images based on NCQI images can be formulated as follows.

Red channel

$$\begin{aligned} |\mathrm{QIH}\rangle _{R}= & {} \frac{1}{2^{q}}\sum ^{2^{q}-1}_{C_{r}=0}|C_{r} \rangle \otimes |N_{C_{r}}\rangle , \nonumber \\ |C_{r}\rangle= & {} |C^{q-1}_{r}C^{q-2}_{r}\ldots C^{1}_{r}C^{0}_{r}\rangle , C^{i}_{r}\in {0,1}, i=(0,1,\ldots ,q-1), \nonumber \\ |N_{C_{r}}\rangle= & {} |N^{2n}_{C_{r}}N^{2n-1}_{C_{r}}\ldots N^{1}_{C_{r}}N^{0}_{C_{r}}\rangle , \end{aligned}$$
(19)

Green channel

$$\begin{aligned} |\mathrm{QIH}\rangle _{G}= & {} \frac{1}{2^{q}}\sum ^{2^{q}-1}_{C_{g}=0}|C_{g} \rangle \otimes |N_{C_{g}}\rangle , \nonumber \\ |C_{g}\rangle= & {} |C^{q-1}_{g}C^{q-2}_{g}\ldots C^{1}_{g}C^{0}_{g}\rangle , C^{i}_{g}\in {0,1}, i=(0,1,\ldots ,q-1), \nonumber \\ |N_{C_{g}}\rangle= & {} |N^{2n}_{C_{g}}N^{2n-1}_{C_{g}}\ldots N^{1}_{C_{g}}N^{0}_{C_{g}}\rangle , \end{aligned}$$
(20)

Blue channel

$$\begin{aligned} |\mathrm{QIH}\rangle _{B}= & {} \frac{1}{2^{q}}\sum ^{2^{q}-1}_{C_{b}=0}|C_{b}\rangle \otimes |N_{C_{b}}\rangle , \nonumber \\ |C_{b}\rangle= & {} |C^{q-1}_{b}C^{q-2}_{b}\ldots C^{1}_{b}C^{0}_{b}\rangle , C^{i}_{b}\in {0,1}, i=(0,1,\ldots ,q-1), \nonumber \\ |N_{C_{b}}\rangle= & {} |N^{2n}_{C_{b}}N^{2n-1}_{C_{b}}\ldots N^{1}_{C_{b}}N^{0}_{C_{b}}\rangle . \end{aligned}$$
(21)

Take a simple \(4\times 4\) RGB image as an example. The QIH model for red channel of this image is demonstrated in Fig. 8, with a table showing how essential information of the histogram is turned to the qubit sequence. Likewise, \(|\mathrm{QIH}\rangle _{G}\) and \(|\mathrm{QIH}\rangle _{B}\) can be calculated according to the QIH.

Fig. 8
figure 8

Quantum image histogram (QIH) for the red channel of a simple \(4\times 4\) RGB image

As for Eq. 1920 and 21, they precisely seem to be similar to QIH model for grayscale images shown in Eq. 4. Consequently, the preparation procedure of this extended model is like what has been discussed in Sect. 3, meaning that it is necessary to carry out the procedure three times. In other words, for preparing QIH for RGB images with size \(2^{n}\times 2^{n}\) and color range \(2^{q}\) based on NCQI model, \(\left( 3\times (q+2n+1)\right) \) qubits are required fundamentally. Furthermore, having threefold time complexity, \(|\mathrm{QIH}\rangle _{RGB}\) is considerably more complex than that of \(|\mathrm{QIH}\rangle \) belonged to grayscale images on the account of the fact that it needs to store color channels and its corresponding numbers individually.

Having defined \(\varGamma _{1}\) in Sect. 3 (Eq. 7), it should be applied to three qubit sequences named \(|\psi _{R0}\rangle \), \(|\psi _{G0}\rangle \) and \(|\psi _{B0}\rangle \), which each of them includes \(|0\rangle ^{\otimes q+2n+1}\). So \(\varGamma _{1}\) brings about the following intermediate states.

$$\begin{aligned} |\psi _{R1}\rangle= & {} \frac{1}{2^{q}}\sum ^{2^{q-1}}_{C_r=0}|C_r\rangle \otimes |0\rangle ^{\otimes 2n+1}\end{aligned}$$
(22)
$$\begin{aligned} |\psi _{G1}\rangle= & {} \frac{1}{2^{q}} \sum ^{2^{q-1}}_{C_g=0}|C_g\rangle \otimes |0\rangle ^{\otimes 2n+1}\end{aligned}$$
(23)
$$\begin{aligned} |\psi _{B1}\rangle= & {} \frac{1}{2^{q}} \sum ^{2^{q-1}}_{C_b=0}|C_b\rangle \otimes |0\rangle ^{\otimes 2n+1}. \end{aligned}$$
(24)

Regarding \(U_{i}\) defined in Eq. 9, it should be applied to our RGB image three times to involve red, green and blue channels separately and store the histogram information in \(|\psi _{R0}\rangle \), \(|\psi _{G0}\rangle \) and \(|\psi _{B0}\rangle \) in turn.

$$\begin{aligned}&U_{i}^{\otimes 3}\left( |{\textit{NCQI}}\rangle \right) = U_{i}^{\otimes 3}\left( \frac{1}{2^{n}}\sum ^{2^{2n}-1}_{j=0}|C_{\mathrm{RGB}_{i}}\rangle \otimes |j\rangle \right) \\&\quad =\frac{1}{2^{n}}U_{i}^{\otimes 3}\left( \sum ^{2^{2n}-1}_{j=0,j\ne i}|C_{\mathrm{RGB}_{i}}\rangle \otimes |j\rangle + |C_{\mathrm{RGB}_{i}}\rangle \otimes |i\rangle \right) \nonumber \\ \nonumber&\quad \left\{ \begin{array}{ll} \hbox {Red}, &{} {\frac{1}{2^{n}}\left( \sum ^{2^{2n}-1}_{j=0,j\ne i}|R_{j}\rangle |G_{j}\rangle |B_{j}\rangle \otimes |j\rangle + \varOmega _{i}\left( |R_{i}\rangle \right) |G_{i}\rangle |B_{i}\rangle \otimes |i\rangle \right) ;} \\ \hbox {Green}, &{} {\frac{1}{2^{n}}\left( \sum ^{2^{2n}-1}_{j=0,j\ne i}|R_{j}\rangle |G_{j}\rangle |B_{j}\rangle \otimes |j\rangle + |R_{i}\rangle \varOmega _{i}\left( |G_{i}\rangle \right) |B_{i}\rangle \otimes |i\rangle \right) ;} \\ \hbox {Blue}, &{} {\frac{1}{2^{n}}\left( \sum ^{2^{2n}-1}_{j=0,j\ne i}|R_{j}\rangle |G_{j}\rangle |B_{j}\rangle \otimes |j\rangle + |R_{i}\rangle |G_{i}\rangle \varOmega _{i}\left( |B_{i}\rangle \right) \otimes |i\rangle \right) .} \\ \end{array} \right. \end{aligned}$$
(25)

\(\varOmega _{i}\) causes the value of each channel in position \(|i\rangle \) is counted once. To obtain the final states \(|\mathrm{QIH}_{R}\rangle \), \(|\mathrm{QIH}_{G}\rangle \) and \(|\mathrm{QIH}_{B}\rangle \), the quantum operation \(\varGamma _{2}\) defined in Eq. 15 should be implemented three times. Consequently, \(\varGamma _{2}^{\otimes 3}\) is our final operation that should be applied to our NCQI (RGB) image to generate the related image histogram information.

Note that the designed quantum circuit depicted in Fig. 5 can also be used in this section. It is necessary to apply it to our RGB images three times, in which red, green and blue channels would be involved. The generality of our proposed approach is obvious here owning to the fact that just by one quantum network, image histograms can be generated efficiently for both grayscale and RGB images.

4 Comparison

Notwithstanding the fact that QImP has now become the focal center of interest among researchers, to the best of our knowledge, image histogram has not received enough attention in QImP. The only related work that can be considered here is a contribution published by Zhang et al. [28], which is capable of proposing a quantum model for representing a digital image as well as constructing its histogram information simultaneously. The following demonstrate a fair comparison with the mentioned published paper.

  1. 1.

    The introduced method in Ref. [28] is just based on grayscale images and cannot be used for RGB images including red, green and blue channels, as opposed to our investigated approach which is able to be used for both grayscale and RGB images.

  2. 2.

    Unarguably, used for conducting an in-depth statistical analysis, image histogram should indicate the number of all possible intensities even those which are not in the image, so that histogram processing methods would be able to be performed effectively. Take enhancing contrast of images using image histogram as an example; it is of crucial importance to have frequency of all possible intensities. Reference [28] just stores the number of existent intensities, meaning that for some histogram processing purposes, this quantum model cannot be used. Our suggested method encodes not only the number of all intensities of pixels, but also the nonexistent intensities (as zero).

  3. 3.

    Not everything, however, is negative about Ref. [28]. Their time complexity to construct an image histogram based on quantum properties is not more than \(O(2^{2n+q})\), while ours is \(O(nq2^{2n+q})\). This is due to the fact that we sacrifice time complexity to have a flexible quantum model, which is able to be used for both grayscale and RGB images, and also, it can be used in quantum image histogram processing methods efficiently.

5 QIH as a strict criterion for quantum data hiding algorithms

In quantum image processing (QImP), data hiding algorithms refer to methods which conceal some secret information in a cover image represented in quantum states. Fundamentally, they can be categorized as two approaches: quantum image steganography and quantum image watermarking. The former is defined as hiding secret information in an innocent cover image, in which nobody except the receiver can figure out the secret data [18]. The latter aims at embedding specific information, usually owner’s identification, into a carrier image for copyright protection methods [24]. In both methods, it is of crucial importance that they should not change the cover image visually so that unauthorized individuals would not be able to guess whether the submitted image is an original image or a manipulated one.

Image histogram can be regarded as a useful tool for assessing the visual effects caused by both aforementioned approaches. As a matter of fact, the more similarity between the histogram diagrams belonged to the original and manipulated images, the more reliability, meaning that this similarity is capable of proving indiscernible modifications. Consequently, image histogram is one of the most useful tools in quantum data hiding algorithms. In this section, we shows how QIH can be utilized effectively as a useful criterion in QImP.

Figure 9 illustrates image histogram diagrams of four selected images before and after applying two methods proposed by Heidari et al. [20, 23]. The similarity between the indicated diagrams proves the good performance of their approaches.

Fig. 9
figure 9

Image histograms of four selected images before and after applying two suggested methods (Refs. [20, 23])

The provided diagrams shown in Fig. 9 have been simulated by a classical computer in MATLAB environment, which means QImP lacks such a criterion in quantum states. So, by having QIH as a model for representing image histograms of both grayscale and RGB images, the future suggested methods in quantum data hiding can be evaluated based on QIH instead of simulating digitally.

Consider QIH and QIH’ as quantum image histograms of the original gray-tone image and the manipulated one, respectively, which can be given as follows.

$$\begin{aligned} |{\textit{QIH}}\rangle= & {} \frac{1}{2^{q}}\sum ^{2^{q}-1}_{C=0}|C\rangle \otimes |N_{C}\rangle , \nonumber \\ |C\rangle= & {} |C^{q-1}C^{q-2}\ldots C^{1}C^{0}\rangle , C^{i}\in {0,1}, i=(0,1,\ldots ,q-1), \nonumber \\|N_{C}\rangle= & {} |N^{2n}_{C}N^{2n-1}_{C}\ldots N^{1}_{C}N^{0}_{C}\rangle , \end{aligned}$$
(26)
$$\begin{aligned} |{\textit{QIH}}'\rangle= & {} \frac{1}{2^{q}}\sum ^{2^{q}-1}_{C'=0}|C\rangle \otimes |N'_{C'}\rangle ,\nonumber \\ |C'\rangle= & {} |C'^{q-1}C'^{q-2}\ldots C'^{1}C^{0}\rangle , C'^{i}\in {0,1}, i=(0,1,\ldots ,q-1), \nonumber \\ |N'_{C'}\rangle= & {} |N'^{2n}_{C'}N'^{2n-1}_{C'}\ldots N'^{1}_{C'}N'^{0}_{C'}\rangle . \end{aligned}$$
(27)
Fig. 10
figure 10

Required quantum circuit to calculate the difference between \(|N_{C}\rangle \) and \(|N'_{C'}\rangle \)

To know the similarity, a quantum operation to calculate the difference between the two QIHs is required. This quantum operation should be the subtracter operation which has been discussed in Sect. 3 and is shown in Fig. 6. As explained earlier, considering inputs (ab), the output of the subtracter will be \((a,a-b)\) when \(a>b\). When \(a<b\), the output will be \((a, 2^{n+1}-(b-a))\), where \(n+1\) is the size of the second register. It means the results will be stored in the second register. All we need here to have the difference between \(|N_{C}\rangle \) and \(|N'_{C'}\rangle \) is making them as inputs of the quantum subtracter. The required quantum circuit is provided in Fig. 10, showing how the difference is stored in \(|N'_{C'}\rangle \). Consequently, it would be obvious how much \(|N'_{C'}\rangle \) is close to zero, and the desired observation of similarity could be obtained easily, meaning that the more values are close to zero, the more related method is reliable.

6 Conclusion

In recent years, quantum image processing (QImP) has been investigated noticeably by researchers and a variety of representations has been introduced based on quantum computation to store image information in quantum states. In other words, this area of study tends to be developed effectually as long as more and more practical tools can be proposed for its applications. As one of the most important statistical analysis tools, which are used widely in digital image processing, in this paper, a general quantum model for constructing image histogram named QIH has been presented. Image histogram can be defined as a technique used for showing the frequency of the intensity values that occurs in an image. QIH initializes two entangled qubit sequences in order to create the image histogram based on NEQR and NCQI image, meaning that it can be used for both quantum grayscale and RGB images. The discussed constructive polynomial preparation of this model proved that the time complexity based on NEQR image is no more than \(O(nq2^{2n+q})\), when size of NEQR image is \(2^{n}\times 2^{n}\) with gray range \(2^{q}\), and also, it required \((q+2n+1)\) qubits to be carried out. Moreover, because of being similar to NEQR image, NCQI has been used in the proposed model in order to construct image histogram for RGB images. Finally, to show a practical use of the proposed method, we have discussed how QIH can be used efficiently as a strict criterion in quantum data hiding algorithms.

As regards future studies, QIH can be used effectively in statistical analysis procedures such as image enhancement, image equalization, histogram matching, brightness and contrast purposes, and thresholding, based on quantum computation, which are applicable for medical, defense, security, space-borne, aeronautical and many other fields.