Milestone 7 of 8

Save, reload, inspect, and replay

Save supported PNG stages without overwrite, reload exact arrays, conserve per-channel counts, read artifacts back, and reproduce them in a separate replay.

The picture is not the only evidence. Save the exact arrays, checks, and identities needed to show that a later reader sees the same pixels.

Goal

Save transformation stages as PNG files, verify them numerically, reload them through the same array contract, inspect selected pixels and counts, and replay the complete plan in a separate output tree.

Save and reload contract

Save grayscale arrays as mode L after removing only the toolkit's explicit length-one channel axis. Save three-channel arrays as mode RGB. Reload each PNG through the same loader and require exact shape, dtype, and pixel equality. Preserve source files and refuse silent output overwrite.

For each full-size stage, save shape, dtype, minimum, maximum, per-channel sum, and a 256-bin per-channel value-count table. Every count must sum to height × width.

Deliverables

Extend src/verify.py, src/report.py, and src/main.py to produce:

  • PNG stage files and exact reload-equality records;
  • stage_records.jsonl, pixel_checks.csv, per-channel summaries, and value-count tables;
  • source/stage comparison, selected-pixel, and per-channel count figures with exact plot data;
  • output/image_toolkit_manifest.json; and
  • a replay agreement or mismatch record under output/replay/.

The manifest records source, plan, configuration, artifact, and implementation identities. Replay must not overwrite the original output.

Checks

Read every artifact back and check schemas, shapes, dtypes, ranges, pixels, sums, value-count conservation, stage digests, and identities. Replay from saved source and plan into a distinct directory and compare arrays, PNG reload records, tables, figures, and stage records.

Deliberately change one source digest, plan argument, operation implementation identity, or saved PNG. Report the first mismatch while leaving original output unchanged. Check one-pixel, grayscale, RGB, extreme, and transformed fixtures.

Workspace

Keep original artifacts under output/ and replay artifacts under output/replay/. Keep the manifest and toolkit card at stable project paths.

Hints

HintPicture and pixels agree together
A displayed PNG can look right while its dtype or mode is wrong. Require exact reload equality as well as selected visual checks.
HintCounts have a denominator
A per-channel value-count table has height × width pixel positions. Check that denominator before interpreting the distribution.

Review

Open one original and replayed stage and compare a selected pixel, shape, and value-count row. What does exact equality establish for this source and plan? What does it not establish about perceptual quality or model performance?

How to check your work

Checks compare manifest fields, PNG mode, array equality, numerical tables, figures, and replay output with the fixtures. A mismatch remains visible instead of being repaired by a silent overwrite.