• **the two facts it exploits**:
1. **coherence** — adjacent output patches usually map to **adjacent** source patches, so **one good offset is good for its neighbors.**
2. **the birthday-paradox / law of large numbers** — over a whole image **some** patches get a good match by **random guessing**; you just need to **spread** the lucky hits.
• **the algorithm — three moves** [`fig-patchmatch-three-steps`]:
1. **random initialization**: every pixel gets a **random** offset. Mostly bad — a few good.
2. **propagation**: scan (alternating raster order each iteration); for $p$, also **try the offsets its scanned neighbors used** (shifted by one) → good offsets **flood-fill** across coherent regions.
3. **random search**: refine the best by testing random offsets in an **exponentially shrinking window** ($w\cdot\alpha^i$) — large jumps escape local optima, small jumps fine-tune.
• iterate 2–5 times → a clean NNF in **milliseconds**, orders of magnitude faster than exhaustive search.
• **pseudocode block** (in the draft): the init-then-sweep loop — `init f randomly; repeat passes (alternating scan): for each p: propagate from neighbors, then random-search in a shrinking window; return f`.
• **why it converges fast**: propagation makes a single lucky match **infect** an entire coherent region in one scan; random search avoids getting stuck. *Randomness + coherence beats brute force.*
• **generalized PatchMatch** (Barnes et al. 2010): k nearest neighbors + **rotations/scales** — needed for matching transformed content (style transfer, denoising).
• 💡 **why it sits next to Shift-Map**: PatchMatch answers "where does each patch come from?" **heuristically and fast**; Shift-Map answers the **same** question **optimally and slower** (next).