WaterQRcode: Anti-Counterfeiting QR with Hidden Stochastic Texture
Course: Digital Image Processing
University: Università degli Studi di Brescia (UNIBS) - Master's in Computer Engineering
Authors: Filippo Camossi & Davide Leone
WaterQRcode is a Digital Image Processing project that implements and verifies the anti-counterfeiting technique described in the scientific paper "A Texture-Hidden Anti-Counterfeiting QR Code and Authentication Method" (Wang, Zheng, et al., Sensors 2023).
The primary objective is to generate a QR code that intrinsically resists physical duplication (print-and-scan attacks). This is achieved by embedding a high-frequency stochastic (random) texture into the background of the QR code. The security mechanism exploits the inevitable image degradation introduced by the physical copying process. This degradation irreversibly alters the texture's signature, allowing the system to detect forgeries through frequency domain analysis (Discrete Fourier Transform).
The project is structured as an end-to-end processing pipeline, executing six distinct phases within a Jupyter Notebook environment:
- Phase 1: Stochastic Texture Synthesis. Generates a binary halftone background pattern. It starts with Gaussian noise (μ=120, σ=100), applies low-pass filtering via bilinear interpolation, and performs halftoning using Ordered Dithering (Level 2 Bayer Matrix).
- Phase 2: Spatial QR Refinement. Creates a standard QR code with maximum error correction (Level H, 30% redundancy) and selectively shrinks the data modules to 5x5 pixels while preserving critical alignment and positioning patterns.
- Phase 3: Mask-based Fusion. Merges the refined QR code with the stochastic texture, safely replacing background placeholder pixels without compromising the QR readability.
- Phase 4: Forgery Simulation. Generates a simulated testing dataset representing both genuine paths (Digital → Print → Capture) and counterfeited paths (Digital → Print → Scan → Reprint → Capture) to evaluate robustness.
- Phase 5: DFDA Authentication. Implements the Dual Feature Detection Algorithm. It assesses image sharpness (MAF), verifies logical decodability to detect "gluing" phenomena, and performs Spectral Analysis in the frequency domain calculating Normalized Correlation (NC) and Pixel Ratio (PR) metrics.
- Phase 6: Experimental Verification. Validates the algorithm's thresholds over a simulated dataset of 200 samples to establish optimal NC and PR detection boundaries.
- Research-to-Code Implementation: Successfully translates complex signal processing algorithms and mathematical models from a published scientific paper into a functional Python application.
- Security vs. Usability Balance: Brilliantly combines the practical robustness of Level H QR error correction with advanced signal-based security, ensuring the code remains easily readable by standard smartphone scanners while being mathematically secure against replication.
- Automated Print Export: Automatically generates print-ready A4 PDF/PNG sheets with the generated secure QR codes scaled at various physical dimensions for real-world testing.
- Language: Python 3.7+
- Environment: Jupyter Notebook
- Core Libraries:
numpy(matrix operations),opencv-python(image processing & DFT),qrcode[pil](QR generation),pyzbar(QR decoding),matplotlib(spectral visualization).
Follow these steps to run the image processing pipeline locally.
- Python 3.7 or higher installed on your system.
-
Clone the repository:
git clone https://github.com/SickCiQuattro/WaterQRcode.git cd WaterQRcode -
Install the required dependencies:
pip install -r requirements.txt
-
Launch the Jupyter Notebook:
jupyter notebook qrgen.ipynb
-
Run the cells sequentially. The parameters can be tweaked in the CONFIG_* dictionaries at the beginning of the notebook.
-
Check the output/ directory for the intermediate processing steps, the final simulated forgery datasets, and the printable A4 sheets.
-
Primary Study: Wang, T.; Zheng, H.; You, C.; Ju, J. "A Texture-Hidden Anti-Counterfeiting QR Code and Authentication Method". Sensors 2023, 23, 795. DOI: 10.3390/s23020795
-
Standards: ISO/IEC 18004 (QR Code Standard)