Skip to main content

Wu's list decoder for Reed-Solomon / QR codes over GF(2^8)

Project description

qr-list-decoder

Wu's list decoder QR codes

Completed as Master's Thesis Project (MTP) in the CSE Department at IIT Bombay.

This library implements Wu's list decoding algorithm, enabling error correction beyond the standard decoding radius of the code. It can recover QR codes with significantly more damage than standard decoders can handle.

Not only does it contain the advanced mathematical backend, but it also includes an end-to-end QR code pipeline (generating matrices, reading images, unmasking, and decoding).

Installation

From PyPI (Recommended):

pip install list-decoder-qr

From Source / Development: If you want to modify the code locally, clone the repository and install it in editable mode:

pip install .
# or for development
pip install -e .

What You Can Do With This Library

Here are the main tasks you can perform with qr-list-decoder:

Task 1: Read a QR Code from an Image File

If you have a picture of a QR code and you want to extract the hidden text from it:

from qr_list_decoder import decode_qr_image

# Pass the path to your image
result = decode_qr_image("my_scratched_qr.png")

if result.get('wu_success') or result.get('bm_success'):
    print("Decoded Text:", result.get('wu_text') or result.get('bm_text'))
else:
    print("Decoding failed:", result.get('error'))

Task 2: Batch Process a Whole Folder of Images

If you have a folder containing hundreds of QR code images and want to decode all of them at once:

from qr_list_decoder import decode_folder

# This will scan the folder, process every image, and print the results
decode_folder("./dataset_of_qr_codes")

(You can also do this directly from the command line: python qr_demo.py --folder ./dataset_of_qr_codes)

Task 3: Generate a New QR Code Image

You can use the library to encode text and create your own QR code images:

from qr_list_decoder import qr_encode_text, get_best_qr_matrix, render_qr

# 1. Convert text to bytes (e.g., Version 2 QR)
data_bytes = qr_encode_text("Hi Tejas!", version=2)

# 2. Let the library calculate the ECC bytes and build the best 2D matrix
matrix, mask_used = get_best_qr_matrix(data_bytes, version=2, ecc_level='high')

# 3. Render the matrix into an image and save it!
img = render_qr(matrix, scale=10, fg=(0, 0, 0), bg=(255, 255, 255))
img.save("my_new_qr.png")

Task 4: Decode a Raw 2D Matrix

If you already extracted the binary grid yourself (or generated it) and want to bypass the image processing step:

from qr_list_decoder import decode_raw_matrix

# A 2D list or NumPy array where 1 is black and 0 is white.
my_matrix = [
    [1, 1, 1, 1, 1, 1, 1, 0, 0, 1, ...],
    [1, 0, 0, 0, 0, 0, 1, 0, 1, 1, ...],
    [1, 0, 1, 1, 1, 0, 1, 0, 0, 0, ...],
    # ... rest of the matrix rows
]

result = decode_raw_matrix(my_matrix)
if result.get('wu_success') or result.get('bm_success'):
    print("Decoded Text:", result.get('wu_text') or result.get('bm_text'))

Task 5: Byte-level Decoding

If you don't care about images or matrices, and just want to play with the underlying math:

from qr_list_decoder import rs_encode, wu_decode

# 1. Create a raw codeword
codeword = rs_encode(n=26, k=9, message=[72, 101, 108, 108, 111])

# 2. Simulate data corruption (flip random bytes)
corrupted = codeword.copy()
corrupted[2] ^= 255
corrupted[8] ^= 128
corrupted[14] ^= 42

# 3. Use Wu's algorithm to mathematically recover the original bytes!
candidates = wu_decode(n=26, k=9, received=corrupted)
print("Recovered bytes:", candidates[0])

API Reference

The library exposes the following high-level core API components. Please check the source code for more advanced mathematical helper functions.

Function Description
rs_encode(n, k, message) Encode a message into an RS(n, k) codeword
rs_syndromes(n, k, received) Compute syndromes of a received word
berlekamp_massey(syndromes) Run standard Berlekamp-Massey
wu_decode(n, k, received) Main math entry point — list-decode a corrupted codeword
decode_qr_image(img_path) Decode a QR code directly from an image file
decode_raw_matrix(matrix) Decode a 2D array of 0s and 1s
decode_folder(path) Batch process a folder of QR images

Dependencies

  • Python ≥ 3.8
  • NumPy
  • Pillow (PIL)
  • Optional: OpenCV (opencv-python) for robust perspective-unwarping on camera photos.

Optional C++ Acceleration

The package includes an optional C++ backend (wu_core) built with pybind11 that provides a massive ~20x-50x speedup on hot-path polynomial operations. It is automatically used if compiled:

pip install pybind11
python setup.py build_ext --inplace

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

list_decoder_qr-0.1.0.tar.gz (51.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

list_decoder_qr-0.1.0-cp313-cp313-win_amd64.whl (173.5 kB view details)

Uploaded CPython 3.13Windows x86-64

File details

Details for the file list_decoder_qr-0.1.0.tar.gz.

File metadata

  • Download URL: list_decoder_qr-0.1.0.tar.gz
  • Upload date:
  • Size: 51.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for list_decoder_qr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7f83648ce4442c51a3e085406cb7b59cb63d0b7f0e258e53d07b2518f79cba94
MD5 d0b0ff2842a6fbcb59f5719c997f9d6f
BLAKE2b-256 34191f5398b2608bb925e293b6622fa4c0bbbac9873929d10b9154b66659acbd

See more details on using hashes here.

File details

Details for the file list_decoder_qr-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for list_decoder_qr-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 38b3be85581afc8b164f281f4b72559bf34f06c2971f9227614fb22e08c81f06
MD5 7214d6eefdbc39eb91288eafbf476036
BLAKE2b-256 cb9c57a00414826e91ad44b1150228163ccc95496dbae24b9bff48617badd09a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page