5D_Heredero_Louis_TM2022/python/img_gen/qr_mask_gen.py

34 lines
846 B
Python
Raw Permalink Normal View History

2022-09-22 11:13:15 +00:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Generates QR Code mask figures
(C) 2022 Louis Heredero louis.heredero@edu.vs.ch
"""
import numpy as np
from PIL import Image
MASKS = [
lambda x, y: (x+y) % 2 == 0,
lambda x, y: y % 2 == 0,
lambda x, y: (x) % 3 == 0,
lambda x, y: (x+y) % 3 == 0,
lambda x, y: (y//2+x//3) % 2 == 0,
lambda x, y: ((x*y) % 2 + (x*y) % 3) == 0,
lambda x, y: ((x*y) % 2 + (x*y) % 3) % 2 == 0,
lambda x, y: ((x+y) % 2 + (x*y) % 3) % 2 == 0
]
if __name__ == '__main__':
for i, mask in enumerate(MASKS):
a = np.ones([21, 21], dtype="uint8")
for y in range(a.shape[0]):
for x in range(a.shape[1]):
if mask(x, y):
a[y, x] = 0
a *= 0xffffff
img = Image.fromarray(a)
img.save(f"qr_mask_{i}.png")