Manuscript Offprint
arXiv:2610.13176Fix the Match, Not the Solver: STITCH -- a Self-Supervised Compatibility Measure for Eroded Visual Puzzles
Abstract
Unlike the clean and pixel-aligned complete pieces of standard jigsaw benchmarks, real-world puzzle fragments lose their boundary regions to erosion, destroying the signal that classical compatibility measures (CMs) rely on. We first re-establish, via oracle experiments, that the CM, not the solver, is the performance bottleneck: with a perfect CM, even a simple greedy solver achieves perfect reconstruction. This motivates STITCH, a self-supervised CM that sidesteps missing boundaries by comparing frozen ViT patch tokens from piece interiors via a lightweight cross-attention head (~249 K trainable parameters), trained without manual annotation. Plugged into unchanged compatibility-based solvers, STITCH reaches .992/.954 Abs/Perf on JPwLEG-5 (+.629 Perf over the best prior method), nearly saturating the benchmark. On a new ImageNet 7×7 benchmark, it outperforms all alternatives, including inpaint-then-match pipelines built on modern generative models. Importantly, performance remains robust across erosion levels and generalizes to puzzles with over 40% missing pieces without retraining. Trained on the recent GAP datasets of irregular, heavily eroded fragments, the same CM recipe enables compatibility-based solvers to surpass recent learning-based solvers on GAP-3 and GAP-5. Since this leap in performance is achieved by a pluggable CM module, the takeaway is clear: fix the match, not the solver.
1 Introduction
When humans solve jigsaw puzzles, they often match pieces by visual information along shared boundaries (Fissler et al. 2018), and algorithmic reassembly has long adopted the same principle for applications such as reconstructing archaeological finds, shredded documents, and deteriorated photographs (Tsesmelis et al. 2024; Richter et al. 2012; Sizikova and Funkhouser 2017). Two solver families dominate. The first are compatibility-based solvers, which take a compatibility measure (CM) as a modular input and employ of various ways (greedy, genetic, LP-based, relaxation labeling (Pomeranz, Shemesh, and Ben-Shahar 2011; Sholomon, David, and Netanyahu 2013; Yu, Russell, and Agapito 2016; Vardi et al. 2023)) to search over the space of placements. The second family includes learning-based solvers (Paumard, Picard, and Tabia 2020; Kim, Cho, and Nam 2025; Liu et al. 2024; Scarpellini et al. 2024; Elkin, Shahar, and Ben-Shahar 2025), that learn matching and placements jointly. Evaluation of all solvers has always relied on various benchmarks, which over time have shifted steadily toward greater realism, from clean, pixel-aligned complete tiles to puzzles with eroded boundaries (Song et al. 2023a) and, most recently, irregular archaeology-inspired fragments (Shahar, Elkin, and Ben-Shahar 2026).
In this work, we further push forward the dominant line of research on square jigsaw puzzles that are based on partitioning an image into an grid of square pieces that are then shuffled, where the goal is correct reassembly of the original image. When considering eroded puzzles with erosion level e, the puzzle generation process also strips the outermost e pixels from every side of every piece. Naturally, larger e degrades the boundary signals and eventually destroys them altogether. We make the common assumption that piece orientations are known, but unlike recent works, we also evaluate our solutions on the harder, unknown-orientation case (Gallagher 2012). Moreover, employing the recent GAP datasets (Shahar, Elkin, and Ben-Shahar 2026), we consider the even more challenging case of square puzzles with irregular fragments whose shapes are learned from real archaeological ones.
A CM is a function that scores a pair of pieces and their relative spatial relation by their likelihood of being direct neighbors (formalized in Sec. 3). CMs are a key explicit component in compatibility-based solvers, and are implicit in learning-based solvers. We say the CM is the bottleneck of a puzzle-solving pipeline if replacing it with a perfect compatibility oracle, while keeping the solver fixed, suffices for near-perfect reconstruction.
For over a decade, the community’s response to erosion has largely been better solvers (Sholomon, David, and Netanyahu 2013; Yu, Russell, and Agapito 2016; Paumard, Picard, and Tabia 2020). Yet solvers still perform far worse on eroded benchmarks than on clean-edge ones, and learning-based solvers entangle matching with placement, obscuring where their gains come from. Learned CMs do improve compatibility-based solvers under mild erosion (Bridger, Danon, and Tal 2020; Rika et al. 2022b,a), but they rely on boundary strips and degrade quickly as gaps widen. Crucially, no prior work attempted to isolate the CM’s contribution from the solving algorithm itself (in particular, by ablating the CM and replacing it with a perfect "oracle" CM). At the same time, no single CM, including recent measures for irregular fragments (Shahar, Elkin, and Ben-Shahar
2025), has been evaluated simultaneously under challenging conditions like deep erosion, missing pieces, and/or irregular geometry. These gaps thus leave open a very fundamental question: is the limiting factor the solving itself, or is it the compatibility signal that drives it?
We provide a decisive answer. Replacing a solver’s CM with an oracle compatibility (1 for true neighbors, 0 otherwise) yields perfect reconstructions for every solver we test on a standard eroded benchmark, even the simplest greedy strategy (Fig. 4). Failures on eroded puzzles are thus failures of matching, not search. Rather than designing another solver, we therefore seek to fix the match.
Our contributions are:
-
An oracle analysis establishing the CM, not the solver, as the performance bottleneck on eroded puzzles.
-
Introduction of STITCH (Self-supervised Token InTerior Cross-attention Head), a very light (~249 K-parameter) cross-attention head.
-
Introduction of ImageNet , a new benchmark of larger, more combinatorially challenging eroded puzzles, spanning erosion levels px and over 40% of pieces missing, settings that break all current learning-based solvers.
-
SOTA performance of STITCH when plugged into every compatibility-based solver we tested. It nearly saturates JPwLEG-3/5, it outperforms all alternative CMs on ImageNet (including inpaint-then-match pipelines), and it generalizes to over 40% missing pieces without retraining.
-
Evidence that STITCH’s concept extends to fragments with strongly irregular erosion. Trained on GAP (Shahar, Elkin, and Ben-Shahar 2026), STITCH allows “classical” compatibility-based solvers to surpass recent deep learning-based ones (including unknown-orientation scenarios).
-
A conceptual shift: from ever more complex solvers to better compatibility signals.
Learning-based solvers. Learning-based solvers instead learn matching and placement jointly, spanning CNN classifiers with shortest-path search (Paumard, Picard, and Tabia 2020), reinforcement and evolutionary learning (Song et al. 2023a,b, 2025b,a), adversarial and generative models (Li et al. 2021; Talon, Del Bue, and James 2022, 2025; Liu et al. 2024), ViT-based prediction (Heck, Lermé, and Le Hégarat-Mascle 2025; Kim, Cho, and Nam 2025), Seq2Seq modeling (Elkin, Shahar, and Ben-Shahar 2025), vision-language alignment (Xu and Liu 2025), and flow matching over irregular fragments (Shahar, Elkin, and Ben-Shahar 2026). Despite this diversity, such systems are not decomposable: it is difficult to isolate whether gains come from better matching or better search. Our oracle analysis (Fig. 4) cuts through this ambiguity, and our modular design enables exactly the controlled comparison these methods cannot offer.
Compatibility functions. Handcrafted CMs (SSD (Cho, Avidan, and Freeman 2010), (Paikin and Tal 2015), PBC (Pomeranz, Shemesh, and Ben-Shahar 2011), MGC (Gallagher 2012), and newer border and hybrid measures (Guerroui and Séridi 2018; Shih, Lu, and Ma 2019)) compare strips of boundary pixels and excel on clean edges but degrade sharply under erosion (Sec. 5). Cho, Avidan, and Freeman (2010) compares such measures by neighbor classification, though never within full solver pipelines. Learned CMs push further: DNN-Buddies (Sholomon, David, and Netanyahu 2016) learns edge compatibility for a compatibility-based solver, while Bridger, Danon, and Tal (2020) and JiGAN (Khoroshiltseva et al. 2022) inpaint the eroded gap and score its plausibility. TEN (Rika et al. 2022b) learns edge-specific embeddings from whole-piece content, and Edge2Vec (Rika et al. 2022a) learns boundary embeddings tolerating 1-px erosion. Closest to our setting, Shahar, Elkin, and Ben-Shahar (2025) propose a CM for arbitrarily irregular fragments, yet within a single solving framework and without missing pieces. All of the above rely on boundary or near-boundary signals, which are precisely what erosion removes first, so they degrade quickly as gaps widen (Fig. 5). STITCH instead discards boundaries entirely, reasoning via cross-attention over frozen ViT interior tokens, a fundamentally different inductive bias that may explain its robustness.
Complexity and irregular fragments. Square puzzle solving is NP-complete (Demaine and Demaine 2007), so no search can escape a poor compatibility signal, another lens on our oracle finding (see Sec. 5.2). Attempting to provide better realism and applicability, irregular-fragment work spans non-square rectangular pieces (Gur and Ben-Shahar 2017), polygonal puzzles (Harel and Ben-Shahar 2021; Harel, Shahar, and Ben-Shahar 2024), wall paintings (Sizikova and Funkhouser 2017), and archaeological benchmarks (Tsesmelis et al. 2024) (see the survey of Yilmaz and Nabiyev (2023)). The GAP datasets (Shahar, Elkin, and Ben-Shahar 2026) bring heavily eroded, irregularly shaped fragments to grid puzzles, but their solver, PuzzleFlow, abandons pairwise compatibility for holistic reasoning. We show the paradigm needs fixing, not abandoning. Indeed, trained on GAP, STITCH boosts compatibility-based solvers past PuzzleFlow (Sec. 5).
Pretrained visual backbones. We build on frozen patch-level features, which encode interior content unaffected by boundary removal. MAE (He et al. 2022) reconstructs masked patches, yielding tokens rich in local texture, whereas backbones pretrained with classification (Dosovitskiy et al. 2020), self-distillation (Oquab et al. 2024), or language-contrastive (Radford et al. 2021) objectives favor semantics over fine spatial detail, and convolutional baselines (Liu et al. 2022; He et al. 2016) complete our six-backbone comparison (Fig. 8). And while jigsaw puzzles were used as a motivational task for studying representation learning (Noroozi and Favaro 2016; Carlucci et al. 2019), here we invert this line of thinking and use pretrained features to solve eroded jigsaws.
3 Problem Setup and Datasets
Puzzles and erosion. A square jigsaw puzzle is defined by a source image partitioned into an grid of non-overlapping pieces , each having original size pixels. These pieces are then shuffled and must be re-assembled computationally. In an eroded puzzle, pixels are removed from every side of every piece, reducing it to pixels and creating a -pixel gap between true neighbors. To follow the terminology used by the different benchmarks, on ImageNet we report erosion as the level per side, while on JPwLEG-3/5 the presentation is based on the resulting -pixel gap. Our main experiments follow the standard regime of known grid size and piece orientation. However, we do evaluate robustness for both missing pieces and unknown orientations (Unknown-orientation results are in the Supp).
Compatibility functions and solvers. A CM takes an anchor , a candidate , and a spatial relation (Right, Down, Left, Up), and returns a score that orders candidates by their likelihood of being direct neighbors. The polarity of this ordering varies across measures: dissimilarity-based CMs such as SSD, , PBC, MGC, and Edge2Vec assign lower scores to better matches, whereas STITCH (Sec. 4.3) produces similarity scores in via cosine similarity, where higher is better. A solver utilizes the full CM score matrix and produces an assignment of pieces to grid positions. When the solver treats the CM as a replaceable black-box module, any other CM, including STITCH, can be plugged in unchanged, modulo a sign convention.
Datasets. We use several different datasets in our study. JPwLEG-3 and JPwLEG-5 (Song et al. 2023a) contain puzzles with 48 px gaps and puzzles with 12 px gaps, respectively, built from MET artwork images, with random positional jitter of px that imitates real-world misalignment. ImageNet is our own new benchmark of larger, more combinatorially challenging puzzles generated from randomly sampled ImageNet images (Russakovsky et al. 2015), divided into a pieces of px, with no image overlap with JPwLEG. It is released with erosion levels px and missing pieces, over which we sweep in Sec. 5.4. GAP-3 and GAP-5 (Shahar, Elkin, and Ben-Shahar 2026) extend the same grid topologies ( and ) to irregular, heavily eroded fragments whose shapes are learned from real archae-

