Quantum Image Processing Visualization

by Makar Kuznietsov and Quantum Quintessential Quintuplets Team

Introduction

Image processing is in growing needs with the development of applications like facial recognition and autonomous vehicles. Due to the large volume and complexity of data, image processing is computationally expensive. More and more often, specialized hardwares such as GPUs are used to accelerate image processing. Quantum computing promises speed ups in a number of image processing algorithms, such as edge extraction.

We demonstrate Quantum Image Processing on the trapped ion quantum computers provided by IonQ. We first transform the image into a qubit representation named Flexible Representation of Quantum Images (FRQI). Next, we perform Quantum Fourier Transform on the input image as a demonstration of practical image processing on quantum computers. We visualize this process by repeatedly measuring the output qubits and feeding the output into a fractal generation routine.

Quantum Image Representation

To perform QFT on images, we first transform the images into a qubit representation named Flexible Representation of Quantum Images (FRQI). Each pixel is encoded with the color information encoding (cosθi|0⟩+sinθi|1⟩) and position encoding |i⟩, therefore the entire image is represented by the following quantum state:

The following circuit is used to prepare the quantum state with a 2x2 image. Larger images can be prepared using the same principle.

Circuit used to prepare quantum state of 2*2 image

QFT Algorithm:

Fourier transform is used in multiple applications: signal processing, image transformation, complexity theory, music, engineering, and more. Quantum Fourier Transform (QFT) is the quantum implementation of the discrete Fourier Transform. Multiple algorithms use the Quantum Fourier Transform including Shor’s factoring algorithm, and quantum phase estimation.

The Quantum Fourier Transform acts on a quantum state vector while the classical Fourier transform acts on a vector. The discrete Fourier Transform with 2^n amplitudes can be implemented as a quantum circuit with O(n²) controlled phase shift gates, and Hadamard gates. However, with the classical algorithm, it takes O(n2^n) gates. With Quantum Fourier transform, we have an exponential speed on the classical algorithm (Nielsen, Chuang, 2010).

QFT Implementation

In general, discrete Fourier transform maps a set of vectors x0, x1, …., x_N-1 to y0, y1, …., yN-1 .

Quantum Fourier transform maps a quantum state in x-basis to quantum state in y-basis

The N-qubit QFT unitary gate is then:

Our quantum circuit implementation comprises of Hadamard and Controlled-Rotation gates to create desired overall unitary gate.

Circuit used for QFT algorithm

As a result of QFT we obtain image in frequency(states) domain:

Output of QFT

Visualization

To visualize the process, we take the above measurement results to generate fractals. We first normalize the measured amplitudes of different states. Then, the normalized results are used as coefficients in a polynomial recursive formula in a fractal generation. Fractals are composed of patterns that are self-similar at different scales. We create fractals by repeating a simple process over and over in an ongoing feedback loop — creating so-called Julia sets. As we zoom into fractals, we notice similar shapes. This property is called self-similarity also known as expanding symmetry.

Fractals Implementation

As a recursive formula to generate Julia Sets we are using

where P and Q are polynomials. Coefficients of P and Q are determined uniquely by amplitudes from QFT analysis. We are running the recursive formula on every point of the complex plane in certain boundaries. The cells of the image are painted corresponding to how quickly the value of the cell became bigger than 2 by mapping from that value to RGB. As a result of an image, we see brighter regions — the ones that diverge slowly(or don’t diverge at all) and darker zones — the ones that diverge faster.

Image with different shades symbolising different speeds of converging.

The fractal is also evolving in time as the c coefficient is changing by a small increment every iteration. Polynomial formula is written in such a way that the fractal evolution represents decaying of |1> state to |0> state due to hardware noise. As a result in the end amplitudes of all states will be zero, except the |00…0> state, which will have maximum amplitude.

Left: Initial state, Right: Final state after sufficient time interval

The color of the fractal is smoothly changing from blue to red throughout time for vibrant visuals.

Results

From one of our images we obtained the following visualization.

Hardware

To run experiments, we primarily trained on QBraid with the IonQ simulation backend with noise since the fractal generation did not require a high degree of accuracy for the Quantum Fourier Transform. We used 1024 shots per experiment to approximate the probability amplitudes of the transformed wavefunction, which corresponded with approximately 3 significant figures. To confirm our results using actual hardware, we also generated two fractals using the IonQ hardware backend and received promising results.

Source Cited:

QSobel: A novel quantum image edge extraction algorithm

Space fractal art with Qiskit. (2022, August 17). LinkedIn. https://www.linkedin.com/pulse/space-fractal-art-qiskit-wiktor-mazin-phd-mmt/

Quantum fourier transform. (2022, November 29). qiskit.org. https://qiskit.org/textbook/ch-algorithms/quantum-fourier-transform.html

Quantum image processing: The truth, the whole truth, and nothing but the truth about its problems on internal image representation and outcomes recovering. (n.d.). arXiv.org. https://arxiv.org/abs/2002.04394

--

--