From 5fb9020f79056ed20419248411643a1bd3ae73c7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 27 Apr 2026 18:33:40 +0200 Subject: [PATCH] stereogramer --- usr/bin/stereogramer | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 usr/bin/stereogramer diff --git a/usr/bin/stereogramer b/usr/bin/stereogramer new file mode 100755 index 0000000..a137321 --- /dev/null +++ b/usr/bin/stereogramer @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +import sys +import numpy as np +from PIL import Image + +def depth_map(w, h): + # simple demo: circular bump + y, x = np.ogrid[:h, :w] + cx, cy = w // 2, h // 2 + r = min(w, h) // 3 + d = ((x - cx)**2 + (y - cy)**2) <= r*r + return d.astype(np.float32) + +def stereogram(depth, pattern_w=64, max_shift=32): + h, w = depth.shape + img = np.random.randint(0, 256, (h, w), dtype=np.uint8) + + for y in range(h): + for x in range(pattern_w, w): + z = depth[y, x] + shift = int(z * max_shift) + src = x - pattern_w + shift + if src >= 0: + img[y, x] = img[y, src] + return img + +def main(argc, argv): + w = int(argv[1]) if argc > 1 else 600 + h = int(argv[2]) if argc > 2 else 400 + out = argv[3] if argc > 3 else "stereogram.png" + + d = depth_map(w, h) + s = stereogram(d) + + Image.fromarray(s).save(out) + print(out) + +if __name__ == "__main__": + main(len(sys.argv), sys.argv)