Figure 1: Architecture overview. Both pieces are canonicalized so facing edges align to a fixed position (Sec. 4.2). A frozen MAE ViT-B/16 extracts patch tokens (precomputed). Tokens are projected (768 → 64), passed through bidirectional cross-attention layers (4 heads), and scored via mean tokenwise cosine similarity ( ). Only K parameters are trained.
ological fragment statistics over MET images. Split sizes and per-benchmark statistics are in the Supp.
Metrics. We employ and report three metrics. Top-1 measures CM quality (independently of any solver). For each query of an anchor piece and relation , we find the best matching piece according to the CM. The query scores 1 if that match is the correct neighboring piece and 0 otherwise. Top-1 averages these scores over all queries in the test set (Cho, Avidan, and Freeman 2010).
At the solver level, Abs is the fraction of pieces placed in their correct grid position (Cho, Avidan, and Freeman 2010), and Perf is the fraction of puzzles solved perfectly (Pomeranz, Shemesh, and Ben-Shahar 2011).
4 STITCH
STITCH is a two-stage pipeline (Fig. 1): a frozen self-supervised ViT extracts patch-level features, and a lightweight cross-attention head compares the two feature maps to produce a compatibility score. Only the head is trained. The following subsections describe each component.
4.1 Backbone Feature Extraction
Every piece, whatever its size after erosion, is resized to px before the backbone, so a frozen ViT with patch size yields a fixed token map with and , identically across all benchmarks and erosion levels. Positional embeddings are bicubically interpolated from the backbone's pretraining resolution to this grid. Crucially, these tokens describe the piece interior, the region erosion leaves untouched, rather than its inaccessible eroded boundary. Features are precomputed and cached, so no ViT forward pass occurs at training time. We use MAE (He et al. 2022), which consistently outperforms all alternative backbones (Fig. 8).
4.2 Canonicalization
The CM must score candidate neighbors in all four directions . Rather than learning four separate comparators or conditioning the head on d, both of which fragment the training signal, we canonicalize the pieces: each piece is

Figure 2: Canonicalization by relative position. A piece (center) is transformed according to where it sits relative to its partner: left – identity; right – horizontal flip; above – transpose; below – 90° CW rotation. Each transform brings the piece’s facing edge to its rightmost column.
transformed by a single deterministic rule that depends only on its position relative to its partner, so that its edge abutting the anchor piece, where the interaction happens, always lands in its rightmost column (Fig. 2). Specifically, a piece left of its partner needs no transform (identity) because the interacting edge is already at its right hand side. A piece to the right is flipped horizontally, a piece above the anchor is transposed, and a piece below is rotated 90° CW. After canonicalization, every pair of anchor and candidate pieces is reduced to the same comparison regardless of their spatial relationship – they become two pieces whose abutting edges are in the same (right-facing) canonical position.
Formally, let denote this transform for relative position , and write for the map of canonicalized against a partner lying in direction from it. Since then lies in the opposite direction from that partner, the transform applied is , and symmetrically for the candidate:
This reduces four directional comparisons to a single learned function, concentrating the training signal in one comparator and keeping the head small. All four transformed variants per piece are precomputed. An alternative dual-canonical scheme maps horizontal and vertical edges to separate positions. We compare both and provide details in the Supp.
4.3 Cross-Attention Interaction Head
Given canonicalized token maps and , each flattened to tokens, the head produces a scalar score. Tokens are first projected to via a shared linear layer with layer norm and GELU. The projected sequences then pass through bidirectional cross-attention layers (4 heads), each performing multi-head attention in both directions followed by a feed-forward network with residual connections. This is where compatibility is estimated: every interior token of the anchor can attend to every interior token of the candidate, letting the head discover texture continuations that no boundary comparison could see. No additional positional embeddings are added. The frozen ViT tokens already encode spatial structure.
Finally, the two output streams are compared by mean tokenwise cosine similarity:
where and are the -th output tokens of the anchor and candidate streams. The full head contains 249 K trainable parameters, all in the projection and cross-attention layers.
4.4 Training
Pair construction and loss. For each piece and direction, the true grid neighbor forms a positive pair. Negatives are sampled 50/50 from intra-puzzle (same image, non-adjacent) and cross-puzzle pools (M=32 per anchor). Adjacency labels come for free from the known grid, so no manual annotation is required. Writing for the score of the positive pair and for that of the m-th negative, we train with InfoNCE (Oord, Li, and Vinyals 2018):
where is a learnable inverse temperature (init. 1/0.07). Label smoothing of 0.05 is applied, omitted above for clarity. Each batch uses a single edge direction, so the head cannot key on transform-specific artifacts instead of content continuity.
Optimization. All models share identical hyperparameters ( , L=2, 4 heads, “right column” canonicalization) across all benchmarks, with no benchmark-specific tuning. The same configuration is reused on JPwLEG-3/5, ImageNet , and GAP. The full optimization protocol (AdamW, schedule, early stopping) is provided in the Supp.
5 Experiments
5.1 Experimental Setup
Each CM is trained once per benchmark and then frozen. The same head is reused across all solvers, erosion levels, and missing-piece counts without fine-tuning, and on ImageNet training uses px only. We compare four handcrafted CMs (SSD (Cho, Avidan, and Freeman 2010), (Paikin and Tal 2015), PBC (Pomeranz, Shemesh, and Ben-Shahar 2011), MGC (Gallagher 2012)) and our reimplementation of Edge2Vec (Rika et al. 2022a), each plugged into three compatibility-based solvers (greedy (Paikin and Tal 2015), genetic (Sholomon, David, and Netanyahu 2013), LP (Yu, Russell, and Agapito 2016)), negating dissimilarity CMs so every solver always consumes a higher-is-better CM score. On ImageNet we add inpaint-then-match pipelines that restore the eroded gap with SDXL (Podell et al. 2024), LaMa (Suvorov et al. 2022), or MAE inpainting before applying a classical boundary CM, following Bridger, Danon, and Tal (2020). On GAP we compare against PuzzleFlow (Shahar, Elkin, and Ben-Shahar 2026) and its official baselines. Protocol details are in the Supp.
5.2 Oracle Analysis and CM Swap on JPwLEG
We first replace each solver’s CM with an oracle returning 1 for true neighbors and 0 otherwise. Every solver, including
JPwLEG-3 (3×3, 48 px gap)
| CM | Greedy | Genetic | LP | ||||
|---|---|---|---|---|---|---|---|
| Top-1 | Abs | Perf | Abs | Perf | Abs | Perf | |
| SSD | 38.5 | .43 | .09 | .43 | .13 | .47 | .16 |
| 42.5 | .46 | .11 | .50 | .23 | .54 | .26 | |
| PBC | 36.6 | .41 | .08 | .40 | .11 | .44 | .13 |
| MGC | 38.1 | .48 | .12 | .45 | .16 | .48 | .19 |
| Edge2Vec | 50.8 | .56 | .17 | .70 | .44 | .74 | .49 |
| STITCH | 80.1 | .84 | .64 | .97 | .92 | .98 | .93 |
JPwLEG-5 (5×5, 12 px gap)
| CM | Greedy | Genetic | LP | ||||
|---|---|---|---|---|---|---|---|
| Top-1 | Abs | Perf | Abs | Perf | Abs | Perf | |
| SSD | 51.3 | .27 | .01 | .44 | .16 | .23 | .05 |
| 56.3 | .31 | .02 | .56 | .37 | .34 | .11 | |
| PBC | 48.8 | .26 | .01 | .41 | .15 | .22 | .04 |
| MGC | 52.6 | .30 | .01 | .57 | .27 | .23 | .03 |
| Edge2Vec | 75.0 | .61 | .19 | .93 | .81 | .69 | .46 |
| STITCH | 83.5 | .85 | .51 | .99 | .95 | .96 | .86 |
Table 1: Averaged over 2000 test puzzles and 5 runs, SEM . All STITCH-vs-baseline gaps are significant at under paired, corrected two-sided tests (Supp).

