# A Fast Quantum Image Component Labeling Algorithm

^{1}

^{2}

^{3}

^{4}

^{*}

## Abstract

**:**

## 1. Introduction

## 2. Local-Operator Technique

#### 2.1. Basic Definitions

#### 2.2. The Parallel-Shrink Operator

- No connected component becomes disconnected.
- No two disconnected components become connected in any step.

#### 2.3. The Label-Propagate Operator

#### 2.4. A Simple Example of the Local-Operator Technique

**Phase 1 Preparation:**When every pixel has its ${N}_{s}$ and ${N}_{p}$ neighbors, the original image is extended by a 1-pixel outer border that pads the border of the image with white. The white pixels (0 value) are ignored in the board so that we can focus better on changes in the black regions (1 value), as shown in Figure 2b.

**Phase 2 Parallel shrinking:**In Phase 2, the parallel-shrink operator, (1) or (2), is performed on every pixel simultaneously. Since the maximum value of the internal diameter of the two connected regions is 3, the operator would be applied three times, and then all pixels of the image will change to 0 and that completes Phase 2. Figure 2c–e depict the performance process. In Figure 2c–e, we only show the pixels that were changed using the red dotted box.

**Phase 3 Label propagating:**As mentioned before, label propagating is a reverse-order process, so Equations (3) and (4) are applied for the same number of times as Phase 2. The process order is indicated in Figure 2f–h using the left arrow, and the purple dotted boxes are used for marking the label change. In Figure 2h, $p(1,1)$, $p(2,5)$, and $p(3,4)$ are labeled with different numbers based on (3) at the same time. We use the row–column criterion to label the pixels. In Figure 2f, serial numbers of the pixels that have been labeled are represented in the upper left corner box, $p(1,2)$, $p(2,1)$, $p(3,5)$, $p(4,4)$ need new labels based on Equation (3), and $p(2,5)$ needs a change of the labeled number based on Equation (4) to keep consistent with $p(3,5)$’s ${N}_{p}$ neighbors. In Figure 2f, the last two pixels, $p(2,2)$ and $p(4,5)$, are labeled, which means that label propagating is finished, and two different label numbers are obtained.

## 3. Quantum Version of the Local-Operator Technique

#### 3.1. Modified NEQR Model Representation of a Binary Image

#### 3.2. Basic Quantum Functional Circuits

#### 3.2.1. Address Shift Operation Circuits

**.**We call the shift transformation circuit an address shift operation circuit just like the address-of operator in classical programming.

#### 3.2.2. Logic Operation Circuit

#### 3.2.3. Control Assignment Operation Circuit

#### 3.2.4. Compare Operation Circuit

#### 3.2.5. Full Addition Circuit

#### 3.2.6. Full Subtraction Circuit

#### 3.3. Implementing Quantum Image Component Labeling

#### 3.3.1. Quantum Parallel Shrinking

#### 3.3.2. Quantum Label Propagating

## 4. Quantum Circuit Complexity Analysis

#### 4.1. Time Complexity

#### 4.1.1. Quantum Parallel Shrinking

#### 4.1.2. Quantum Label Propagating

#### 4.2. Spatial Complexity

## 5. Simulation on Classical Computer

## 6. Conclusions

## Author Contributions

## Funding

## Institutional Review Board Statement

## Informed Consent Statement

## Data Availability Statement

## Acknowledgments

## Conflicts of Interest

## References

