depthmap's picture
Upload 13 files
d4c3536 verified
Raw History Blame Contribute Delete
1.25 kB
#!/usr/bin/env python3
"""Re-count unique gray values in the three depth-map PNGs."""
from pathlib import Path
from PIL import Image
import struct
ROOT = Path(__file__).resolve().parent
def png_bit_depth(path: Path) -> int:
data = path.read_bytes()
if data[:8] != b"\x89PNG\r\n\x1a\n":
raise ValueError(f"{path} is not a PNG")
return data[24]
def summarize(path: Path) -> None:
im = Image.open(path)
values = list(im.getdata())
if values and isinstance(values[0], tuple):
raise SystemExit(f"{path.name}: expected a grayscale depth map, got mode {im.mode}")
unique = set(values)
multiples = all(v % 257 == 0 for v in unique)
print(f"{path.name}")
print(f" PNG header bit depth: {png_bit_depth(path)}")
print(f" Pillow mode: {im.mode}")
print(f" size: {im.size[0]}x{im.size[1]}")
print(f" unique values: {len(unique)}")
print(f" min / max: {min(unique)} / {max(unique)}")
print(f" all multiples of 257: {multiples}")
print()
if __name__ == "__main__":
for name in (
"lion-depth-16bit.png",
"lion-depth-8bit.png",
"lion-depth-8bit-upscaled-to-16bit.png",
):
summarize(ROOT / name)