Milestone 5 of 8

Measure coverage and reconstruct honestly

Accumulate valid patch positions and values safely, prove source-times-coverage, reconstruct exactly when complete, and list uncovered coordinates when it is not.

Coverage tells you which source pixels the grid copied and how many times. It also tells you when a reconstruction is impossible. Do not hide uncovered coordinates behind a filled image.

Goal

Build coverage and wide-value accumulators, prove the source-times-coverage invariant, reconstruct exactly when every pixel is covered, and report incomplete cases with their uncovered coordinates.

Coverage contract

For an image of shape (H, W, C), create an integer coverage map of shape (H, W). Add one for every valid patch position mapped to a source pixel. Separately accumulate valid patch values in a wide integer array of shape (H, W, C).

For every covered source pixel, prove:

accumulated_values == source_values * coverage_count

If every coverage value is positive, divide exactly by coverage and require an exact uint8 reconstruction. If any coverage value is zero, record an incomplete reconstruction and list uncovered coordinates. Do not fill them and claim success.

Deliverables

Implement coverage and reconstruction in src/coverage.py. Save per-image coverage arrays, wide accumulators or their checks, source-times-coverage records, reconstruction arrays where complete, equality records, and uncovered-coordinate records where incomplete.

Checks

Check divisible complete grids, non-divisible drop grids with gaps, non-divisible pad grids, smaller-than-patch images, and overlapping patches. Check one-pixel and constant/extreme-value images. Verify every copied value, coverage count, accumulator, and reconstructed pixel.

Deliberately remove one valid patch and make coverage identify the affected coordinates. Deliberately alter one pixel and make the source-times-coverage check fail. Confirm wide accumulation prevents integer overflow and source and patch arrays are not mutated.

Workspace

Keep coverage maps, accumulators, reconstruction, and uncovered-coordinate reporting in src/coverage.py. Group selection and batching belong next.

Hints

HintCount before dividing
Overlapping patches may copy one pixel several times. Add all copies first, then divide by the exact count.
HintZero has a location
An incomplete reconstruction is not just a boolean. Save the row and column coordinates where coverage is zero.

Review

Choose one overlapped pixel and show its source value, coverage count, and accumulated value. What can you conclude when coverage is zero? Why would filling that pixel with a pad value misrepresent reconstruction?

How to check your work

Checks compare maps, accumulators, equality records, and uncovered coordinates with the fixtures. Exact reconstruction is a statement about this source and grid, not about information recovery in general.

LLM PrimerMeasure coverage and reconstruct honestlyhttps://llmprimer.com/python/projects/build-an-image-patch-dataset/measure-coverage-and-reconstruct-honestly© 2026 LLM Primer