BurningTimesAi/공유/기획/FirstRising/맵/tools/tile_check.py

34 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
# 텍스처가 이음매 없이 이어지는지 본다 — 2×2 로 이어 붙인 그림과, 가장자리의 밝기 차이(이음매 점수)를 낸다.
# python tile_check.py <결과 이름> <경로> [<경로> ...]
import os, sys
import numpy as np
from PIL import Image, ImageDraw
Image.MAX_IMAGE_PIXELS = None
ROOT = "C:/BurningTimes/FirstRising/"
SP = os.path.dirname(os.path.abspath(__file__))
out, paths = sys.argv[1], sys.argv[2:]
cell = 256
cols = 4
rows = (len(paths) + cols - 1) // cols
sheet = Image.new("RGB", (cell * cols, (cell + 20) * rows), (20, 20, 20))
d = ImageDraw.Draw(sheet)
for n, p in enumerate(paths):
im = Image.open(ROOT + p).convert("RGB")
a = np.asarray(im).astype(np.float32)
# 이음매 점수: 맞닿는 가장자리(왼쪽 끝 ↔ 오른쪽 끝, 위 ↔ 아래)의 차이 ÷ 그림 안쪽 이웃 픽셀의 평균 차이
inner = (np.abs(a[:, 1:] - a[:, :-1]).mean() + np.abs(a[1:, :] - a[:-1, :]).mean()) * 0.5
seam = (np.abs(a[:, 0] - a[:, -1]).mean() + np.abs(a[0, :] - a[-1, :]).mean()) * 0.5
# 가장자리 한 줄이 안쪽보다 밝거나 어두운가(테두리 선)
border = (a[0, :].mean() + a[-1, :].mean() + a[:, 0].mean() + a[:, -1].mean()) / 4.0 - a[8:-8, 8:-8].mean()
print("%-46s %4dx%-4d 이음매 %.2f배 테두리 밝기 차 %+.1f" % (os.path.basename(p), im.size[0], im.size[1], seam / max(1e-3, inner), border))
half = im.resize((cell // 2, cell // 2), Image.LANCZOS)
x, y = (n % cols) * cell, (n // cols) * (cell + 20)
for i in range(2):
for j in range(2):
sheet.paste(half, (x + i * cell // 2, y + 20 + j * cell // 2))
d.text((x + 3, y + 4), "%d %s" % (n, os.path.basename(p)[:30]), fill=(255, 230, 150))
sheet.save(os.path.join(SP, "cap", out + ".png"))
print("saved", out)