29 lines
939 B
Python
29 lines
939 B
Python
"""Compare two directories of same-sized PNG frames."""
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
import numpy as np
|
|
from PIL import Image
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("a", type=Path)
|
|
parser.add_argument("b", type=Path)
|
|
parser.add_argument("--frames", type=int, required=True)
|
|
args = parser.parse_args()
|
|
|
|
rows = []
|
|
for index in range(args.frames):
|
|
a = np.asarray(Image.open(args.a / f"frame_{index:04d}.png")).astype(np.int16)
|
|
b = np.asarray(Image.open(args.b / f"frame_{index:04d}.png")).astype(np.int16)
|
|
diff = np.abs(a - b)
|
|
rows.append((index, int(diff.max()), float(diff.mean()), float(np.percentile(diff, 99))))
|
|
|
|
print({
|
|
"frames": args.frames,
|
|
"max": max(row[1] for row in rows),
|
|
"mean": sum(row[2] for row in rows) / len(rows),
|
|
"top_max": sorted(rows, key=lambda row: row[1], reverse=True)[:10],
|
|
"top_mean": sorted(rows, key=lambda row: row[2], reverse=True)[:10],
|
|
})
|