Figure 3: Qualitative results on JPwLEG (STITCH + genetic solver). JPwLEG-3 (left, 48 px gap) and JPwLEG-5 (right, 12 px gap). Red frames mark misplaced pieces, which occur only on near-uniform dark pieces (left) and repetitive stained-glass panels (right), where interior content is interchangeable.
the simplest greedy strategy, achieves perfect Abs and Perf with the oracle (Fig. 4): failures on eroded puzzles are failures of matching, not search, the central thesis of this work.
Table 1 then tests how much of this oracle gap STITCH closes by swapping only the CM. STITCH attains the highest Top-1 on both benchmarks by a wide margin, and the gain propagates through every solver, lifting the genetic and LP solvers to within a few Abs points of the oracle ceiling. On JPwLEG-5 the genetic solver rises from .93 Abs with the strongest prior CM (Edge2Vec) to a near perfect .99, almost doubling the .57 of the best handcrafted CM (MGC).
5.3 Comparison with Prior Work
Pairing STITCH with the genetic solver, the strongest on JPwLEG-5 (Table 1), surpasses all learning-based solvers on both benchmarks (Table 2). The margin over the runner-up is narrow on JPwLEG-3 but widens dramatically on JPwLEG-5 (+.629 Perf over PuzLM), leaving virtually no room for further gains. Since Table 1 shows the same head upgrading every solver, better matching, not better search, drives this leap.
5.4 Upscaling performance using ImageNet : robustness to erosion level and missing pieces
ImageNet scales to 49 pieces while varying erosion and missing pieces independently, which JPwLEG's fixed per-grid erosion cannot support. Across erosion levels px, STITCH's Top-1 stays nearly flat (see Fig. 5), dropping only pt across the full range, while handcrafted CMs collapse by 40–50 pt from their clean-boundary peak and Edge2Vec degrades sharply beyond its training erosion. A natural reservation is that modern generative models would make handling erosion easy: inpaint the gap, then match boundaries. Unfortunately, they do not. At px, restoring pieces to their original px before applying the best classical CM (MGC) reaches 48.90 Top-1 with SDXL, 56.85 with LaMa, and 66.08 with MAE inpainting, against 90.00 for STITCH when applied directly on the eroded pieces. Generative inpainting hallucinates plausible but unfaithful content precisely where matching needs evidence, and costs a full generative forward pass per candidate pair. STITCH consults the intact interior instead. Full grids over four CMs are in the Supp.

Figure 4: Oracle ceiling (JPwLEG-5). Abs (top) and Perf (bottom) for each solver with its original CM (gray), STITCH (green), and a perfect oracle (gold). All solvers reach 1.00 with the oracle. STITCH closes most of the gap.
We further removed pieces at test time (4 px erosion, no retraining), choosing removed pieces randomly but in a way that preserves a single connected block of pieces rather than scattered "islands". Table 3 reports the performance of the LP solver, which allows unoccupied positions. STITCH degrades gracefully even when over of the pieces are removed. At , learning-based solvers trained with missing pieces reach .68/.07 Abs/Perf (DiffAssemble) and .02/.00 (JPDVT), against STITCH's .87/.53 without any missing-piece training (full tables, solver CM
| Method | JPwLEG-3 | JPwLEG-5 | ||
|---|---|---|---|---|
| Abs | Perf | Abs | Perf | |
| Deepzzle (2020) | .738 | .523 | .219 | .000 |
| RL (2023a) | .816 | .597 | .403 | .051 |
| PDN-GA (2023b) | .813 | .582 | .443 | .061 |
| JPDVT (2024) | .713 | - | .041 | .000 |
| ERL-MPP (2025b) | - | - | .527 | .186 |
| FCViT (2025) | .969 | .879 | .432 | .002 |
| DiffAssemble (2024) | .797 | .542 | .629 | .164 |
| PuzLM (2025) | .919 | .845 | .721 | .325 |
| STITCH (genetic solver) | .973 | .925 | .992 | .954 |
Table 2: Comparison with prior work on JPwLEG. Best in bold, second-best underlined, unavailable entries –. All prior methods are learning-based solvers. Ours is a modular CM plugged into a genetic solver (Sholomon, David, and Netanyahu 2013).

Figure 5: Erosion robustness (ImageNet ). Top-1 vs. erosion (px). Learned CMs (STITCH, Edge2Vec) trained once at 4 px. STITCH (red) remains nearly flat while all baselines degrade sharply.

Figure 6: Qualitative results on GAP (STITCH + genetic solver). GAP-3 (left) and GAP-5 (right). Red frames mark misplaced fragments. All others are placed correctly despite the irregular, heavily eroded shapes.
grids, and unconstrained removal are in the Supp).
5.5 Irregular Fragments: GAP-3/5
Finally, we tested whether our compatibility survives irregular geometry, the regime PuzzleFlow (Shahar, Elkin, and Ben-Shahar 2026) addresses by abandoning pairwise compatibility altogether. We train STITCH on the GAP training split, alpha-compositing each RGBA fragment over a con-
| k | MGC | Edge2Vec | STITCH | |||
|---|---|---|---|---|---|---|
| Abs | Perf | Abs | Perf | Abs | Perf | |
| 0 | .42 | .12 | .91 | .78 | .97 | .91 |
| 5 | .27 | .00 | .85 | .39 | .97 | .82 |
| 10 | .21 | .00 | .76 | .10 | .94 | .66 |
| 15 | .18 | .00 | .66 | .03 | .89 | .54 |
| 20 | .18 | .00 | .62 | .01 | .87 | .53 |
Table 3: Missing pieces (ImageNet , LP solver, 4 px erosion). pieces removed at test time, CMs not retrained. Best per row in bold.
| Method | GAP-3 | GAP-5 | ||
|---|---|---|---|---|
| Abs | Perf | Abs | Perf | |
| JigsawGAN (2021) | .453 | .046 | .180 | .000 |
| DiffAssemble (2024) | .505 | .164 | .219 | .000 |
| JPDVT (2024) | .112 | .000 | .039 | .000 |
| PuzLM (2025) | .148 | .000 | .078 | .000 |
| FCViT (2025) | .607 | .252 | .204 | .000 |
| PuzzleFlow (2026) | .629 | .285 | .291 | .003 |
| STITCH (genetic) | .891 | .810 | .667 | .472 |
| STITCH (LP) | .883 | .795 | .657 | .262 |
Table 4: Irregular fragments (GAP-3/5). STITCH is trained on GAP (2026) and plugged into unchanged solvers. Baselines as originally published, with two accuracy measures matching Abs and Perf. Best in bold, second-best underlined, – unavailable. Greedy-solver, Top-1, and neighbor accuracy in the Supp.
stant black background into a fixed square before the frozen MAE, so the irregular shape enters through the pixels alone with no shape-aware change to the head. Plugging the trained STITCH into the genetic and LP solvers surpasses every learning-based solver on GAP-3, clearing the previous best by over .25 Abs and .50 Perf. The genetic solver with STITCH perform similarly on GAP-5 as well (Table 4): it more than doubles PuzzleFlow's Abs and raises Perf from .003 to .472, so nearly half of all GAP-5 puzzles are now reconstructed perfectly (Fig. 6). The pairwise-CM paradigm thus extends to irregular fragments once the match itself is fixed.
5.6 Qualitative Results and Computational Cost
While presenting a leap from the prior art on compatibility, STITCH is not perfect. The few remaining errors, however, concentrate in textureless or repetitive regions where interior tokens become interchangeable, and compatibility is arguably undecidable (Figs. 3 and 6): near-uniform dark pieces in JPwLEG-3, recurring stained-glass panels in JPwLEG-5, and sparse or repetitive fragments in GAP. Fig. 7 suggests why this happens. When pieces carry pictorial content, cross-attention anchors onto the facing edges and the true neighbor is ranked first, whereas on textureless pieces attention finds nothing to lock on and the match fails, consistent with a head that has learned spatially meaningful, facing-edge-driven patterns. Additional failure examples are in the Supp.

Figure 7: Cross-attention on JPwLEG-5. Outer columns show anchor A and candidate B, inner columns the attention between them (A→B and A←B), aggregated over all heads and query tokens in the last layer. Top (green): on pieces with rich pictorial content, attention concentrates on the facing edges and STITCH ranks B first. Bottom (red): on near-textureless pieces, attention finds no structure to key on and the true neighbor is missed.

Figure 8: Backbone comparison (JPwLEG-5, LP solver). Six frozen backbones positioned by solver-level Perf (x) and CM-level Top-1 (y), with area proportional to parameter count. MAE ViT-B/16 dominates both axes despite matching DINov2, CLIP, and supervised ViT-B/16 in size (~86M) and architecture: the objective, not capacity, drives performance.
Computationally, scoring one pair costs a single 23 MFLOP head forward pass over cached ViT features, so all 4,704 pairs of a puzzle are scored in under 0.1 s on one RTX 4090 (full hardware and software specifications in the Supp), making the solver, not the CM, the runtime bottleneck. Feature extraction is a one-time cost of 196 backbone passes per puzzle, amortized across every pair. Learning-based solvers of comparable accuracy carry 85–124M trained parameters (Shahar, Elkin, and Ben-Shahar 2026), whereas STITCH trains a relatively negligible 249 K parameters on top of an off-the-shelf frozen backbone.
6 Ablations
We ablate the backbone and the head configuration, both on JPwLEG-5 with the LP solver.
Backbone. Fig. 8 compares six frozen backbones. MAE ViT-B/16 occupies the top-right corner alone, and the three backbones that share its architecture and size, differing only in pretraining objective, trail it by up to 39.7 Top-1 points: classification, self-distillation, and contrastive-language pre- training all discard the local texture signal that eroded matching requires, whereas MAE's reconstruction objective preserves it. A ResNet-50 with a third of the parameters outscores two of them, confirming that the objective, not capacity or architecture, is what matters.
| Variant | Params | MFLOPs | Top-1 | Abs | Perf |
|---|---|---|---|---|---|
| Projection dimension | |||||
| ~25 K | 3 | 77.2 | .890 | .742 | |
| ~249 K | 23 | 83.5 | .964 | .868 | |
| ~891 K | 73 | 83.5 | .965 | .867 | |
| (no proj.) | ~28.3 M | 2,139 | 80.1 | .948 | .834 |
| Cross-attention layers | |||||
| (no cross-attn.) | ~49 K | 7 | 64.8 | .522 | .240 |
| ~149 K | 15 | 82.5 | .950 | .848 | |
| ~249 K | 23 | 83.5 | .964 | .868 | |
| ~449 K | 38 | 84.5 | .967 | .873 | |
Table 5: Head configuration ablation (JPwLEG-5, LP solver). Each block varies one hyperparameter with the other fixed at the default. marks the chosen configuration, the cheapest on the accuracy plateau.
Head configuration. Table 5 varies the two head hyperparameters around the default ( , L=2, marked ). Cross-attention is essential: removing it (L=0) collapses Perf from .868 to .240. One layer recovers most of the gain, and depth beyond two adds Top-1 point at nearly double the parameters. For the projection, loses over 6 Top-1 points, only matches the default, and no projection costs two orders of magnitude more compute while reducing accuracy. We therefore adopt the cheapest configuration on the accuracy plateau. Full sweeps are in the Supp.
7 Conclusion
We demonstrate that the bottleneck in puzzle solving is not the solver but the match (namely the compatibility measure), and argue that this component deserves far more attention than it has received. Toward this end, we introduce STITCH, a pluggable data-driven CM that improves square-puzzle solving regardless of the reconstruction method: training only 249 K parameters on top of a frozen backbone, and plugging into any solver as-is, it nearly saturates both JPwLEG benchmarks, generalizes to unseen erosion levels and missing pieces without retraining, and, once trained on GAP, boosts compatibility-based solvers to outperform the best learning-based model when solving grid puzzles of irregular fragments. Natural future work includes extensions to real fragment collections beyond grid topologies (Harel and Ben-Shahar 2021; Tsesmelis et al. 2024; Elkin et al. 2025) and large puzzles where caching the complete compatibility table is impractical.
References
Andaló, F. A.; Taubin, G.; and Goldenstein, S. 2017. PSQP: Puzzle Solving by Quadratic Programming. IEEE Transactions on Pattern Analysis and Machine Intelligence, 39(2): 385–396.
Bridger, D.; Danon, D.; and Tal, A. 2020. Solving jigsaw puzzles with eroded boundaries. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, 3526–3535.
Carlucci, F. M.; D'Innocente, A.; Bucci, S.; Caputo, B.; and Tommasi, T. 2019. Domain generalization by solving jigsaw puzzles. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, 2229–2238.
Cho, T. S.; Avidan, S.; and Freeman, W. T. 2010. A probabilistic image jigsaw puzzle solver. In 2010 IEEE Computer society conference on computer vision and pattern recognition, 183–190. IEEE.
Demaine, E. D.; and Demaine, M. L. 2007. Jigsaw Puzzles, Edge Matching, and Polyomino Packing: Connections and Complexity. Graphs and Combinatorics, 23(1): 195–208.
Dosovitskiy, A.; Beyer, L.; Kolesnikov, A.; Weissenborn, D.; Zhai, X.; Unterthiner, T.; Dehghani, M.; Minderer, M.; Heigold, G.; Gelly, S.; et al. 2020. An image is worth words: Transformers for image recognition at scale. arXiv:2010.11929.
Elkin, G.; Shahar, O. I.; and Ben-Shahar, O. 2025. Seq2Seq Models Reconstruct Visual Jigsaw Puzzles without Seeing Them. arXiv:2511.06315.
Elkin, G.; Shahar, O. I.; Ohayon, Y.; Alali, N.; and Ben-Shahar, O. 2025. Recognizing artistic style of archaeological image fragments using deep style extrapolation. In International Conference on Human-Computer Interaction, 115–131. Springer.
Fissler, P.; Küster, O. C.; Laptinskaya, D.; Loy, L. S.; Von Arnim, C. A.; and Kolassa, I.-T. 2018. Jigsaw puzzling taps multiple cognitive abilities and is a potential protective factor for cognitive aging. Frontiers in aging neuroscience, 10: 299.
Gallagher, A. C. 2012. Jigsaw puzzles with pieces of unknown orientation. In 2012 IEEE Conference on computer vision and pattern recognition, 382–389. IEEE.
Guerroui, N.; and Séridi, H. 2018. Solving computational square jigsaw puzzles with a novel pairwise compatibility measure. Journal of King Saud University - Computer and Information Sciences.
Gur, S.; and Ben-Shahar, O. 2017. From square pieces to brick walls: The next challenge in solving jigsaw puzzles. In Proceedings of the IEEE international conference on computer vision, 4029–4037.
Harel, P.; and Ben-Shahar, O. 2021. Crossing cuts polygonal puzzles: Models and Solvers. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 3084–3093.
Harel, P.; Shahar, O. I.; and Ben-Shahar, O. 2024. Pictorial and apictorial polygonal jigsaw puzzles from arbitrary number of crossing cuts. International Journal of Computer Vision, 132(9): 3428–3462.
He, K.; Chen, X.; Xie, S.; Li, Y.; Dollár, P.; and Girshick, R. 2022. Masked autoencoders are scalable vision learners. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, 16000–16009.
He, K.; Zhang, X.; Ren, S.; and Sun, J. 2016. Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition, 770–778.
Heck, G.; Lermé, N.; and Le Hégarat-Mascle, S. 2025. Solving jigsaw puzzles with vision transformers. Pattern Analysis and Applications, 28(2): 110.
Huroyan, V.; Lerman, G.; and Wu, H.-T. 2020. Solving Jigsaw Puzzles by the Graph Connection Laplacian. SIAM Journal on Imaging Sciences, 13(4): 1717–1753.
Khoroshiltseva, M.; Traviglia, A.; Pelillo, M.; and Vascon, S. 2022. Relaxation Labeling Meets GANs: Solving Jigsaw Puzzles with Missing Borders. arXiv:2203.14428.
Kim, G.; Cho, H.; and Nam, H. 2025. Solving jigsaw puzzles by predicting fragment's coordinate based on vision transformer. Expert Systems with Applications, 272: 126776.
Li, R.; Liu, S.; Wang, G.; Liu, G.; and Zeng, B. 2021. JigsawGAN: Auxiliary Learning for Solving Jigsaw Puzzles with Generative Adversarial Networks. IEEE Transactions on Image Processing, 31: 513–524.
Liu, J.; Teshome, W.; Ghimire, S.; Sznaier, M.; and Camps, O. 2024. Solving masked jigsaw puzzles with diffusion vision transformers. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 23009–23018.
Liu, Z.; Mao, H.; Wu, C.-Y.; Feichtenhofer, C.; Darrell, T.; and Xie, S. 2022. A convnet for the 2020s. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, 11976–11986.
Noroozi, M.; and Favaro, P. 2016. Unsupervised learning of visual representations by solving jigsaw puzzles. In European conference on computer vision, 69–84. Springer.
Oord, A. v. d.; Li, Y.; and Vinyals, O. 2018. Representation learning with contrastive predictive coding. arXiv:1807.03748.
Oquab, M.; Darcet, T.; Moutakanni, T.; Vo, H.; Szafraniec, M.; Khalidov, V.; Fernandez, P.; Haziza, D.; Massa, F.; El-Nouby, A.; et al. 2024. DINOv2: Learning robust visual features without supervision. Transactions on Machine Learning Research Journal.
Paikin, G.; and Tal, A. 2015. Solving multiple square jigsaw puzzles with missing pieces. In Proceedings of the IEEE conference on computer vision and pattern recognition, 4832–4839.
Paumard, M.-M.; Picard, D.; and Tabia, H. 2020. Deepzzle: Solving visual jigsaw puzzles with deep learning and shortest path optimization. IEEE Transactions on Image Processing, 29: 3569–3581.
Podell, D.; English, Z.; Lacey, K.; Blattmann, A.; Dockhorn, T.; Müller, J.; Penna, J.; and Rombach, R. 2024. SDXL: Improving latent diffusion models for high-resolution image synthesis. In International Conference on Learning Representations, volume 2024, 1862–1874.
Pomeranz, D.; Shemesh, M.; and Ben-Shahar, O. 2011. A fully automated greedy square jigsaw puzzle solver. In CVPR 2011, 9–16. IEEE.
Radford, A.; Kim, J. W.; Hallacy, C.; Ramesh, A.; Goh, G.; Agarwal, S.; Sastry, G.; Askell, A.; Mishkin, P.; Clark, J.; et al. 2021. Learning transferable visual models from natural language supervision. In International conference on machine learning, 8748–8763. PMLR.
Richter, F.; Ries, C. X.; Cebron, N.; and Lienhart, R. 2012. Learning to reassemble shredded documents. IEEE Transactions on multimedia, 15(3): 582–593.
Rika, D.; Sholomon, D.; David, E.; and Netanyahu, N. S. 2022a. Edge2Vec: a high quality embedding for the jigsaw puzzle problem. arXiv:2211.07771.
Rika, D.; Sholomon, D.; David, E.; and Netanyahu, N. S. 2022b. TEN: Twin embedding networks for the jigsaw puzzle problem with eroded boundaries. arXiv:2203.06488.
Russakovsky, O.; Deng, J.; Su, H.; Krause, J.; Satheesh, S.; Ma, S.; Huang, Z.; Karpathy, A.; Khosla, A.; Bernstein, M.; Berg, A. C.; and Fei-Fei, L. 2015. ImageNet Large Scale Visual Recognition Challenge. International Journal of Computer Vision (IJCV), 115(3): 211–252.
Scarpellini, G.; Fiorini, S.; Giuliari, F.; Moreiro, P.; and Del Bue, A. 2024. DiffAssemble: A unified graph-diffusion model for 2D and 3D reassembly. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 28098–28108.
Shahar, O. I.; Elkin, G.; and Ben-Shahar, O. 2025. Pairwise Alignment & Compatibility for Arbitrarily Irregular Image Fragments. arXiv:2507.09767.
Shahar, O. I.; Elkin, G.; and Ben-Shahar, O. 2026. The Missing GAP: From Solving Square Jigsaw Puzzles to Handling Real World Archaeological Fragments. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 3186–3196.
Shih, H.-C.; Lu, J.-L.; and Ma, C.-H. 2019. Square puzzle solving using border compatibility matching. In 2019 16th IEEE International Conference on Advanced Video and Signal Based Surveillance (AVSS), 1–5. IEEE.
Sholomon, D.; David, O.; and Netanyahu, N. S. 2013. A genetic algorithm-based solver for very large jigsaw puzzles. In Proceedings of the IEEE conference on computer vision and pattern recognition, 1767–1774.
Sholomon, D.; David, O. E.; and Netanyahu, N. S. 2016. DNN-Buddies: A Deep Neural Network-Based Estimation Metric for the Jigsaw Puzzle Problem. In International Conference on Artificial Neural Networks (ICANN), 170–178.
Sizikova, E.; and Funkhouser, T. 2017. Wall painting reconstruction using a genetic algorithm. Journal on Computing and Cultural Heritage (JOCCH), 11(1): 1–17.
Son, K.; Hays, J.; and Cooper, D. B. 2014. Solving Square Jigsaw Puzzles with Loop Constraints. In European Conference on Computer Vision (ECCV), 32–46.
Son, K.; Hays, J.; Cooper, D. B.; et al. 2016. Solving small-piece jigsaw puzzles by growing consensus. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, 1193–1201.
Song, X.; Jin, J.; Yao, C.; Wang, S.; Ren, J.; and Bai, R. 2023a. Siamese-discriminant deep reinforcement learning
for solving jigsaw puzzles with large eroded gaps. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 37, 2303–2311.
Song, X.; Shangguan, J.; Li, Y.; Zhang, J.; Ren, J.; Bai, R.; Chen, X.; and Jiang, X. 2025a. CEARI: Co-Evolutionary Agents for Reassembling and Inpainting Puzzles with Gaps and Missing Pieces. In Proceedings of the 33rd ACM International Conference on Multimedia, 2634–2642.
Song, X.; Yang, X.; Ren, J.; Bai, R.; and Jiang, X. 2023b. Solving jigsaw puzzle of large eroded gaps using puzzlet discriminant network. In ICASSP 2023-2023 IEEE international conference on acoustics, speech and signal processing (ICASSP), 1–5. IEEE.
Song, X.; Yang, X.; Yao, C.; Ren, J.; Bai, R.; Chen, X.; and Jiang, X. 2025b. ERL-MPP: Evolutionary reinforcement learning with multi-head puzzle perception for solving large-scale jigsaw puzzles of eroded gaps. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 39, 6968–6977.
Suvorov, R.; Logacheva, E.; Mashikhin, A.; Remizova, A.; Ashukha, A.; Silvestrov, A.; Kong, N.; Goka, H.; Park, K.; and Lempitsky, V. 2022. Resolution-robust large mask inpainting with Fourier convolutions. In Proceedings of the IEEE/CVF winter conference on applications of computer vision, 2149–2159.
Talon, D.; Del Bue, A.; and James, S. 2022. Ganzle: Reframing Jigsaw Puzzle Solving as a Retrieval Task Using a Generative Mental Image. In IEEE International Conference on Image Processing (ICIP), 4083–4087.
Talon, D.; Del Bue, A.; and James, S. 2025. Ganzle++: Generative Approaches for Jigsaw Puzzle Solving as Local to Global Assignment in Latent Spatial Representations. Pattern Recognition Letters, 187: 35–41.
Tsesmelis, T.; Palmieri, L.; Khoroshiltseva, M.; Islam, A.; Elkin, G.; Shahar, O. I.; Scarpellini, G.; Fiorini, S.; Ohayon, Y.; Alali, N.; et al. 2024. Re-assembling the past: The REPAIR dataset and benchmark for real world 2D and 3D puzzle solving. Advances in Neural Information Processing Systems, 37: 30076–30105.
Vardi, B.; Torcinovich, A.; Khoroshiltseva, M.; Pelillo, M.; and Ben-Shahar, O. 2023. Multi-phase relaxation labeling for square jigsaw puzzle solving. arXiv:2303.14793.
Xu, Z.; and Liu, X. 2025. VLHSA: Vision-Language Hierarchical Semantic Alignment for Jigsaw Puzzle Solving with Eroded Gaps. arXiv:2509.25202.
Yilmaz, S.; and Nabiyev, V. V. 2023. Comprehensive survey of the solving puzzle problems. Computer Science Review, 50: 100586.
Yu, R.; Russell, C.; and Agapito, L. 2016. Solving Jigsaw Puzzles with Linear Programming. In Proc. British Machine Vision Conference (BMVC), 139.1–139.12.