Skip to content

Kaminyou/Halftone-Color-QR-Codes

Repository files navigation

python version License: MIT linting workflow

Halftone-Color-QR-Codes

DIP 2025 Final Project. This project is an extension of the Halftone QR codes.

Install

$ pip install -r requirements.txt

Usage Examples

# gray example
$ python main.py -t 'https://www.csie.ntu.edu.tw/' -i 'input/gray_dog.png' -o 'output/stylized_qrcode.png' --meta -v 6 -b 3
# color example
$ python main.py -t 'https://www.csie.ntu.edu.tw/' -i 'input/color_hokkaido.png' -o 'output/stylized_qrcode.png' --meta -v 6 -b 5 --color

Summary

This project presents a lightweight yet effective method to generate stylized QR codes using traditional image processing techniques, extending the original Halftone QR code concept. Unlike prior deep-learning-based approaches, our method is efficient, supports color images, adjustable box sizes, and edge-aware module dropping to preserve important visual features. The result is visually appealing QR codes that remain highly scannable on common mobile devices. Key contributions include:

  • Color support: Stylization is applied independently across RGB channels.
  • Flexible control: Parameters like QR version, box size, and dropout ratio are user-adjustable.
  • Edge-aware stylization: Preserves details in salient image regions.
  • Open-source: Fully implemented in Python with clear CLI interface.

This approach provides a practical solution for integrating QR codes into aesthetic and design-sensitive contexts without sacrificing usability. For more details, please check our report

CLI Details

Command-line arguments for the Halftoning QRCode Generator.

Arguments:
    -t, --text (str): 
        The text or URL to encode into a QR code.
        Default: 'https://www.csie.ntu.edu.tw/'

    -i, --input (str): 
        Path to the input style image used to stylize the QR code.
        Default: 'input/sample1.png'

    -o, --output (str): 
        Path to save the stylized output QR code image.
        Default: 'output/stylized_qrcode.png'

    -v, --version (int): 
        QR code version (controls size and data capacity).
        Range: 1–40.
        Default: 6

    -b, --box-size (int): 
        Size (in pixels) of each QR code module (box).
        Default: 3

    -d, --drop-ratio (float): 
        Ratio (0.0–1.0) of randomly dropping a QR code module 
        for stylization or artistic effect.
        Default: 0.0

    --meta (flag): 
        If set, saves additional metadata associated with the QR code generation.
        Default: False (disabled)

    --color (flag): 
        If set, enables RGB mode (stylization with color image).
        Default: False (grayscale)
    
    --edge-enhance (flag): 
        If set, edges will be detected for module region keeping.
        Default: False (disabled)

    -e, --edge-ratio(float): 
        Ratio (0.0–1.0) of pixel of edge in the input image.
        Default: 0.1

    --wo-halftone (flag): 
        If set, our function will turn off the halftoning process.
        Default: False (Do halftoning)

    --pad-size (int): 
        Padding (in pixels) to apply around the final output QR code.
        Default: 5

Acknowledgement

This project is an extension of the Halftone QR codes.

@article{chu2013halftone,
  title={Halftone QR codes},
  author={Chu, Hung-Kuo and Chang, Chia-Sheng and Lee, Ruen-Rone and Mitra, Niloy J},
  journal={ACM transactions on graphics (TOG)},
  volume={32},
  number={6},
  pages={1--8},
  year={2013},
  publisher={ACM New York, NY, USA}
}

About

Halftone-Color-QR-Codes

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •