Files

80 lines
3.9 KiB
Python

#!/usr/bin/env python3
"""Comparison-only Ezekiel finish-mask trial; never writes production exports."""
from pathlib import Path
import hashlib
import json
import subprocess
import sys
import numpy as np
from PIL import Image, ImageDraw, ImageFont
HERE = Path(__file__).resolve().parent
REVISION = HERE.parents[1]
REPO = next(p for p in HERE.parents if (p / "docs/card-layer-pipeline.md").is_file())
sys.path.insert(0, str(REPO / "tools/card-production"))
from finish_masks import extract_raw_ridges, RECIPE_SHA256
ART = REVISION / "source/art-master-candidate-03.png"
PANES = REVISION / "source/pane-coverage.png"
TEXT = REVISION / "source/text/text-2000.png"
OVERLAY = REPO / "artifacts/layers/uncommon/v3/exports/overlay-normal-2000.png"
BASELINE = REVISION / "high/normal/finish-mask.png"
def digest(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def save_data_map(gray, path):
rgba = gray.convert("RGBA")
rgba.putalpha(255)
rgba.save(path)
def main():
for path in (ART, PANES, TEXT, OVERLAY, BASELINE):
if not path.is_file():
raise FileNotFoundError(path)
filtered_path = HERE / "filtered-art.png"
subprocess.run(["convert", str(ART), "-kuwahara", "5x5", str(filtered_path)], check=True)
filtered = Image.open(filtered_path).convert("RGB")
assert filtered.size == (2000, 2800)
ridges = extract_raw_ridges(filtered)
Image.fromarray(ridges).save(HERE / "smoothed-ridges-2000.png")
pane = np.asarray(Image.open(PANES).convert("L"), dtype=np.float32) / 255.
overlay = np.asarray(Image.open(OVERLAY).convert("RGBA").getchannel("A"), dtype=np.float32) / 255.
text = np.asarray(Image.open(TEXT).convert("RGBA").getchannel("A"), dtype=np.float32) / 255.
active = 1 - (1 - overlay) * (1 - text)
out = np.rint(pane * (1 - ridges.astype(np.float32) / 255.) * (1 - active) * 255).astype(np.uint8)
master = Image.fromarray(out)
for width in (2000, 1000, 500):
image = master if width == 2000 else master.resize((width, width * 7 // 5), Image.Resampling.BILINEAR)
save_data_map(image, HERE / f"smoothed-normal-finish-{width}.png")
ridge_small = Image.fromarray(ridges).resize((500, 700), Image.Resampling.BILINEAR)
ridge_small.save(HERE / "smoothed-ridges-500.png")
baseline = Image.open(BASELINE).convert("L").resize((500, 700), Image.Resampling.BILINEAR)
candidate = master.resize((500, 700), Image.Resampling.BILINEAR)
art = Image.open(ART).convert("RGB").resize((500, 700), Image.Resampling.LANCZOS)
sheet = Image.new("RGB", (1520, 750), "#11161c")
draw = ImageDraw.Draw(sheet)
font = ImageFont.truetype(str(REPO / "fonts/P052-Bold.otf"), 23)
for index, (label, view) in enumerate((("Artwork", art), ("Current mask", baseline), ("Smoothed trial", candidate))):
x = 10 + index * 505
draw.text((x + 6, 8), label, fill="#f4ead4", font=font)
sheet.paste(view.convert("RGB"), (x, 40))
sheet.save(HERE / "comparison-500.png")
report = {
"status": "experimental; not production-selected",
"method": "ImageMagick Kuwahara 5x5 edge-preserving smoothing of fitted art, then unchanged raw-ridges-v1 ridge extractor; original pane weights and active Normal overlay/text alpha retained",
"source": {"artSHA256": digest(ART), "paneSHA256": digest(PANES), "textSHA256": digest(TEXT), "overlaySHA256": digest(OVERLAY)},
"baselineSHA256": digest(BASELINE), "approvedRecipeSHA256": RECIPE_SHA256,
"outputs": {name: digest(HERE / name) for name in ("smoothed-ridges-2000.png", "smoothed-normal-finish-2000.png", "comparison-500.png")},
"warning": "This is not the approved raw-ridges-v1 production path and has not had moving-light review. Pane weights are loaded from the prior 8-bit diagnostic for a fast comparison.",
}
(HERE / "trial.json").write_text(json.dumps(report, indent=2) + "\n")
if __name__ == "__main__":
main()