- Venegas-Andraca, S.E.; Bose, S. Storing, Processing, and Retrieving an Image Using Quantum Mechanics. Quantum Inf. Comput.
**2003**, 5105, 137–147. [Google Scholar] - Venegas-Andraca, S.E.; Ball, J. Processing images in entangled quantum systems. Quantum Inf. Processing
**2010**, 9, 1–11. [Google Scholar] [CrossRef] - Le, P.Q.; Dong, F.; Hirota, K. A flexible representation of quantum images for polynomial preparation, image compression, and processing operations. Quantum Inf. Processing
**2011**, 10, 63–84. [Google Scholar] [CrossRef] - Zhang, Y.; Lu, K.; Gao, Y.; Xu, K. A novel quantum representation for log-polar images. Quantum Inf. Processing
**2013**, 12, 3103–3126. [Google Scholar] [CrossRef] - Zhang, Y.; Lu, K.; Gao, Y.; Wang, M. NEQR: A novel enhanced quantum representation of digital images. Quantum Inf. Processing
**2013**, 12, 2833–2860. [Google Scholar] [CrossRef] - Mastriani, M. Quantum Boolean image denoising. Quantum Inf. Processing
**2015**, 14, 1647–1673. [Google Scholar] [CrossRef] [Green Version] - Yuan, S.; Mao, X.; Xue, Y.; Chen, L.; Xiong, Q.; Compare, A. SQR: A simple quantum representation of infrared images. Quantum Inf. Processing
**2014**, 13, 1353–1379. [Google Scholar] [CrossRef] - Sun, B.; Iliyasu, A.; Yan, F.; Dong, F.; Hirota, K.J. An RGB multi-channel representation for images on quantum computers. J. Adv. Comput. Intell. Intell. Inform.
**2013**, 17, 404–415. [Google Scholar] [CrossRef] - Li, H.-S.; Zhu, Q.; Zhou, R.-G.; Song, L.; Yang, X.-J. Multi-dimensional color image storage and retrieval for a normal arbitrary quantum superposition state. Quantum Inf. Processing
**2014**, 13, 991–1011. [Google Scholar] [CrossRef] - Sang, J.; Wang, S.; Li, Q. A novel quantum representation of color digital images. Quantum Inf. Processing
**2017**, 16, 42. [Google Scholar] [CrossRef] - Abdolmaleky, M.; Naseri, M.; Batle, J.; Farouk, A.; Gong, L.-H. Red-Green-Blue multi-channel quantum representation of digital images. Optik
**2017**, 128, 121–132. [Google Scholar] [CrossRef] - Xu, G.; Xu, X.; Wang, X.; Wang, X. Order-encoded quantum image model and parallel histogram specification. Quantum Inf. Processing
**2019**, 18, 346. [Google Scholar] [CrossRef] - Khan, R.A. An improved flexible representation of quantum images. Quantum Inf. Processing
**2019**, 18, 201. [Google Scholar] [CrossRef] - Wang, L.; Ran, Q.; Ma, J.; Yu, S.; Tan, L. QRCI: A new quantum representation model of color digital images. Opt. Commun.
**2019**, 438, 147–158. [Google Scholar] [CrossRef] - Chen, G.-L.; Song, X.-H.; Venegas-Andraca, S.E.; El-Latif, A.; Ahmed, A. QIRHSI: Novel quantum image representation based on HSI color space model. Quantum Inf. Processing
**2022**, 21, 5. [Google Scholar] [CrossRef] - Zhu, H.-H.; Chen, X.-B.; Yang, Y.-X. Image preparations of multi-mode quantum image representation and their application on quantum image reproduction. Optik
**2022**, 251, 168321. [Google Scholar] [CrossRef] - Le, P.Q.; Iliyasu, A.M.; Dong, F.; Hirota, K. Strategies for designing geometric transformations on quantum images. Theor. Comput. Sci.
**2011**, 412, 1406–1418. [Google Scholar] [CrossRef] [Green Version] - Wang, J.; Jiang, N.; Wang, L. Quantum image translation. Quantum Inf. Processing
**2015**, 14, 1589–1604. [Google Scholar] [CrossRef] - Le, P.Q.; Iliyasu, A.M.; Dong, F.; Hirota, K. Fast Geometric Transformations on Quantum Images. Int. J. Appl. Math.
**2010**, 40, 3. [Google Scholar] - Jiang, N.; Wang, J.; Mu, Y. Quantum image scaling up based on nearest-neighbor interpolation with integer scaling ratio. Quantum Inf. Processing
**2015**, 14, 4001–4026. [Google Scholar] [CrossRef] - Sang, J.; Wang, S.; Niu, X. Quantum realization of the nearest-neighbor interpolation method for FRQI and NEQR. Quantum Inf. Processing
**2016**, 15, 37–64. [Google Scholar] [CrossRef] - Li, P.; Liu, X. Bilinear interpolation method for quantum images based on quantum Fourier transform. Int. J. Quantum Inf.
**2018**, 16, 1850031. [Google Scholar] [CrossRef] - Zhou, R.-G.; Cheng, Y.; Liu, D. Quantum image scaling based on bilinear interpolation with arbitrary scaling ratio. Quantum Inf. Processing
**2019**, 18, 267. [Google Scholar] [CrossRef] - Jiang, N.; Wang, L. Analysis and improvement of the quantum Arnold image scrambling. Quantum Inf. Processing
**2014**, 13, 1545–1551. [Google Scholar] [CrossRef] - Zhou, R.-G.; Sun, Y.-J.; Fan, P. Quantum image Gray-code and bit-plane scrambling. Quantum Inf. Processing
**2015**, 14, 1717–1734. [Google Scholar] [CrossRef] - Caraiman, S.; Manta, V.I. Histogram-based segmentation of quantum images. Theor. Comput. Sci.
**2014**, 529, 46–60. [Google Scholar] [CrossRef] - Caraiman, S.; Manta, V.I. Image segmentation on a quantum computer. Quantum Inf. Processing
**2015**, 14, 1693–1715. [Google Scholar] [CrossRef] - Wang, X.; Yang, C.; Xie, G.-S.; Liu, Z. Image thresholding segmentation on quantum state space. Entropy
**2018**, 20, 728. [Google Scholar] [CrossRef] [Green Version] - Li, P.; Shi, T.; Zhao, Y.; Lu, A. Design of threshold segmentation method for quantum image. Int. J. Theor. Phys.
**2020**, 59, 514–538. [Google Scholar] [CrossRef] - Zhang, Y.; Lu, K.; Gao, Y. QSobel: A novel quantum image edge extraction algorithm. Sci. China Inf. Sci.
**2015**, 58, 1–13. [Google Scholar] [CrossRef] [Green Version] - Fan, P.; Zhou, R.-G.; Hu, W.W.; Jing, N. Quantum image edge extraction based on Laplacian operator and zero-cross method. Quantum Inf. Processing
**2019**, 18, 27. [Google Scholar] [CrossRef] - Fan, P.; Zhou, R.-G.; Hu, W.; Jing, N. Quantum image edge extraction based on classical Sobel operator for NEQR. Quantum Inf. Processing
**2019**, 18, 24. [Google Scholar] [CrossRef] - Zhou, R.-G.; Yu, H.; Cheng, Y.; Li, F.-X. Quantum image edge extraction based on improved Prewitt operator. Quantum Inf. Processing
**2019**, 18, 261. [Google Scholar] [CrossRef] - Li, P.; Shi, T.; Lu, A.; Wang, B. Quantum implementation of classical Marr–Hildreth edge detection. Quantum Inf. Processing
**2020**, 19, 64. [Google Scholar] [CrossRef] - Chetia, R.; Boruah, S.; Sahu, P. Quantum image edge detection using improved Sobel mask based on NEQR. Quantum Inf. Processing
**2021**, 20, 21. [Google Scholar] [CrossRef] - Jiang, N.; Dang, Y.; Wang, J. Quantum image matching. Quantum Inf. Processing
**2016**, 15, 3543–3572. [Google Scholar] [CrossRef] [Green Version] - Dang, Y.; Jiang, N.; Hu, H.; Zhang, W. Analysis and improvement of the quantum image matching. Quantum Inf. Processing
**2017**, 16, 269. [Google Scholar] [CrossRef] - Luo, G.; Zhou, R.-G.; Liu, X.; Hu, W.; Luo, J. Fuzzy matching based on gray-scale difference for quantum images. Int. J. Theor. Phys.
**2018**, 57, 2447–2460. [Google Scholar] [CrossRef] - Heidari, S.; Naseri, M. A novel LSB based quantum watermarking. Int. J. Theor. Phys.
**2016**, 55, 4205–4218. [Google Scholar] [CrossRef] - Hu, W.; Zhou, R.-G.; Luo, J.; Liu, B. LSBs-based quantum color images watermarking algorithm in edge region. Quantum Inf. Processing
**2019**, 18, 16. [Google Scholar] [CrossRef] - He, L.; Ren, X.; Gao, Q.; Zhao, X.; Yao, B.; Chao, Y. The connected-component labeling problem: A review of state-of-the-art algorithms. Pattern Recognit.
**2017**, 70, 25–43. [Google Scholar] [CrossRef] - Alnuweiri, H.M.; Prasanna, V.K. Parallel architectures and algorithms for image component labeling. IEEE Trans. Pattern Anal. Mach. Intell.
**1992**, 14, 1014–1034. [Google Scholar] [CrossRef] - Levialdi, S. On shrinking binary picture patterns. Commun. ACM
**1972**, 15, 7–10. [Google Scholar] [CrossRef] - Cheng, K.-W.; Tseng, C.-C. Quantum full adder and subtractor. Electron. Lett.
**2002**, 38, 1343–1344. [Google Scholar] [CrossRef] - Barenco, A.; Bennett, C.H.; Cleve, R.; DiVincenzo, D.P.; Margolus, N.; Shor, P.; Sleator, T.; Smolin, J.A.; Weinfurter, H. Elementary gates for quantum computation. Phys. Rev. A
**1995**, 52, 3457. [Google Scholar] [CrossRef] [PubMed] [Green Version] - Nielsen, M.A.; Chuang, I. Quantum Computation and Quantum Information, 10th ed.; Cambridge University Press: Cambridge, UK, 2010. [Google Scholar]
- LaRose, R. Overview and comparison of gate level quantum software platforms. Quantum
**2019**, 3, 130. [Google Scholar] [CrossRef] [Green Version] - Bolelli, F.; Cancilla, M.; Baraldi, L.; Grana, C.J. Toward reliable experiments on the performance of connected components labeling algorithms. J. Real Time Image Processing
**2020**, 17, 229–244. [Google Scholar] [CrossRef] [Green Version] - Chang, F.; Chen, C.-J.; Lu, C.-J. A linear-time component-labeling algorithm using contour tracing technique. Comput. Vis. Image Underst.
**2004**, 93, 206–220. [Google Scholar] [CrossRef] [Green Version] - Wu, K.; Otoo, E.; Suzuki, K. Optimizing two-pass connected-component labeling algorithms. Pattern Anal. Appl.
**2009**, 12, 117–135. [Google Scholar] [CrossRef]

