Manuscript Offprint

arXiv:2608.24119

TransPhy: Visual In-Context Learning for Physically Grounded Image Editing

Siyi Xie, Xuanke Shi, Jinsheng Quan, Haoran Tang, Zukai Chen, Lei Yang, Quan Wang

Abstract

Visual demonstrations provide a natural interface for specifying image transformations that are difficult to describe exhaustively with text. However, existing visual in-context learning (VICL) methods primarily focus on appearance-level relation transfer and provide limited support for physically grounded transformations, whose outcomes depend on material properties, geometry, object interactions, and environmental conditions. Given a source–target exemplar pair and a query image, physically grounded VICL requires a model to infer the demonstrated transformation, adapt its effects to the query-specific scene context, and preserve rule-irrelevant content. We introduce PhysVICL-74, comprising 74 physically grounded transformation rules and 5,240 source–target image pairs that form nearly 75K training and evaluation contexts. Its benchmark split separately evaluates novel-instance transfer and unseen-rule generalization. We further propose TransPhy, a framework that decomposes physically grounded VICL into physical-rule induction and transition-aligned rendering. TransPhy first predicts the demonstrated rule and an explicit query-specific target-state description, and then synthesizes the target image through token-wise mixture-of-experts adaptation, with expert routing guided by localized transition cues. Experiments show that TransPhy improves physical-rule adherence, query consistency, and unseen-rule generalization over existing visual in-context editing methods.

1 Introduction

Text prompts provide an intuitive interface for image editing (Brooks, Holynski, and Efros 2023; Feng et al. 2025; Samadi et al. 2025; Feng et al. 2024; Mao et al. 2026; Ma et al. 2026). However, language often underspecifies transformations involving multiple coupled effects and complex spatial dependencies. Melting, for example, may require coordinated changes in material state, object shape, solid volume, and interaction with the supporting surface. Exhaustively describing these consequences in text is cumbersome and ambiguous. Visual in-context learning (VICL) provides a natural alternative: given a source–target exemplar pair, a model transfers the demonstrated transformation to a new query image. By showing both changed and preserved content, visual exemplars can specify transformations that are difficult to express precisely through language alone.

Existing VICL methods effectively transfer perceptual and semantic relations across stylization, visual effects, attribute

Figure

Figure 1: Physically grounded VICL. Top: limitations of prior methods (1) and our TransPhy framework (2). Bottom: representative PhysVICL-74 transformations.

editing, representation conversion, and image restoration (Li et al. 2025; Black Forest Labs et al. 2025; Song et al. 2026b; Zhang et al. 2025; Chen et al. 2025a; Gong et al. 2025; Manor et al. 2026; Rajagopalan and Patel 2025). These tasks are largely evaluated by reproducing the demonstrated relation. Physically grounded transformations additionally require query-dependent adaptation: the same rule may yield different outcomes according to material, geometry, interactions, and environment. For example, melting ice and wax produces different deformations, material states, and secondary effects despite sharing a high-level rule. Successful transfer must therefore infer the transformation and adapt it to the query rather than copy the exemplar difference. We call a transformation physically grounded when its observable outcome depends on these query-specific physical factors.

Given a source–target exemplar pair (A,A′)(A, A') and a query image BB, physically grounded VICL synthesizes a context-appropriate result B′B' while preserving unaffected content. It poses two coupled challenges: First, transformation interpretation must separate the transferable rule from incidental exemplar properties such as identity, texture, color, and background. Second, query-conditioned realization must adapt that rule to the query's structure and context. Because these

∗^{*}Corresponding author.

effects are spatially heterogeneous, transformed objects, interaction regions, secondary effects, and preserved areas may require distinct generation behaviors. Existing methods often encode exemplar relations globally or use image- or layer-level adaptation, capturing only salient effects. As Figure 1 shows, a model may transfer melting by generating a liquid puddle while leaving the solid volume unchanged—a visually suggestive but incomplete physical transition.

Despite growing interest in physically plausible image editing (Zhao et al. 2025; Lin et al. 2026; Ding et al. 2026; Sheng et al. 2026; Xu et al. 2026), prior work mainly studies text-specified transformations. Whether VICL models can infer such transformations from visual exemplars, adapt them to new instances, and generalize to unseen types remains unclear. We introduce PhysVICL-74, a training-and-evaluation benchmark comprising 74 transformation rules, 5,240 source-target image pairs, and nearly 75K exemplar-query contexts. It supports two complementary protocols. Novel-instance transfer applies seen rules to new objects and scenes. Unseen-rule generalization instead holds out entire rules during training. Together, they evaluate whether a model follows the demonstrated rule, adapts it to the query, and preserves rule-irrelevant content.

Building on these observations, we propose TransPhy, a physical-transformation induction and transition-aligned rendering framework that decomposes physically grounded VICL into transformation interpretation and query-conditioned realization. The former captures the transferable rule, while the latter predicts how that rule should manifest in the query, reducing reliance on exemplar-specific appearance. Its understanding pathway predicts textual descriptions of the demonstrated rule and query-specific target state, specifying what transfers and how it manifests while reducing exemplar-specific copying. To realize the predicted transformation, token-wise mixture-of-experts low-rank adaptation (MoE-LoRA) then allows spatial tokens to activate specialized rendering experts. We further develop a training-only State-Transition Capturer (STC), which extracts localized transition representations from the vision transformer (ViT) feature differences between B and B′B'. These representations regularize expert routing toward transition-sensitive generation behaviors, encouraging different regions to handle primary changes, secondary effects, and content preservation appropriately. Thus, textual interpretation determines what transformation occurs, while transition-aligned routing controls how it is realized across the query image.

Experiments show that TransPhy improves both novel-instance transfer and unseen-rule generalization, producing more complete, physically plausible transformations with competitive perceptual quality and broader visual-relation performance. These results indicate that explicit transformation induction and fine-grained alignment strengthen physically grounded editing and general VICL rule transfer.

Our contributions are summarized as follows:

• We formulate physically grounded visual in-context learning, a setting that requires models to infer a transformation from a visual exemplar and adapt its consequences to the physical properties and context of the query.

• We introduce PhysVICL-74, a dataset and benchmark containing 74 physically grounded transformation rules, 5,240 source–target image pairs, and nearly 75K exemplar–query contexts, with separate evaluation of novel-instance transfer and unseen-rule generalization.

• We propose TransPhy, combining textual rule interpretation with transition-aligned token-wise expert routing to improve physical plausibility and generalization.

References (47)