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


QPIE Encoding Implementation
Now, convert an image into valid QPIE probability amplitudes. The image is converted to grayscale if needed, flattened to a 1D vector, made non-negative, and L2-normalized so the sum of squared values equals- If the image is all zeros, a uniform normalized vector is returned to avoid division by zero.
Output:
Modified QHED Algorithm
The QHED algorithm detects edges by:- Adding an auxiliary qubit in state
- Applying amplitude permutation to shift pixels
- Applying Hadamard to compute differences
- 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:
| pos | edge_aux | count | probability | bitstring | |
|---|---|---|---|---|---|
| 0 | 11710 | 0 | 173 | 0.000865 | 010110110111110 |
| 1 | 11839 | 0 | 169 | 0.000845 | 010111000111111 |
| 2 | 11316 | 0 | 162 | 0.000810 | 010110000110100 |
| 3 | 11712 | 0 | 162 | 0.000810 | 010110111000000 |
| 4 | 11711 | 0 | 159 | 0.000795 | 010110110111111 |
| … | … | … | … | … | … |
| 17285 | 16371 | 1 | 1 | 0.000005 | 111111111110011 |
| 17286 | 16372 | 1 | 1 | 0.000005 | 111111111110100 |
| 17287 | 16375 | 1 | 1 | 0.000005 | 111111111110111 |
| 17288 | 16376 | 1 | 1 | 0.000005 | 111111111111000 |
| 17289 | 16377 | 1 | 1 | 0.000005 | 111111111111001 |
17290 rows × 5 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.Output:

Output:

Output:

Output:
