Multimodal LLM Graphic Reconstruction: Methods, Evaluation, and Engineering Practices
This article breaks down how multimodal large language models convert images into compilable vector graphics code. It explains why the task is difficult, how to split it into geometry reconstruction, 3D and occlusion reasoning, layer and style separation, and drawing order planning, and how to design structured prompts, layered evaluation metrics, and failure-handling workflows for reliable structured generation.
1. Why Reconstructing Graphics from Images Is Harder Than It Looks
A recurring topic in recent technical discussions is whether multimodal large language models can take a UI screenshot, diagram, or engineering sketch and directly output compilable vector graphics code. It looks like simple image-to-code conversion, but the actual pipeline is long: the model must first reconstruct 3D structure from 2D pixels, determine which parts are occluded and which belong to different layers, and then map that understanding into coordinates, paths, solid and dashed line types, fill regions, and drawing order.
The core tension is that images are dense, continuous inputs without explicit semantic labels, while vector graphics descriptions are discrete, structured code that is sensitive to order. Errors at any stage are amplified during rendering: a half-unit coordinate offset may be invisible, but a wrong drawing order means later shapes directly cover earlier ones, so the final image “looks wrong without a clear reason.”
Performance varies significantly across models and versions, and the task is still evolving. This article therefore does not evaluate any specific product version. Instead, it abstracts the problem into reusable engineering methods: how to decompose the task, design evaluation, and improve prompts and post-processing.
2. Task Decomposition: Four Sub-Problems That Must Be Modeled Explicitly
Splitting image-to-vector-code conversion into four layers significantly improves controllability.
The first layer is geometric structure reconstruction. The model must identify basic primitives (lines, rectangles, circles, polygons, curves), their endpoints, and relative positions, then output a self-consistent coordinate system. In practice, define the canvas size and coordinate origin first to prevent scale drift from unconstrained model output.
The second layer is 3D and occlusion reasoning. Diagrams often contain front-to-back relationships, such as a cube blocking a cylinder behind it, or a dialog covering underlying UI content. The model must distinguish visible from hidden contours, decide which edges are solid or dashed, and which faces need filling.
The third layer is separating layers from styles. Fill color, line width, line type, and opacity are style attributes; geometry is structural. Mixing both in the same code block makes errors hard to localize, while separate declarations are easier to debug.
The fourth layer is drawing order planning. Vector rendering follows the rule that later drawing covers earlier drawing, so order itself is semantic. A reasonable strategy is background layer first, body layer second, and annotation layer last.
3. Prompt and Structured Output Design
A stable output format is a prerequisite for accuracy. A three-part structure of “declare, describe, draw” is recommended, constrained by illustrative code:
[CANVAS] width=800 height=600 origin=top-left[LAYERS] background, body, annotation[STYLE] body: stroke=solid width=2 fill=#EEEEEE[DRAW]layer=background: rect(0,0,800,600)layer=body: polygon(...) style=bodylayer=annotation: line(...) stroke=dashed[END]
This format provides three benefits: coordinates and styles are declared centrally for batch correction; layers are explicitly named so occlusion relationships can be checked; drawing blocks execute in order, so rendering matches code order one-to-one. If the model omits a section, the output can be judged non-compliant and retried without guessing intent.
For complex graphics, an intermediate representation can act as a buffer: first have the model output a primitive list (type, bounding box, visibility flag), then translate that list into code. The two-step approach adds one call but isolates “understanding errors” from “expression errors,” making localization more efficient.
4. Evaluation: From Visual Similarity to Quantifiable Metrics
Subjective impressions are not enough for iteration. A three-layer evaluation is recommended.
The structural layer measures format compliance and compilability: whether output can be parsed and whether primitive counts fall in a reasonable range. The geometric layer measures key-point position error and primitive recall, computed after normalization to a unified canvas. The rendering layer measures image similarity, supplemented by manual checks of occlusion and line types.
A practical approach is a tiered test set: simple UI cards, mechanical diagrams with occlusion, engineering drawings with dashed lines, and multi-layer posters. Bucket statistics by difficulty reveal which tier actually improves. Validating only on simple samples easily leads to overly optimistic conclusions.
5. Common Failure Modes and Engineering Countermeasures
The first is scale drift, where the overall output is too large or too small. Fix the canvas and repeat constraints in the prompt; normalize output coordinates in post-processing if necessary.
The second is occlusion misjudgment, where hidden contours are drawn as solid lines. Require the model to explicitly annotate a visibility field and run a consistency check before rendering.
The third is order confusion, where annotation lines cover the body. Enforce layer order and always place annotations last.
The fourth is style-structure coupling, where changing one color requires rewriting the whole block. Separate the style sheet from geometry and bind via reference names.
The fifth is long-output truncation, where complex graphics are missing at the end. Generate in segments: output the primitive list first, then complete layer by layer.
6. Combining with Cloud Engineering Practices
To turn this capability into a service, no proprietary interface is usually required; general cloud product categories are sufficient: object storage for original images and rendered outputs, container platforms for parsing and rendering services, message queues for peak shaving and chaining the “understand-generate-validate” pipeline, and logging and monitoring with alerts to track format compliance and failure distribution. Baidu AI Cloud offers corresponding product categories for these general capabilities, which can be combined as needed without binding to a specific implementation.
The more critical engineering point is the closed loop: automatically feed rendering-failure samples back into the test set for continuous regression. Compared with one-off tuning, this data-driven iteration yields more stable gains for structured generation tasks.
7. Conclusion
Converting 2D images into vector code compresses visual understanding, spatial reasoning, and structured expression into one pipeline. Rather than chasing short-term performance of a specific version, make four things solid: task decomposition, output contracts, layered evaluation, and failure feedback. When format compliance, geometric error, and occlusion accuracy can all be quantified, model choice becomes a replaceable engineering detail, and overall system reliability becomes the sustainable competitive advantage.
