Update card production workflow and workspaces
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Comparison-only relaxed dark-ridge detector for Ezekiel's glass seams."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFilter, 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 _shift, _smooth
|
||||
|
||||
FILTERED = HERE / "filtered-art.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"
|
||||
ART = REVISION / "source/art-master-candidate-03.png"
|
||||
|
||||
|
||||
def digest(path):
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def detect(art):
|
||||
gray = np.asarray(art.convert("RGB").filter(ImageFilter.GaussianBlur(1.2)).convert("L"), dtype=np.float32) / 255.
|
||||
darkness = 1 - _smooth(0.24, 0.54, gray)
|
||||
out = np.zeros_like(gray)
|
||||
for index in range(8):
|
||||
angle = math.pi * index / 8
|
||||
for radius in (2, 4, 8, 14):
|
||||
dx, dy = round(math.cos(angle) * radius), round(math.sin(angle) * radius)
|
||||
shoulders = np.minimum(_shift(gray, dx, dy), _shift(gray, -dx, -dy))
|
||||
ridge = _smooth(0.012, 0.055, shoulders - gray) * darkness
|
||||
np.maximum(out, ridge, out=out)
|
||||
return np.rint(out * 255).astype(np.uint8)
|
||||
|
||||
|
||||
def main():
|
||||
for path in (FILTERED, PANES, TEXT, OVERLAY, BASELINE, ART):
|
||||
if not path.is_file():
|
||||
raise FileNotFoundError(path)
|
||||
ridges = detect(Image.open(FILTERED))
|
||||
Image.fromarray(ridges).save(HERE / "relaxed-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)
|
||||
rgba = image.convert("RGBA")
|
||||
rgba.putalpha(255)
|
||||
rgba.save(HERE / f"relaxed-normal-finish-{width}.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), ("Relaxed dark-ridge 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-relaxed-500.png")
|
||||
report = {
|
||||
"status": "experimental; not production-selected",
|
||||
"method": "Kuwahara 5x5 art, then 1.2px blurred luminance; eight-orientation opposed shoulders at 2/4/8/14px; contrast smoothstep .012-.055; darkness smoothstep .24-.54; original pane diagnostic and active Normal overlay/text alpha retained",
|
||||
"sourceSHA256": {str(path.relative_to(REPO)): digest(path) for path in (ART, PANES, TEXT, OVERLAY, FILTERED)},
|
||||
"baselineSHA256": digest(BASELINE),
|
||||
"outputs": {name: digest(HERE / name) for name in ("relaxed-ridges-2000.png", "relaxed-normal-finish-2000.png", "comparison-relaxed-500.png")},
|
||||
"warning": "This changes approved extraction parameters and is only a separate visual trial. No production or runtime files have been replaced.",
|
||||
}
|
||||
(HERE / "relaxed-trial.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user