Training-free Spatially Grounded Geometric Shape Encoding

Yuhang He

TL;DR

Transformers gave us compact, elegant positional encodings for individual points and tokens, yet we still lack a universal, training-free way to encode entire 2D geometric shapes alongside their spatial context. XShapeEnc solves this using 1930s optical math—specifically, orthogonal Zernike polynomials—to compress any arbitrary 2D shape and its spatial pose into an invertible, neural-friendly vector without training a single parameter. Better yet, it comes with a built-in mathematical "slider" that lets you smoothly tune whether the representation cares more about what a shape looks like or where it sits in space.

What Problem Does This Paper Address?

If you want a neural network to reason about a single coordinate in space, standard discrete positional encodings have you covered. What if you want it to reason about a complex, continuous 2D region—say, a building footprint on a map or a custom target zone for image generation?

Historically, we have taken one of two flawed paths. First, we rasterize shapes into pixel grids and throw heavy vision backbones (CNNs, ViTs) at them, ignoring their pure geometric nature. Second, we build task-specific encoders that either require massive training datasets or make restrictive assumptions—like forcing shapes to be convex, hole-free, or simple polygons. Furthermore, traditional recognition models deliberately throw away spatial context (position, scale, orientation). As spatial intelligence applications grow, we need a unified, task-agnostic, and training-free representation that captures arbitrary 2D geometry and its spatial pose simultaneously.

Methods

XShapeEnc decomposes a 2D shape into two components: its normalized geometry (a binary mask scaled inside a unit disk) and its pose vector (a flattened $2 \times 2$ linear transformation matrix plus a 2D translation vector). Both are projected onto a shared mathematical foundation: Zernike bases, a set of functions originally invented for optical wavefront analysis that are mutually orthogonal over the unit disk in polar coordinates.

Figure 1: Zernike basis visualiza- tion, we visualize nine real-part ba- sis governed by radial mode n and angular frequency m.

Here is how the pieces fit together:

  • Geometry Encoding & FreqProp: Projecting the binary shape mask onto Zernike bases yields complex coefficients—low orders capture coarse outlines, while high orders capture fine details. Simple shapes (like a circle) only activate low-frequency modes, leaving high frequencies sparse—which neural networks dislike. To fix this, the author introduces Frequency Propagation (FreqProp), a deterministic, invertible sweep that bleeds structural magnitude and phase from lower-frequency modes into adjacent higher-frequency ones with exponential long-range decay.
  • Harmonic Pose Encoding: How do you project a 1D pose vector onto a 2D disk? XShapeEnc maps each pose scalar onto radially orthonormal Gaussian-bump windows multiplied by an angular cosine wave, creating a 2D "harmonic pose field" over the unit disk. Projecting this field onto the Zernike bases yields real-valued pose coefficients that can be exactly inverted via linear algebra.
Figure 3: Three orthonormal radial windows and the harmonic pose field visualization.
  • Controllable Joint Encoding: Because geometry yields complex coefficients and pose yields real ones on the exact same basis, XShapeEnc fuses them via phase modulation—using the pose coefficient as a rotation angle acting on the complex geometry coefficient. A tunable parameter $\beta \in [0, 2]$ acts as an emphasis dial, either suppressing pose rotations ($\beta > 1$) or flattening geometry magnitudes toward a unit carrier so pose dominates ($\beta < 1$).

Datasets

Because XShapeEnc is training-free, datasets are used strictly for evaluation (or training lightweight downstream classifiers):

  • XShapeCorpus (Newly Curated): A synthetic benchmark of 1,000 complex 2D shapes with hierarchical complexity (governed by construction depth), built to stress-test invertibility and clustering under heavy perturbations.
  • Mendeley 2D Shape & MPEG-7 CE-Shape-1 Part B: Standard shape retrieval benchmarks featuring 90,000 deformed primitive shapes (Mendeley) and 70 classes of organic silhouettes like beetles and utensils (MPEG-7).
  • OpenStreetMap Polygons (Singapore & New York): Real-world geographic polygon pairs exhibiting five topological relationships (disjoint, touch, equal, overlap, within) to test joint geometry-pose reasoning.

Key Insights and Ideas

  • Reconciling Spectral Mismatches via Phase: Geometry energy spreads broadly across Zernike modes, whereas pose energy concentrates in narrow angular bands. Embedding pose purely into the phase of the complex geometry coefficients prevents scale interference while remaining mathematically consistent with how Zernike polynomials naturally rotate.
  • Zero-Training Continuous Disentanglement: Varying $\beta$ smoothly reorganizes the latent space on the fly. As shown below, the exact same 16 shapes seamlessly transition from clustering by shape identity ($\beta = 1.8$) to clustering by spatial quadrant ($\beta = 0.2$).
Figure 5: XShapeEnc controllable shape geometry-pose joint encoding visualization. By varying the emphasis modulation parameter β, we can emphasize either shape geometry or shape pose.
  • Invertibility by Design: Unlike neural embeddings that crush shapes into black-box vectors, both the FreqProp-enriched geometry encoding and the radially orthonormal pose encoding are analytically invertible—allowing shapes to be reconstructed directly from their feature vectors.

Key Results

  • Invertibility & Clustering: Reconstructing complex shapes from XShapeCorpus shows steadily decreasing MSE as encoding length grows from 64 to 4,096. Under heavy elastic deformation, shearing, and jitter, 512-d XShapeEnc features form tight, well-separated t-SNE clusters, matching pretrained ResNet18 and ViT backbones whileclassical descriptors scatter.
  • Shape Retrieval: On Mendeley, XShapeEnc achieves a 0.91 mAP, outperforming classical descriptors (e.g., ShapeContexts at 0.55), self-supervised ShapeEmbed (0.73), and pretrained CLIP (0.57). On organic MPEG-7 shapes, it scores 0.59 mAP, second only to CLIP (0.64) and ahead of ViT (0.57) and ResNet18 (0.56).
  • Topological Relation Classification: Using a simple two-layer MLP on OpenStreetMap polygon pairs, XShapeEnc hits 0.760 accuracy on Singapore (beating task-tailored Poly2Vec at 0.702 and CLIP at 0.700) and 0.768 on New York (second only to CLIP's 0.779). Ablating FreqProp drops accuracy to 0.740 and 0.753, respectively, confirming the value of high-frequency enrichment.

Limitations and Future Work

  • Clean Mask Assumptions: The framework assumes shapes have crisp, well-defined interiors; robustness to noisy or degraded boundaries has not yet been thoroughly explored.
  • Joint Invertibility Trade-off: Once geometry and pose are entangled in the joint phase-modulated vector, neither can be recovered directly unless one of the components is stored separately.
  • Broader Horizons: Evaluation hasn't yet extended to generative control, robotics, or embodied AI. Future directions include baking semantic cues (like texture or class labels) into the encoding and generalizing the math from 2D unit disks to 3D objects—and eventually 3D objects in motion.

Summary updated

Abstract

In this work, we introduce a novel training-free encoding framework, dubbed **XShapeEnc**, that encodes an arbitrary spatially grounded 2D geometric shape into a compact representation exhibiting five favorable properties, including invertibility, adaptivity, generality and controllability. Specifically, a 2D spatially grounded geometric shape is decomposed into its normalized geometry within the unit disk and its pose vector, where the pose is further transformed into a harmonic pose field that also lies within the unit disk. A set of orthogonal Zernike basis is constructed to encode shape geometry and pose either independently or jointly, with controllable relative emphasis on shape geometry or shape pose. We demonstrate the theoretical validity, efficiency, discriminability, and wide applicability of **XShapeEnc** via extensive analysis and experiments across a wide range of shape-aware tasks and our self-curated **XShapeCorpus** dataset. We envision **XShapeEnc** as a foundational framework for encoding tasks beyond one-dimensional discrete data and data-driven, learning-based paradigms, paving the way for unified and trained-free spatial encoding framework design.
BibTeX
@inproceedings{he2026training,
  author = {Yuhang He},
  title = {{Training-free Spatially Grounded Geometric Shape Encoding}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=j770IgUZZG},
}
Figure