#! /usr/bin/python3 # Last edited on 2025-08-20 07:13:36 by stolfi # Reads a TIFF file produced by the multispectral scanning team. # Writes to stdout the samples as a plain (ASCII, not binary) PGM file. import tifffile as tiff import sys def main(): fname = sys.argv[1]; a = tiff.imread(fname) assert len(a.shape) == 2, f"should be monchrome, shape = {a.shape}" rows, cols = a.shape; assert a.dtype == 'uint16', f"bad dtype {a.dtype}" sys.stdout.write("P2\n") sys.stdout.write(f"{cols} {rows}\n") sys.stdout.write("65535\n") for row in range(rows): for col in range(cols): sys.stdout.write(f" {a[row,col]}\n") sys.stdout.flush() return 0 main()