**Figure 2.**The simple example of local-operator techniques. (

**a**) original image. (

**b**) adding border. (

**c**) partial result 1. (

**d**) partial result 2. (

**e**) partial result 3. (

**f**) propagate 3. (

**g**) propagate 2. (

**h**) propagate 1.

**Figure 3.**The quantum circuit of Figure 2b.

**Figure 4.**Address shift operation circuit. (

**a**) Shift + operator circuit. (

**b**) Shift − operator circuit.

**Figure 5.**Logic operation circuit. (

**a**) Logic operation $\wedge $ (AND). (

**b**) Logic operation $\vee $ (OR).

**Figure 9.**Full subtractor circuit. (

**a**) 1-bit full subtractor circuit. (

**b**) n-bit full subtractor circuit.

**Figure 18.**The example of traffic signs. (

**a**) original image. (

**b**) binary image. (

**c**) component labeling.

**Figure 19.**The example of license plates, “陕” in figure means Shanxi Province. (

**a**) original image. (

**b**) binary image. (

**c**) component labeling.

No. | Function | Ancilla Qubits |
---|---|---|

1 | Address Shift Operation Circuit | 0 |

2 | Logic Operation Circuit | 1 |

3 | Control Assignment Operation Circuit | n + 1 |

4 | Compare Operation Circuit | 2n |

5 | Full Addition Circuit | 2n + 1 |

6 | Full Subtraction Circuit | 2n + 1 |

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |

© 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Li, Y.; Hao, D.; Xu, Y.; Lai, K.
A Fast Quantum Image Component Labeling Algorithm. *Mathematics* **2022**, *10*, 2718.
https://doi.org/10.3390/math10152718

**AMA Style**

Li Y, Hao D, Xu Y, Lai K.
A Fast Quantum Image Component Labeling Algorithm. *Mathematics*. 2022; 10(15):2718.
https://doi.org/10.3390/math10152718

**Chicago/Turabian Style**

Li, Yan, Dapeng Hao, Yang Xu, and Kinkeung Lai.
2022. "A Fast Quantum Image Component Labeling Algorithm" *Mathematics* 10, no. 15: 2718.
https://doi.org/10.3390/math10152718