WeChall - Rauschen

Challenge

Rauschen

Your older brother grew up in the 90'ies... he showed you a picture with a hidden solution, but it looks like rauschen.

哥哥在 90 年代长大,给出一张带有隐藏 solution、但看起来像 rauschen(噪声)的图片。

Analysis

90 年代流行的 Magic Eye / autostereogram(随机点立体图)利用水平重复纹理隐藏内容。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from pathlib import Path

import numpy as np
from PIL import Image

source = Path("/tmp/rauschen.png")
output = Path("/tmp/rauschen-period-120.png")
img = np.asarray(Image.open(source).convert("RGB"))
gray = img.astype(float).mean(axis=2)
gray -= gray.mean(axis=1, keepdims=True)

scores = []
for shift in range(1, 501):
left = gray[:, :-shift]
right = gray[:, shift:]
scores.append((shift, np.mean(left * right)))

print(sorted(scores, key=lambda x: x[1], reverse=True)[:5])
period = max(scores, key=lambda x: x[1] if x[0] >= 20 else -np.inf)[0]
print(f"selected period: {period}")

# Pixels that differ from the previous repeated tile form the hidden text.
same = np.all(img[:, period:] == img[:, :-period], axis=2)
visible = np.where(same, 255, 0).astype(np.uint8)
canvas = np.full(img.shape[:2], 255, dtype=np.uint8)
canvas[:, period:] = visible
Image.fromarray(canvas).save(output)
print(f"wrote: {output}")
STEREO