Skip to main content

View on GitHub

Open this notebook in GitHub to run it yourself
Based on the paper: “Edge Detection Quantumized: A Novel Quantum Algorithm for Image Processing” https://arxiv.org/html/2404.06889v1 This notebook demonstrates:
  1. QPIE (Quantum Probability Image Encoding) encoding
  2. QHED (Quantum Hadamard Edge Detection) algorithm
The encoding was implemented based on this paper: https://arxiv.org/pdf/1801.01465
Output:

QPIE Encoding Implementation

Convert an image into valid QPIE probability amplitudes. The image is converted to grayscale if needed, made non-negative, and L2-normalized so the sum of squared values equals
  1. The result is stored as an n×nn \times n array IMAGE_DATA.
Output:
Output:

Modified QHED Algorithm

We define an ImagePixel QStruct with separate x and y registers, and load the image via lookup_table - the amplitudes are computed classically from the pixel coordinates and loaded with prepare_amplitudes. The QHED algorithm detects edges by:
  1. Adding auxiliary qubits in +|+\rangle state
  2. Controlled shifts of xx (horizontal) and yy (vertical) by 1-1
  3. Applying Hadamard to compute differences
  4. Measuring to get edge information
Output:

Synthesize and Analyze the Quantum Circuit

The model is synthesized with a 20-qubit width limit and a long timeout, and finally exported as quantum_image_edge_detection with 15-digit numeric precision.
Output:
Output:
Output:
pixel.x pixel.y edge_aux counts probability bitstring
0 63 92 0 185 0.000925 010111000111111
1 71 94 0 167 0.000835 010111101000111
2 62 91 0 165 0.000825 010110110111110
3 63 91 0 163 0.000815 010110110111111
4 37 87 0 155 0.000775 010101110100101
17250 113 127 1 1 0.000005 111111111110001
17251 117 127 1 1 0.000005 111111111110101
17252 118 127 1 1 0.000005 111111111110110
17253 121 127 1 1 0.000005 111111111111001
17254 123 127 1 1 0.000005 111111111111011

17255 rows × 6 columns

Create Edge Image from Measurement Results

If edge_aux == 1 then it is marked as an edge pixel. The new amplitude is calculated based on the number of shots measured for that pixel, normalized by the total number of shots.
Analyze amplitude distributions
Output:
Some amplitudes are extremely small and can be treated as noise; discarding them yields a cleaner edge image.
Output:
The resulting edge-detected image
Output:
In comparison, the original image is:
Output: