From Images to Executable Vector Drawing Code: Beta Testing Multimodal Models

    This article shares beta-testing experience in using multimodal models to convert 2D schematic diagrams into structured, executable vector drawing code. It covers the problem definition, observed improvements in reconstruction completeness for complex diagrams, and the technical pipeline: image preprocessing and element detection, scene graphs and layer topology, geometric constraints, style mapping and draw order, and code generation with render-back validation. It also proposes layered evaluation metrics and practical engineering recommendations for human-in-the-loop validation, template constraints, confidence flags, and regression testing. The goal is to show how teams can move beyond image recognition toward reconstructable, executable, and reviewable diagram code while understanding current limitations.

    From Images to Executable Vector Drawing Code: Beta Testing Multimodal Models

    1. Problem Background: From “Understanding an Image” to “Writing Executable Drawing Code”

    When multimodal models process schematic diagrams, the goal is not simple image captioning or OCR. The goal is to reconstruct a 2D image as structured drawing code that can be edited, rendered, and reviewed. This task involves visual understanding, geometric reasoning, layer topology, and code generation, making it significantly harder than ordinary image-question answering.

    In complex schematic diagrams, an image often contains 3D structures, occlusions, grouped containers, arrow relationships, solid and dashed line semantics, filled regions, and text labels. The model must first determine which elements exist, then how they relate, and finally map those relationships into coordinates, paths, styles, and draw order. If the model only traces pixels, the generated code may look similar but will be non-editable, non-reusable, and hard to review manually. The valuable capability is therefore to reconstruct the image as a semantically meaningful scene graph and then compile it into structured vector drawing instructions.

    2. Beta Testing Observations: Improved Reconstruction Completeness on Complex Diagrams

    Qualitative observations from the intermediate beta version show that reconstruction completeness on complex diagrams has improved noticeably. Early visual experiment versions tended to stay at element recognition, such as rectangles, arrows, and text, but were less stable on occlusion relationships, 3D hierarchy, and draw order. The new version performs more completely in the following areas:

    1. It can understand 3D structure in 2D images. The model attempts to distinguish foreground, main subject, background, and auxiliary lines instead of flattening all elements into the same layer.
    2. It can handle occlusion and layer relationships. For partially occluded elements, the model produces visible contours, inferred boundaries, and layer order, reducing errors caused by elements covering each other.
    3. It can generate more complete drawing elements. Output includes not only coordinates and paths but also solid and dashed lines, filled regions, line width, arrow direction, and draw order.
    4. It can maintain a degree of structural consistency. Relative positions, connections, and grouping relationships among multiple elements in complex diagrams are closer to the original image rather than being assembled in a scattered way.

    It should be emphasized that this capability remains “assisted generation” rather than “fully automatic reconstruction.” For images with strong perspective ambiguity, severe occlusion, dense labels, or unclear style, the model still needs confidence indicators, manual review, and template constraints.

    3. Technical Breakdown: The Key Pipeline from Image to Drawing Code

    3.1 Image Preprocessing and Element Detection

    Input images first need resolution normalization, contrast enhancement, and region segmentation. For large images, multi-scale scanning can be used: first identify the overall layout, then perform fine-grained detection on local regions. In the element detection stage, the system should output candidate primitives such as rectangles, circles, polylines, arrows, text blocks, and filled regions, and record bounding boxes, colors, and approximate hierarchy.

    3.2 Scene Graph and Layer Topology Construction

    The scene graph is the core intermediate representation. Nodes represent primitives or groups; edges represent connection, containment, pointing, and occlusion relationships. The model needs to estimate the z-order of each node: who is in front, who is behind, and who is occluded by whom. For invisible parts, it should mark them as “inferred boundaries” rather than treating guesses as certain facts. The more accurate the layer topology, the more stable the subsequent draw order.

    3.3 Geometric Quantification and Constraint Solving

    Visual understanding provides relative relationships, while drawing code requires concrete coordinates and paths. Engineering practice should introduce constraint solving: horizontal alignment, vertical alignment, equidistant distribution, containment relationships, arrow endpoint snapping, and container boundary constraints. Paths should be simplified as much as possible into polylines, arcs, or Bezier curves, and duplicate coordinates, out-of-bounds paths, and self-intersecting paths should be validated.

    3.4 Style Mapping and Draw Order

    Styles include line width, color, solid and dashed lines, fill, opacity, and arrow type. Solid and dashed lines often carry semantics, such as indicating auxiliary relationships, hidden edges, or non-primary flows. Draw order should generally follow the principle of “background layer—container layer—main primitives—connector lines—labels—highlight layer” to prevent text from being covered or arrows from being obscured by filled regions.

    A reviewable intermediate structure can be abstracted as the following pseudocode:

    1. diagram := {
    2. canvas: {width, height},
    3. nodes: [
    4. {id: "container_a", type: "rect", bbox: [x, y, w, h], z: 10,
    5. style: {stroke: "solid", fill: "light"}},
    6. {id: "shape_b", type: "path", points: [...], z: 20,
    7. style: {stroke: "dashed", fill: "none"}},
    8. {id: "label_b", type: "text", anchor: [x, y], z: 30}
    9. ],
    10. edges: [
    11. {from: "shape_b", to: "container_a", arrow: "end", style: "solid"}
    12. ],
    13. groups: [{id: "group_1", children: ["container_a", "shape_b"]}],
    14. draw_order: ["container_a", "shape_b", "edge_1", "label_b"]
    15. }

    The benefits of this intermediate structure are clear semantics, local correction, static validation, and easier conversion to different rendering targets.

    3.5 Code Generation and Render-Back Validation

    Generated code should not be delivered directly. It should undergo syntax validation, coordinate out-of-bounds checks, element overlap checks, and render-back validation. Render-back validation re-renders the generated result as an image and then compares its structure with the original image and performs manual spot checks. If missing elements, incorrect order, or style deviations are found, the differences can be fed back to the model for a second correction.

    4. Evaluation Method: Layered Metrics Are More Reliable Than a Single Similarity Score

    When evaluating this capability, pixel similarity alone is not recommended. A more reasonable approach is layered evaluation:

    • Element recall and precision: whether primitives, text, and arrows are fully recognized;
    • Topology correctness: whether connection, containment, and occlusion relationships are correct;
    • Geometric error: whether coordinates, angles, alignment, and path simplification are reasonable;
    • Style matching: whether solid and dashed lines, fill, line width, and arrows are consistent;
    • Order correctness: whether the drawing hierarchy causes occlusion errors;
    • Executability: whether generated code can render directly and whether error types can be located;
    • Manual readability: whether variable naming, grouping structure, and comments are maintainable.

    Test sets should cover simple flowcharts, complex 3D schematics, heavily occluded diagrams, densely labeled diagrams, and diagrams with unclear styles. Each model update should include regression testing to avoid improvements on complex diagrams while degrading simple ones.

    5. Engineering Deployment Recommendations: Human-in-the-Loop and Closed-Loop Validation

    In actual engineering, this capability should be positioned as a “first-draft generator for drawing code.” Developers can build template libraries and constraint libraries so the model outputs within a controlled scope; add confidence markers for high-risk primitives; and perform automatic validation and manual review on generated results. General cloud capabilities such as object storage, logging, and monitoring can support sample management, evaluation pipelines, and closed-loop error tracking, while the specific implementation should keep interfaces neutral and replaceable.

    Copyright and compliance also require attention: input diagrams should have legitimate sources, and generated code should undergo security scanning and license review. For images with dense text labels, preserving text editability should take priority over tracing text directly into paths.

    6. Boundaries and Conclusion

    These models still have boundaries. Perspective ambiguity can lead to misjudgment of 3D structure; invisible parts of occluded regions can only be inferred; complex styles and hand-drawn styles are difficult to reproduce fully; generated code may be syntactically correct but semantically biased. Therefore, productization should provide diff comparison, local regeneration, constraint editing, and rollback mechanisms.

    Overall, the ability of multimodal models to convert 2D schematic diagrams into structured vector drawing code is moving from “can recognize” toward “can reconstruct, can execute, and can review.” For developers, the key is not to pursue one-shot fully automatic reconstruction, but to build an evaluable and correctable engineering loop around scene graphs, constraint solving, code templates, and render-back validation. Only in this way can the capability deliver stable value in scenarios such as chart reproduction, technical documentation generation, and design assistance.