"""Lay the model's renders beside the picture, view by view (system Python with PIL): python nv_compare.py [--overlay] [--src fit|cycles] previews/compare/.png: for each view the picture's panel on the left, the render (same camera, same framing) on the right; --overlay adds a third column, the picture with the render's outline drawn over it. """ import os, sys from PIL import Image, ImageFilter, ImageChops, ImageDraw HERE = os.path.dirname(os.path.abspath(__file__)) FOLDER = os.path.dirname(HERE) args = [a for a in sys.argv[1:] if not a.startswith("--")] TAG = args[0] if args else "v01" OVER = "--overlay" in sys.argv SRC = sys.argv[sys.argv.index("--src") + 1] if "--src" in sys.argv else "fit" PANELS = {"left": (20, 20, 330, 570), "mid": (350, 10, 690, 570), "right": (670, 20, 990, 570)} K = 2 # renders are twice the picture's size ref = Image.open(os.path.join(FOLDER, "reference", "ref_user.jpg")).convert("RGB") ref2 = ref.resize((ref.width * K, ref.height * K), Image.LANCZOS) cols = [] for v, (u0, v0, u1, v1) in PANELS.items(): path = os.path.join(FOLDER, "previews", SRC, "%s_%s.png" % (TAG, v)) if not os.path.exists(path): continue box = (u0 * K, v0 * K, u1 * K, v1 * K) a = ref2.crop(box) rnd = Image.open(path).convert("RGBA").crop(box) bg = Image.new("RGBA", rnd.size, (24, 24, 26, 255)) bg.alpha_composite(rnd) row = [a, bg.convert("RGB")] if OVER: al = rnd.split()[3].point(lambda x: 255 if x > 40 else 0) edge = al.filter(ImageFilter.FIND_EDGES).filter(ImageFilter.MaxFilter(3)) ov = a.copy() red = Image.new("RGB", a.size, (255, 40, 40)) ov.paste(red, (0, 0), edge) row.append(ov) w = sum(r.width for r in row) + 10 * (len(row) - 1) im = Image.new("RGB", (w, a.height), (0, 0, 0)) x = 0 for r in row: im.paste(r, (x, 0)) x += r.width + 10 cols.append(im) os.makedirs(os.path.join(FOLDER, "previews", "compare"), exist_ok=True) im.save(os.path.join(FOLDER, "previews", "compare", "%s_%s%s.png" % (TAG, v, "_overlay" if OVER else ""))) H = sum(c.height for c in cols) + 10 * (len(cols) - 1) Wd = max(c.width for c in cols) sheet = Image.new("RGB", (Wd, H), (0, 0, 0)) y = 0 for c in cols: sheet.paste(c, (0, y)) y += c.height + 10 os.makedirs(os.path.join(FOLDER, "previews", "compare"), exist_ok=True) out = os.path.join(FOLDER, "previews", "compare", "%s%s.png" % (TAG, "_overlay" if OVER else "")) sheet.save(out) print("COMPARE OK", out, sheet.size)