values = np.unique(mask) if not np.array_equal(values, np.array([0, 255], dtype=np.uint8)): raise SystemExit(f"expected a two-value mask, got: {values.tolist()}")