Visual Primitives: A New Paradigm for Spatial Grounding in Multimodal Models

    Visual primitives give multimodal models a precise, structured way to express spatial locations in images using points, boxes, and polygons instead of vague natural language. This article explains what visual primitives are, why text-only location descriptions fall short, how coordinates are tokenized, how training data is constructed, and how to parse, evaluate, and deploy spatial outputs in production systems.

    1. What Are Visual Primitives

    Visual primitives are the basic geometric units a model uses to describe spatial positions in an image. Common primitives include points, bounding boxes, and polygons. Instead of producing natural-language descriptions like “near the top-left corner” or “the cup on the right,” the model outputs a set of explicitly structured coordinate tokens, so positional information can be expressed, verified, and reused precisely.

    The core idea is turning “space” into “symbols.” Language models excel at handling discrete symbols, while positions in an image are continuous values. Visual primitives bridge the two through special tokens, allowing the model to describe, locate, and reference objects within a single text output.

    2. Why Spatial Primitives Are Needed

    Describing locations in plain text has three obvious problems.

    First, precision is uncontrollable. A phrase like “slightly above center” cannot distinguish two positions tens of pixels apart, and downstream systems cannot crop the image or draw annotations based on it.

    Second, reference is unstable. When multiple objects of the same type appear in a scene, the model needs a unique, verifiable way to indicate “which one.” Coordinate tokens directly specify the target location without relying on linguistic relative relations.

    Third, the output is hard to structure. Business systems typically need JSON or fixed-format data rather than a narrative. Primitives make model output naturally parseable, reducing ambiguity in post-processing.

    3. Three Basic Primitives and Their Use Cases

    3.1 Point

    A point represents a single coordinate and suits keypoint localization, object counting, and pointing-style question answering. For example, when asked “where is the needle on the dashboard in the image,” the model can return a point. Evaluating points is straightforward: Euclidean distance or normalized distance is typically used to measure error.

    3.2 Box

    A box is defined by two diagonal corners—“top-left” and “bottom-right”—and suits object detection, region-level question answering, and document layout analysis. Boxes are cheap to express and compatible with mainstream detection annotation formats. Evaluation commonly uses Intersection over Union (IoU) to measure overlap between predicted and ground-truth boxes.

    3.3 Polygon

    A polygon consists of ordered vertices and suits irregular contours such as handwritten regions, road boundaries, or instrument shapes. Compared to boxes, polygons fit object edges more tightly, but more vertices increase sequence length and decoding instability. In practice, cap the maximum vertex count and standardize vertex ordering, for example clockwise.

    4. From Coordinates to Tokens: The Implementation Mechanism

    Continuous coordinates usually need to be discretized before entering a language model. The common steps are:

    1. Normalization: divide pixel coordinates by image width and height, mapping them into the 0–1 range so the representation is resolution-independent.
    2. Quantization: split normalized values into a fixed number of bins, each mapped to a discrete symbol. More bins mean higher precision, at the cost of a larger vocabulary and longer sequences.
    3. Wrapping: enclose each primitive with start and end tokens so a parser can distinguish types.

    An illustrative token format:

    1. [POINT]0.42 0.31[/POINT]
    2. [BOX]0.10 0.20 0.55 0.68[/BOX]
    3. [POLYGON]0.10 0.10 0.30 0.12 0.28 0.40 0.12 0.35[/POLYGON]

    Token names, bin counts, and coordinate ordering are all interface conventions. Training data and inference-time parsing must follow the same rules, or coordinates will be misaligned.

    5. Constructing Training Data

    Visual primitive capability depends on spatially annotated data. Common sources include:

    • Existing annotations from object detection and segmentation datasets, reused after normalization and format conversion;
    • Referring-expression samples from image-text pairs where descriptions are aligned with region boxes;
    • Manually or semi-automatically annotated QA data requiring explicit spatial tokens in answers.

    Three points matter during data construction. First, the same semantics should use the same primitive type across samples, preventing the model from outputting different formats for similar questions. Second, coordinate precision must match evaluation standards; if annotations themselves are noisy, the model’s ceiling is limited accordingly. Third, negative samples matter. For objects absent from the image, the model should explicitly answer “not found” rather than guess a coordinate.

    6. Inference Output and Parsing

    Once the model outputs primitive tokens, they go through parsing, validation, and mapping. Here is an illustrative Python implementation:

    1. import re
    2. SPATIAL_PATTERN = re.compile(r"\[(POINT|BOX|POLYGON)\](.*?)\[/\1\]", re.S)
    3. NUMBER = re.compile(r"-?\d+(?:\.\d+)?")
    4. MIN_POINTS = {"point": 1, "box": 2, "polygon": 3}
    5. def parse_spatial_spans(text: str) -> list[dict]:
    6. """Extract points, boxes, and polygons from model output with basic validation."""
    7. results = []
    8. for kind, body in SPATIAL_PATTERN.findall(text):
    9. values = [float(v) for v in NUMBER.findall(body)]
    10. if len(values) % 2 != 0:
    11. continue # Unpaired coordinate count; discard to avoid misalignment
    12. pairs = list(zip(values[0::2], values[1::2]))
    13. key = kind.lower()
    14. if len(pairs) < MIN_POINTS[key]:
    15. continue
    16. # Clamp coordinates to [0, 1]; out-of-range values are treated as model error
    17. pairs = [(min(max(x, 0.0), 1.0), min(max(y, 0.0), 1.0)) for x, y in pairs]
    18. results.append({"type": key, "points": pairs})
    19. return results
    20. def to_pixel(points, width: int, height: int):
    21. """Map normalized coordinates back to pixel coordinates."""
    22. return [(round(x * width), round(y * height)) for x, y in points]

    Three parsing considerations. First, coordinate counts must be even; otherwise the entire output may be misaligned. Second, out-of-range coordinates should be clipped or discarded and logged for later analysis. Third, polygons should be checked for vertex count—too few vertices cannot form an area.

    7. Evaluation Metrics

    Evaluation should be designed per primitive type:

    • Points: compute the normalized distance between predicted and annotated points, and measure the proportion falling inside the target region;
    • Boxes: use IoU with multiple thresholds (e.g., 0.5, 0.75) to observe how accuracy changes;
    • Polygons: use region-level IoU or the Dice coefficient to measure area overlap;
    • End-to-end referring: measure the accuracy of “whether the referenced object is correct,” which better reflects real user experience.

    Beyond accuracy, monitor format validity—the proportion of outputs that parse successfully. Format errors cause production failures more readily than localization drift, so they deserve separate monitoring.

    8. Engineering Considerations for Deployment

    1. Input handling: record the original image width and height before feeding it to the model, ensuring normalization and denormalization use the same reference.
    2. Output constraints: use prompts or decoding constraints to require only valid tokens, reducing interference from free-form text.
    3. Visual verification: render parsed results back onto the original image for manual spot-checking and to quickly catch coordinate system inconsistencies.
    4. Fallback handling: when parsing fails or returns empty, the system should return an explicit “unrecognized” status rather than reusing a previous result.
    5. Logging and privacy: images and coordinate results may contain sensitive information; redact logs and restrict access.

    9. Applicable Scenarios and Limitations

    Visual primitives fit tasks such as question answering requiring precise localization, region-based content moderation, document structure parsing, defect annotation in industrial inspection, and automation pipelines that hand visual results to downstream programs.

    They also have clear boundaries. First, in small-object and dense scenes, quantization error is amplified, requiring higher-resolution inputs or finer binning. Second, polygon vertex sequences are long, increasing inference latency and cost; choose the primitive type based on actual needs. Third, primitives are only an output format—the model’s understanding of image content still determines final quality. Correct format does not mean correct judgment.

    When selecting an approach, follow the principle of “start with boxes, use polygons only when necessary.” Boxes satisfy most detection and localization needs with low implementation and evaluation cost. Only when edge precision directly affects business outcomes is the extra cost of polygons justified.