# Spearfish: lays the renders of sf_views.py over the blueprint's panels (plain Python + Pillow, run from the shell). # Writes previews/compare/cmp_.png: the blueprint in grey, the model's outline (from the render's alpha) in red, # the model's shading at 35 % between; and cmp_all.png with every panel. import os, sys from PIL import Image, ImageChops, ImageFilter, ImageOps HERE = os.path.dirname(os.path.abspath(__file__)) D = os.path.join(os.path.dirname(HERE), "previews", "compare") BP = Image.open(os.path.join(os.path.dirname(HERE), "reference", "user_blueprint.webp")).convert("RGB") BOX = {"top": (468, 32, 1168, 282), "side": (468, 290, 1168, 470), "under": (468, 470, 1168, 680), "front": (1175, 95, 1475, 265), "rear": (1175, 370, 1475, 525)} K = 2 tiles = [] for name, b in BOX.items(): rp = os.path.join(D, "r_%s.png" % name) if not os.path.exists(rp): continue r = Image.open(rp).convert("RGBA") bp = BP.crop(b).resize((r.width, r.height), Image.LANCZOS) base = ImageOps.grayscale(bp).convert("RGB") shade = Image.blend(base, r.convert("RGB"), 0.35) a = r.split()[3].point(lambda v: 255 if v > 128 else 0) base = Image.composite(shade, base, a) edge = a.filter(ImageFilter.FIND_EDGES).point(lambda v: 255 if v > 60 else 0).filter(ImageFilter.MaxFilter(3)) red = Image.new("RGB", r.size, (230, 20, 20)) out = Image.composite(red, base, edge) out.save(os.path.join(D, "cmp_%s.png" % name)) tiles.append(out) if tiles: W = max(t.width for t in tiles); H = sum(t.height for t in tiles) sheet = Image.new("RGB", (W, H), "white"); y = 0 for t in tiles: sheet.paste(t, (0, y)); y += t.height sheet.save(os.path.join(D, "cmp_all.png")) print("ok", len(tiles))