#!/usr/bin/env python3 """Write the pinned source photograph the int_hyper integer-codec vectors (the pretrained mbt2018_mean, exported to integers) are regenerated from. python tools/wai_sota_source_image.py The image is a 256x256 crop of `skimage.data.astronaut()` — a photograph that ships inside the scikit-image wheel and is documented there as public domain (NASA; "No known copyright restrictions, released into the public domain"). It is pinned by the SHA-256 of the cropped RGB bytes, so a different image can never be substituted silently: a mismatch is an error, not a warning. A real photograph, rather than a synthetic pattern, is what makes the quality check meaningful: the integer decode is checked against the same model's float decode on natural-image content, and must cost at most 1 dB there (tests/int_hyper_synth.rs). That bar is relative, on this one image; it says nothing about how the model compares with other codecs, or about other images. The 42.6 dB development figure for this codec was taken on a different photograph that is not in this repository. """ import hashlib import sys import numpy as np from PIL import Image from skimage import data CROP = (slice(64, 320), slice(128, 384)) # rows, cols of the 512x512 original SHA256 = "29cb3aee1a55f9585474d056b65edb0aaebbb80371ba200e85030d63665c19d6" def main(out: str) -> int: rgb = np.ascontiguousarray(data.astronaut()[CROP]) got = hashlib.sha256(rgb.tobytes()).hexdigest() if rgb.shape != (256, 256, 3) or got != SHA256: print(f"error: source crop is {rgb.shape} sha256 {got}; pinned (256, 256, 3) {SHA256}. " "The scikit-image sample changed — pin the new hash only after reviewing the image.", file=sys.stderr) return 1 Image.fromarray(rgb).save(out) print(f"wrote {out}: 256x256 RGB, sha256(rgb) {got}") return 0 if __name__ == "__main__": if len(sys.argv) != 2: print(__doc__, file=sys.stderr) raise SystemExit(2) raise SystemExit(main(sys.argv[1]))