Organizations: The Chinese University of Hong Kong · South China University of Technology · Institute of Automation, Chinese Academy of Sciences · Nanyang Technological University
Recent advancements in Unified Multimodal Models (UMMs) have significantly advanced text-to-image (T2I) generation, particularly through the integration of Chain-of-Thought (CoT) reasoning. However, existing CoT-based T2I methods largely rely on abstract natural-language planning, which lacks the precision required for complex spatial layouts, structured visual elements, and dense textual content. In this work, we propose CoCo (Code-as-CoT), a code-driven reasoning framework that represents the reasoning process as executable code, enabling explicit and verifiable intermediate planning for image generation. Given a text prompt, CoCo first generates executable code that specifies the structural layout of the scene. The code is then executed in a sandboxed environment to render a deterministic draft image. Subsequently, the model refines this draft through fine-grained image editing to produce the final high-fidelity result. To support this training paradigm, we construct CoCo-10K, a curated dataset containing structured draft-final image pairs designed to teach both structured draft construction and corrective visual refinement. Empirical evaluations on StructT2IBench, OneIG-Bench, and LongText-Bench show that CoCo achieves improvements of 68.83%, 54.8%, and 41.23%, respectively, over direct generation, while also outperforming other CoT-enhanced generation methods. These results demonstrate that executable code is an effective and reliable reasoning paradigm for precise, controllable, and structured text-to-image generation.
Figures & tables
Figure 1: Comparison of reasoning paradigms for text-to-image generation. (a) Direct generation without explicit reasoning. (b) Text-only Chain-of-Thought (CoT) reasoning prior to image synthesis. (c) Textual CoT with an intermediate visual draft. (d) Multi-turn reasoning with iterative textual and visual drafts. (e) CoCo : our approach generates executable code as a structured visual draft that explicitly specifies object layouts and attributes, which is then rendered and refined to produce the final image.
Figure 2: Framework of CoCo. CoCo operates in three stages: (1) generating executable code from the input prompt to explicitly specify structural layouts, (2) executing the code in a sandboxed environment to render a deterministic draft image, and (3) performing draft-guided refinement to produce the final high-quality output.
Figure 3: Visual comparison between code-generated drafts and final results. Left: draft image synthesized from code generated by CoCo . Right: final image refined by CoCo based on the draft image and input prompt.
Figure 4: Construction Pipeline and Examples of CoCo-10K. We design specialized data pipelines targeting three atomic correction capabilities: general editing, scientific diagrams, and complex text. Using Gemini-3-Pro [ 36 ] and Nano Banana [ 37 ] , we generate code and final images from the collected prompts. The resulting data are organized into two training categories: Text-Code Pairs and Text-Draft Image–Final Image Pairs.
Figure 5: Detailed Visualization of CoCo-10K. We present the prompt, generated code, draft image, and final image. CoCo -10K demonstrates high fidelity and strong semantic alignment between draft and final images.
Figure 6: Contrastive visualization of the experiment. CoCo generates accurate layouts and high-fidelity text, outperforming baselines, and supports adaptive aspect ratios that align images with prompt semantics.
Model
Chart ↑
Graph ↑
Math ↑
Puzzle ↑
Science ↑
Table ↑
Overall ↑
Close-resource models
Seedream 4.0 [ 100 ]
35.79
54.08
63.33
50.89
62.59
68.94
47.52
Nano banana [ 37 ]
35.55
58.96
64.81
63.87
60.75
67.20
48.45
GPT-Image [ 101 ]
37.09
57.00
63.25
59.42
60.94
83.31
49.58
Open-resource models
UniWorld-V1 [ 10 ]
1.71
5.52
4.72
1.58
8.82
5.25
3.20
Table 1: Quantitative comparison on StructT2IBench. All values are reported as Accuracy (%). Orange and Champagne cells indicate the Top 1 and Top 2 performers respectively.
Method
OneIG-Bench [ 40 ]
LongText-Bench [ 39 ]
English
Chinese
Overall
English
Chinese
Overall
Gen. Only Models
FLUX.1-dev [ 103 ]
0.523
-
-
0.607
0.005
0.306
HiDream-I1 [ 102 ]
0.707
0.205
0.456
0.543
0.024
0.284
Kolors 2.0 [ 106 ]
0.427
0.502
0.465
0.258
0.329
0.294
Unified Models
Table 2: Comparison of text rendering capability. All values are reported as Accuracy (%). Orange and Champagne cells indicate the Top 1 and Top 2 performers respectively.
Text-to-image generation creates images from natural-language prompts using generative models, with research focused on fidelity, control, efficiency, and safety.
Unified multi-modal large language models (MLLMs) have achieved strong text-to-image generation quality, but still struggle with structure-aware prompt following, where object counts, spatial relations, attribute bindings, and coarse layouts must be preserved. We attribute this limitation in part to the entanglement of structural planning and appearance rendering within a single conditioning stream. To address this issue, we propose Implicit Visual Chain-of-Thought (IV-CoT), a latent visual reasoning framework for query-conditioned image generation. IV-CoT decomposes the visual conditioning queries into a structural-to-semantic cascade, where structural queries first form a latent visual plan and semantic queries then render appearance conditioned on this plan. To guide the structural queries, we introduce training-only sketch supervision, which encourages them to capture structure from sketches without requiring sketch extraction or intermediate decoding at inference time. IV-CoT performs implicit CoT reasoning in a single forward pass and achieves superior results on GenEval and T2I-CompBench. Visualizations and analyses demonstrate that the learned structural and semantic queries play complementary roles in structure-aware generation.
Zixuan Li, Haokun Lin, Yicheng Xiao +10
NLPR, Institute of Automation, Chinese Academy of Sciences · The University of Hong Kong · Ant Group
Reasoning-based text-to-image (T2I) generation requires models to interpret complex prompts accurately. Existing reasoning frameworks can be broadly categorized into two types: (1) Text-Only Reasoning, which is computationally efficient but lacks access to visual context, often resulting in the omission of critical spatial and visual elements; and (2) Text-Image Interleaved Reasoning, which leverages a T2I generator to provide visual references during the reasoning process. While this approach enhances visual grounding, it incurs substantial computational costs and constrains the reasoning capacity of MLLMs to the representational limitations of the generator. To this end, we propose StruVis, a novel framework that enhances T2I generation through Thinking with Structured Vision. Instead of relying on intermediate image generation, StruVis employs text-based structured visual representations as intermediate reasoning states, thereby enabling the MLLM to effectively "perceive" visual structure within a purely text-based reasoning process. Powered by this, the reasoning potential for T2I generation of the MLLM is unlocked through structured-vision-guided reasoning. Additionally, as a generator-agnostic reasoning framework, our proposed StruVis can be seamlessly integrated with diverse T2I generators and efficiently enhance their performance in reasoning-based T2I generation. Extensive experiments demonstrate that StruVis achieves significant performance improvements on reasoning-based T2I benchmarks, e.g., a 4.61% gain on T2I-ReasonBench and a 4% gain on WISE.
Yuanhuiyi Lyu, Kaiyu Lei, Ziqiao Weng +7
Hong Kong University of Science and Technology (Guangzhou) · Hong Kong University of Science and Technology · East China Normal University +2
In text-to-image in-context learning (T2I-ICL), a model has to infer a latent compositional pattern from fewshot demonstrations for generating a query image. Recent studies show that state-of-the-art multimodal large language models struggle with this setting, particularly due to limited compositional reasoning and sensitivity to prompt construction. In this work, we propose a Tree-of-Thoughts (ToT) reasoning framework for T2I-ICL that introduces a multi-stage reasoning and selection layer that generates, evaluates, and selects among multiple candidate hypotheses before constructing the final prompt for image synthesis. By exploring alternative reasoning branches and selecting a coherent interpretation, the proposed approach mitigates prompt ambiguity and compositional errors. We implement the proposed approach in a complete ToT-T2IICL inference pipeline and evaluate it on the CoBSAT benchmark. Both qualitative and quantitative results show that structured multi-branch reasoning leads to more consistent and semantically aligned image generation compared to baseline and Chain-of-Thought prompting strategies, without any additional training or fine-tuning.
Stepanida Alekseeva, Jenifer Kalafatovich, Seong-Whan Lee
Department of Artificial Intelligence, Korea University, Seoul, Korea.