Thinking with Programming Vision: Towards a Unified View for Thinking with Images

Zirun Guo, Minjie Hong, Feng Zhang, Kai Jia, Tao Jin

TL;DR

State-of-the-art multimodal large language models (MLLMs) are surprisingly brittle when faced with simple image orientation changes, and current "thinking with images" frameworks rely on rigid, narrow toolsets. CodeVision addresses this by introducing a "code-as-tool" paradigm where the model writes Python code as a universal interface to dynamically manipulate images. Optimized via a two-stage Supervised Fine-Tuning (SFT) and Reinforcement Learning (RL) pipeline, CodeVision enables robust error recovery, efficient tool chaining, and the spontaneous emergence of novel image-processing strategies.

What Problem Does This Paper Address?

While recent MLLMs can interactively use tools to reason about visual inputs (often called "thinking with images"), current approaches suffer from three major flaws:

  1. Lack of real-world necessity: Most frameworks focus almost exclusively on a "crop/zoom" tool, which only yields marginal (2–5%) accuracy gains on existing benchmarks.
  2. Rigid and unscalable integration: Current systems rely on fixed, pre-registered tool registries with hand-specified interfaces. Renaming a tool or changing an argument schema requires retraining the model.
  3. Extreme brittleness: Even top-tier models like GPT-4o and Gemini 2.5 Pro degrade significantly when an image is simply rotated or flipped.

The authors argue that restoring an image to its canonical orientation is a prerequisite for accurate downstream reasoning, yet current models lack the flexibility to compose multiple tools across multiple turns to fix these real-world corruptions.

Figure 1. Diagnostic results on image orientation identification.

Methods

CodeVision shifts the paradigm from calling predefined API names to generating executable Python code. This "code-as-tool" approach provides an unbounded toolset and handles complex arguments natively.

To train the model to use code effectively, the authors employ a two-stage methodology:

  • Cold-Start Supervised Fine-Tuning (SFT): The model is first trained on a high-quality dataset of tool-use trajectories. During training, a token-wise mask ensures that the model only learns from the assistant's chain-of-thought reasoning and code blocks, ignoring user inputs and cached tool execution returns.
  • Reinforcement Learning (RL) with Dense Process Rewards: Using Group Relative Policy Optimization (GRPO) as the base algorithm, the authors introduce a multi-component reward function to stabilize training and prevent "reward hacking" (e.g., repeatedly cropping an image just to farm rewards).

The total reward combines an Outcome Reward (terminal accuracy) with Strategy Shaping rewards. Strategy shaping includes a bonus for using mandatory tools (measured via Intersection-over-Union for cropping) and an inferred tool necessity reward that rewards the model for discovering optional, helpful tools via rollout comparisons. Crucially, Constraint Penalties are applied for exceeding turn limits, poor visual grounding, or using tools when none are required.

Datasets

The authors aggregated data from diverse domains to train and evaluate CodeVision:

  • Training Sources: Handwriting datasets (CASIA, IAM), everyday scene OCR/QA (HierText), table/chart understanding (UniChart), math reasoning (We-Math 2.0), and document VQA (DocVQA, TextVQA).
  • Existing Benchmarks (Single-Tool): Evaluated on V*, HRBench4k, and HRBench8k to test cropping proficiency.
  • Orientation Robustness Benchmarks: The authors applied five transformations (90°/180°/270° rotations, horizontal/vertical flips) to OCRBench and ChartQAPro.
  • MVToolBench (New Benchmark): A newly introduced multi-tool benchmark consisting of ~500 samples from the HierText dataset. It requires models to combine orientation adjustments and cropping tools sequentially alongside complex reasoning to find the correct answer.

Key Insights and Ideas

  • The "Code-as-Tool" Paradigm Unlocks Emergent Behavior: Because the model generates code rather than calling a fixed registry, it spontaneously learns to use image-processing operations that were completely absent from its training data—such as adjusting brightness, applying Gaussian blurs, or performing edge detection to solve novel problems.
Figure 6. A word cloud of emergent tools discovered during RL training.
  • SFT is an Absolute Prerequisite for RL Convergence: The authors found that attempting to train the model via pure RL exploration from scratch completely fails to converge. The vast, unstructured action space of code generation requires an initial SFT "warm start" to bootstrap basic syntax and tool-calling patterns.
  • Multi-Turn Error Recovery: CodeVision demonstrates a sophisticated ability to read runtime error logs or poor visual outputs from its own code, revise the code, and retry a different strategy within a multi-turn dialogue.

Key Results

CodeVision models (built on Qwen2.5-VL and Qwen3-VL backbones) demonstrated substantial performance leaps:

  • Orientation Robustness: On the transformed OCRBench subset, CodeVision-7B achieved an average score of 73.4, representing a +17.4 point improvement over its base model.
  • Multi-Tool Mastery: On the newly proposed MVToolBench, CodeVision-7B scored 60.1, nearly doubling the performance of the next-best commercial model, Gemini 2.5 Pro (32.6), and vastly outperforming its base model (18.1).

Limitations and Future Work

While CodeVision represents a major leap forward, its reliance on code generation means it requires a secure, sandboxed, and controlled runtime environment to execute Python code safely during inference. Additionally, the paper primarily focuses on geometric and basic pixel-level image manipulations. Future work could extend this paradigm to more complex visual programming tasks, such as integrating deep learning-based sub-modules (like open-vocabulary detectors or image-to-image diffusion models) directly into the generated code.

Summary updated

BibTeX
@inproceedings{guo2026thinking,
  author = {Zirun Guo and Minjie Hong and Feng Zhang and Kai Jia and Tao Jin},
  title = {{Thinking with Programming Vision: Towards a Unified View for Thinking with Images}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2026},
  url = {https://openreview.net/forum?id=4tD6LULKxl},
}
Figure