Spaces:
Sleeping
Sleeping
File size: 48,365 Bytes
1569336 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 | # Commercial-FCI-Agent:基于闭源商业多模态图像模型的前景条件图像修复系统
**论文级技术方案与开发实现文档 v0.1**
**日期:2026-06-02**
---
## 摘要
**Commercial-FCI-Agent** 是一个 training-free、model-agnostic、agentic foreground-conditioned inpainting 框架。给定前景 RGBA 图像和用户 prompt,系统首先构造前景核心保护区、边界融合环、背景编辑区和接触区域;然后由 VLM/LLM 分析前景语义、材质、姿态、光照、尺度和接触点,生成结构化 scene plan;接着调用闭源商业图像模型生成多个候选背景;之后用 alpha-aware foreground restoration 把原始前景强制复合回候选结果;最后由 VLM critic 和可计算指标共同评分,选择最佳候选,必要时根据失败标签触发 prompt repair、mask repair 或局部 boundary/contact-shadow refinement。
核心原则:
> **商业模型负责生成候选,系统负责保证约束。**
该方案适合把 GPT-image-2、Nano Banana / Gemini Image、Seedream、Firefly 等闭源商业图像模型作为黑盒生成器,用系统化约束、评估和修复机制提升 foreground preservation、spatial rationality、boundary quality 和产品级可控性。
---
## 目录
1. [方法定位](#1-方法定位)
2. [论文贡献点设计](#2-论文贡献点设计)
3. [系统总览](#3-系统总览)
4. [形式化定义](#4-形式化定义)
5. [模块一:Asset Normalizer](#5-模块一asset-normalizer)
6. [模块二:Foreground Analyzer Agent](#6-模块二foreground-analyzer-agent)
7. [模块三:Scene Planner Agent](#7-模块三scene-planner-agent)
8. [模块四:Mask & Layout Builder](#8-模块四mask--layout-builder)
9. [模块五:Prompt Ensemble Agent](#9-模块五prompt-ensemble-agent)
10. [模块六:Commercial Generator Router](#10-模块六commercial-generator-router)
11. [模块七:Alpha-aware Foreground Restorer](#11-模块七alpha-aware-foreground-restorer)
12. [模块八:Boundary / Contact / Shadow Refiner](#12-模块八boundary--contact--shadow-refiner)
13. [模块九:Critic & Reranker Agent](#13-模块九critic--reranker-agent)
14. [模块十:Repair Planner Agent](#14-模块十repair-planner-agent)
15. [完整算法](#15-完整算法)
16. [`report.json` 设计](#16-reportjson-设计)
17. [实验设计](#17-实验设计)
18. [工程实现建议](#18-工程实现建议)
19. [失败模式与解决策略](#19-失败模式与解决策略)
20. [推荐论文结构](#20-推荐论文结构)
21. [最小可行产品版本](#21-最小可行产品版本)
22. [开发里程碑](#22-开发里程碑)
23. [实现原则](#23-实现原则)
24. [一句话版方法](#24-一句话版方法)
25. [参考资料](#25-参考资料)
---
## 1. 方法定位
### 1.1 任务定义
给定一个前景主体 $F$,通常包含 RGB 与 alpha/mask,以及一个目标背景文本 prompt $p$,系统需要生成一张最终图像 $I^*$,满足:
1. **前景主体保持不变**:形状、纹理、身份、logo、文字、姿态尽可能像素级保留。
2. **背景符合 prompt**:语义、风格、场景、材质、时间、天气、摄影风格与用户需求一致。
3. **前景-背景关系合理**:尺度、透视、接触点、地面、阴影、反射、遮挡关系合理。
4. **输出可开发、可评测、可复现**:保留中间产物、prompt、mask、模型参数、critic 分数和失败标签。
5. **不训练主生成模型**:训练成本转移到 pipeline 设计、评估器、数据与 reranking 上。
### 1.2 与普通 inpainting 的区别
普通 text-guided inpainting 主要关心 mask 区域补全;Commercial-FCI-Agent 关心的是:
> 给定一个必须保真的前景主体,如何生成与其语义、形状、尺度、光照、透视和接触关系一致的新背景。
因此,本任务的核心指标不是 FID 或单纯美学分数,而是 foreground preservation、spatial rationality、boundary quality、lighting harmony、prompt alignment 和 human preference。
### 1.3 与直接调用商业图像模型的区别
直接调用 GPT-image-2 / Nano Banana 的问题是:
- 模型可能改写前景。
- 模型可能重画 logo、文字、脸、手或商品细节。
- mask 或自然语言约束不一定严格。
- 结果可能好看但主体漂浮、尺度错误或阴影不自然。
- 结果缺乏可复现记录和可诊断中间产物。
Commercial-FCI-Agent 的关键区别是:
1. **先分析前景,再规划场景。**
2. **生成多个候选,而非一次生成。**
3. **最终强制复合原始前景,而非信任模型输出。**
4. **用 critic 自动评价和诊断失败。**
5. **根据失败标签进行迭代修复。**
---
## 2. 论文贡献点设计
### Contribution 1:Black-box Commercial FCI Protocol
提出一种面向闭源商业图像模型的 foreground-conditioned inpainting 协议。该协议不依赖模型内部 latent、attention 或训练接口,只要求模型支持图像输入、文本 prompt、可选 mask 或多参考图编辑。
### Contribution 2:Alpha-aware Foreground Restoration
提出 **foreground core / boundary ring / editable background / contact region** 四分区机制,并在生成后通过原始前景强制复合,解决闭源模型易改写前景的问题。
### Contribution 3:Critic-guided Agentic Repair
提出面向 FCI 的结构化 VLM critic,自动诊断:
- `foreground_changed`
- `logo_changed`
- `printed_text_changed`
- `floating`
- `wrong_scale`
- `wrong_perspective`
- `missing_shadow`
- `bad_reflection`
- `halo`
- `prompt_mismatch`
并把错误映射到 prompt、mask、layout、模型选择或局部修复策略。
### Contribution 4:Commercial-FCI Benchmark Protocol
提出一套可复现实验协议,对比 raw commercial model、commercial + foreground restoration、commercial + rerank、commercial + agent repair,以及开源 inpainting / foreground-conditioned 方法。
---
## 3. 系统总览
### 3.1 总体架构
```text
Input:
foreground.png / foreground_rgba.png
foreground_alpha.png optional
user_prompt
optional style refs / layout refs / background refs
│
▼
[1] Asset Normalizer
│
▼
[2] Foreground Analyzer Agent
│
▼
[3] Scene Planner Agent
│
▼
[4] Mask & Layout Builder
│
▼
[5] Prompt Ensemble Agent
│
▼
[6] Commercial Generator Router
├── GPT-image-2 Adapter
├── Nano Banana Adapter
└── Other commercial model adapter
│
▼
[7] Alpha-aware Foreground Restorer
│
▼
[8] Boundary / Contact / Shadow Refiner
│
▼
[9] Critic & Reranker Agent
│
▼
[10] Repair Planner Agent
│
└── repeat generation/refinement if needed
▼
Output:
final_composite.png
background.png
foreground.png
alpha.png
contact_shadow.png optional
report.json
```
### 3.2 Agent 列表
| Agent | 输入 | 输出 | 作用 |
|---|---|---|---|
| Asset Normalizer | 原图、mask、RGBA | 标准化 RGBA、画布、分辨率 | 统一尺寸、色彩空间、alpha、边界 |
| Foreground Analyzer | 前景图 + alpha | foreground JSON | 识别主体类别、姿态、材质、光照、接触点 |
| Scene Planner | 用户 prompt + foreground JSON | scene plan JSON | 把用户 prompt 展开成可生成的背景方案 |
| Mask & Layout Builder | alpha、scene plan | masks、layout guides | 构造保护区、编辑区、边界环、接触区 |
| Prompt Ensemble Agent | scene plan、失败历史 | K 个 prompts | 多样化候选生成 |
| Generator Router | prompts、masks、refs | raw candidates | 调用 GPT-image-2 / Nano Banana |
| Foreground Restorer | raw candidate + 原前景 | restored candidate | 强制复合原始前景 |
| Boundary Refiner | restored candidate + contact mask | refined candidate | 修边、接触阴影、反射 |
| Critic & Reranker | candidates + prompt + foreground | scores、failure tags | 评分、排序、诊断失败 |
| Repair Planner | failure tags + history | repair action | 自动决定重试、换模型、改 mask、改 prompt |
---
## 4. 形式化定义
### 4.1 输入
\[
\mathcal{X} = \{I_f, A_f, p, b, R, L, \mathcal{B}\}
\]
其中:
- $I_f \in [0,1]^{H \times W \times 3}$:前景 RGB。
- $A_f \in [0,1]^{H \times W}$:前景 alpha matte。
- $p$:用户目标背景文本 prompt。
- $b$:前景在目标画布中的位置、尺度、旋转。
- $R = \{r_1, ..., r_n\}$:可选参考图,包括风格图、背景图、品牌图、材质图。
- $L$:可选 layout guide,例如地平线、地面区域、桌面、透视线、depth map、sketch。
- $\mathcal{B}$:预算约束,包括最大 API 次数、最大延迟、模型优先级、质量等级。
### 4.2 输出
\[
\mathcal{Y} = \{I^*, B^*, F^*, A^*, S^*, Q^*, \Pi^*\}
\]
其中:
- $I^*$:最终合成图。
- $B^*$:生成背景层。
- $F^* = I_f$:原始前景层。
- $A^* = A_f$:前景 alpha。
- $S^*$:可选接触阴影或反射层。
- $Q^*$:最终质量评分。
- $\Pi^*$:最终 prompt、模型、mask、参数、critic 报告。
### 4.3 候选生成
\[
Y_i = G_m(C, M, P_i, R, L)
\]
其中:
- $G_m$:闭源商业图像模型。
- $C$:带前景的条件画布。
- $M$:编辑 mask 或 mask visualization。
- $P_i$:第 $i$ 个 prompt variant。
### 4.4 最终复合
\[
I_i = A_{soft} \odot I_f + (1 - A_{soft}) \odot Y_i
\]
对于核心保护区:
\[
I_i[x] = I_f[x], \quad \forall x \in A_{core}
\]
这一步是 Commercial-FCI-Agent 的核心,不应省略。
---
## 5. 模块一:Asset Normalizer
### 5.1 输入格式
系统应支持:
```text
case A: foreground_rgba.png
case B: rgb.png + mask.png
case C: product image with background
case D: original image + user-selected foreground bbox
case E: multi-foreground RGBA list
```
推荐内部统一为:
```python
{
"foreground_rgb": "float32[H, W, 3]", # linear or sRGB, documented
"alpha": "float32[H, W]", # 0-1
"canvas_size": [Hc, Wc],
"bbox": [x, y, w, h],
"category_hint": "optional[str]",
"metadata": {
"source": "...",
"has_original_shadow": True,
"has_logo_or_text": True
}
}
```
### 5.2 alpha 获取与清理
如果已有 RGBA:
```text
A_f = alpha channel
I_f = RGB channel
```
如果没有 alpha:
```text
A_f = Matting(SAM/RMBG/BiRefNet/MODNet)
```
后处理:
```text
A_bin = threshold(A_f, tau=0.5)
A_core = erode(A_bin, r_core)
A_dilate = dilate(A_bin, r_dilate)
A_ring = A_dilate - A_core
A_soft = gaussian_blur(A_f, sigma)
M_bg = 1 - A_dilate
```
推荐默认参数:
| 场景 | `r_core` | `r_dilate` | `sigma` | 说明 |
|---|---:|---:|---:|---|
| 商品硬边 | 3 px | 8 px | 1.0 | 鞋、瓶子、电子产品 |
| 人像 | 2 px | 10 px | 1.5 | 保脸、手、衣物纹理 |
| 毛发/动物 | 1 px | 16 px | 2.5 | 允许边缘更软 |
| 玻璃/透明物 | 1 px | 20 px | 3.0 | 避免硬切 |
| logo/text 商品 | 4 px | 8 px | 0.8 | 更强前景保护 |
### 5.3 接触区域估计
接触区域 $A_{contact}$ 很重要,因为前景漂浮感大多来自这里。
基础 heuristic:
```python
bottom_band = lower_25_percent_of_foreground_bbox
contact_seed = alpha_pixels_in_bottom_band_with_high_local_density
A_contact = dilate(contact_seed, radius=40_to_120_px) - A_core
```
更强版本:
1. 用 depth / normal estimator 估计地面。
2. 用 VLM 判断“主体应该接触哪里”。
3. 对人像检测脚部,对商品检测底面,对车辆检测轮胎,对家具检测支撑脚。
4. 构造地面投影椭圆区域作为 shadow candidate mask。
输出:
```json
{
"contact_type": "ground | table | wall | hand-held | floating_allowed",
"contact_points": [[x1, y1], [x2, y2]],
"contact_region_mask": "A_contact.png",
"expected_shadow": "soft oval shadow below the sole"
}
```
---
## 6. 模块二:Foreground Analyzer Agent
### 6.1 目标
Foreground Analyzer 用 VLM/多模态模型把前景变成结构化约束。它不是为了写 caption,而是为了给后续 generation、critique 和 repair 提供可执行信息。
输出 schema:
```json
{
"subject": {
"category": "product/shoe",
"name": "white running shoe",
"count": 1,
"identity_sensitive": true,
"has_logo_or_text": true,
"must_preserve": [
"silhouette",
"logo",
"printed text",
"texture",
"laces",
"sole pattern",
"pose"
]
},
"geometry": {
"viewpoint": "side view, slightly top-down",
"pose": "static product pose",
"bbox": [256, 340, 512, 420],
"approx_real_size": "shoe-sized object",
"expected_support": "floor/table/display surface"
},
"appearance": {
"materials": ["mesh fabric", "rubber sole"],
"dominant_colors": ["white", "gray", "blue"],
"surface_finish": "matte with slight highlights"
},
"lighting": {
"direction": "upper-left",
"softness": "softbox-like",
"color_temperature": "neutral-cool",
"existing_shadow": "none/minimal"
},
"risk_flags": [
"logo_text_sensitive",
"thin_boundary",
"contact_shadow_needed"
]
}
```
### 6.2 Analyzer prompt
```text
You are a foreground analysis module for foreground-conditioned inpainting.
Analyze only the provided foreground subject and its alpha/mask.
Do not invent background details.
Return strict JSON with:
- subject category and concise description
- visible parts and count
- materials and dominant colors
- viewpoint, pose, scale prior, expected support surface
- lighting direction, softness, color temperature
- contact region and expected shadow
- identity-sensitive regions such as face, hands, logo, printed text
- failure risks for background generation
The output will be used to preserve the subject exactly during image editing.
```
### 6.3 开发建议
不要只让 Analyzer 输出自然语言。必须输出结构化 JSON,因为后续 Prompt Ensemble、Mask Builder 和 Critic 都要消费这些字段。
---
## 7. 模块三:Scene Planner Agent
### 7.1 目标
Scene Planner 把用户 prompt $p$ 转换为可执行的 scene plan,补足摄影、空间、光照、接触、风格和负面约束。
输入:
```json
{
"user_prompt": "把这只鞋放在雨夜东京街头的橱窗前",
"foreground_analysis": {...},
"optional_refs": []
}
```
输出:
```json
{
"scene": {
"semantic_scene": "rainy Tokyo street at night",
"support_surface": "wet asphalt sidewalk",
"background_elements": [
"blurred neon signs",
"storefront window",
"subtle rain reflections"
],
"forbidden_elements": [
"extra shoes",
"changed logo",
"unreadable fake brand text on subject"
]
},
"composition": {
"camera": "low product photography angle, 50mm lens",
"horizon": "slightly above the shoe",
"depth_of_field": "shallow background blur",
"subject_position": "center-lower third",
"scale_relation": "shoe rests naturally on sidewalk"
},
"lighting": {
"key_light": "cool neon from upper-left",
"fill_light": "soft ambient city light",
"shadow": "soft contact shadow under sole",
"reflection": "faint reflection on wet pavement"
},
"style": {
"photorealism": "high",
"commercial_quality": "premium ad photography",
"color_palette": "cool blue, magenta neon, wet black pavement"
},
"negative_constraints": [
"do not alter the foreground shoe",
"do not duplicate the shoe",
"do not change logo or printed text",
"no floating object",
"no unrealistic scale mismatch",
"no hard cutout edge"
]
}
```
### 7.2 Planner 设计原则
Scene Planner 的输出要有两个版本:
1. **Generation plan**:给生成器用,强调好看、真实、符合 prompt。
2. **Evaluation plan**:给 critic 用,强调该检查哪些条件。
例如:
```json
{
"must_satisfy": [
"foreground unchanged",
"wet pavement support surface",
"contact shadow below sole",
"neon night city background",
"no second shoe"
],
"nice_to_have": [
"subtle reflection",
"cinematic bokeh",
"premium advertisement look"
]
}
```
---
## 8. 模块四:Mask & Layout Builder
### 8.1 四分区 mask
Commercial-FCI-Agent 不使用单一 mask,而使用四个区域:
```text
A_core : 前景核心保护区,最终 100% 使用原始前景
A_ring : 前景边界融合区,用于软融合、局部修边
M_bg : 背景生成区
A_contact : 接触阴影/反射修复区
```
逻辑关系:
```text
A_core ⊂ A_f
A_ring = dilate(A_f) - erode(A_f)
M_bg = 1 - dilate(A_f)
A_contact near lower/support region, outside A_core
```
### 8.2 GPT-image-2 mask 构造
对 GPT-image-2 路线,使用显式 mask edit。推荐 mask:
```text
editable = M_bg + optional outer part of A_ring + A_contact
protected = A_core
```
注意:不同 API 对 mask alpha 的语义可能不同,工程上建议写一个 `MaskAdapter`,把内部 mask schema 转换为目标 API 所需格式,不要在业务代码里硬编码。
### 8.3 Nano Banana mask visualization
Nano Banana / Gemini 更适合用多参考图和语义编辑方式。可以把 mask 转成可视化 guide:
```text
Image 1: foreground pasted on neutral canvas
Image 2: mask visualization
white = protected foreground
black = editable background
red outline = foreground boundary
blue plane = expected support surface
green dots = contact points
Image 3: optional layout sketch
Image 4: optional style/background reference
```
---
## 9. 模块五:Prompt Ensemble Agent
### 9.1 为什么要 ensemble
闭源模型不可控,单次生成不稳定。Prompt Ensemble 通过多种 prompt variant 采样候选,再由 critic 选择最优。
默认:
```text
K = 4 快速预览
K = 8 标准产品模式
K = 16 论文实验模式
K = 32 离线数据合成模式
```
### 9.2 prompt 类型
| Variant | 目的 |
|---|---|
| `conservative` | 最大化前景保持,背景简单但可靠 |
| `spatial` | 强调接触、尺度、透视、地面 |
| `lighting` | 强调色温、光照方向、阴影 |
| `aesthetic` | 强调广告级画质、构图、景深 |
| `literal` | 严格遵循用户 prompt |
| `reference-heavy` | 强调参考图/品牌风格 |
| `minimal` | 减少额外物体,降低 hallucination |
| `repair-specific` | 针对上一轮失败标签定制 |
### 9.3 GPT-image-2 prompt 模板
```text
Edit only the editable/masked background region. Keep the provided foreground subject exactly unchanged.
Foreground subject:
{foreground_description}
Target scene:
{scene.semantic_scene}
Composition:
{composition.camera}
The subject should be placed naturally on {scene.support_surface}.
Match the subject's current viewpoint, scale, and perspective.
The subject must not float.
Lighting:
Match the foreground lighting: {lighting.direction}, {lighting.softness}, {lighting.color_temperature}.
Add realistic contact shadow around {contact_region_description}.
If physically plausible, add a subtle reflection or ambient occlusion.
Strict preservation constraints:
- Do not redraw, repaint, extend, shrink, duplicate, stylize, or deform the foreground subject.
- Preserve silhouette, identity, texture, logo, printed text, pose, and all visible details.
- Do not add extra copies or extra object parts.
Negative constraints:
{negative_constraints}
Output:
A photorealistic, coherent image with natural foreground-background integration.
```
### 9.4 Nano Banana prompt 模板
```text
You are given reference images.
Image 1 is the composition canvas with the foreground subject already placed.
Image 2 is the mask guide:
- white area means protected foreground, which must remain unchanged
- black area means editable background
- red outline marks the foreground boundary
- blue guide marks the support surface or horizon
- green dots mark expected contact points
Task:
Generate a new realistic background around the protected foreground subject.
Strict requirements:
- Preserve the foreground subject exactly: shape, identity, pose, texture, logo, printed text, and boundary.
- Do not redraw, repaint, duplicate, expand, shrink, replace, stylize, or change the subject.
- Only create the surrounding environment, support surface, lighting, contact shadow, and background depth.
- The subject must be physically grounded and must not float.
- Match perspective, scale, color temperature, and lighting direction.
Target scene:
{scene.semantic_scene}
Camera and composition:
{composition.camera}
Lighting and physical effects:
{lighting}
Avoid:
{negative_constraints}
```
### 9.5 prompt repair 模板
```text
Previous generation failed because:
{failure_tags}
{critic_reason}
Repair instructions:
{repair_instruction}
Generate a corrected version. Prioritize fixing the listed failures while preserving all constraints.
```
---
## 10. 模块六:Commercial Generator Router
### 10.1 设计目标
Generator Router 对外暴露统一接口,对内适配不同闭源模型。
```python
class ImageGeneratorAdapter:
def generate(self, request: GenerationRequest) -> GenerationResult:
...
```
### 10.2 统一请求 schema
```python
from dataclasses import dataclass
from typing import Any, Dict, List, Literal, Optional, Tuple
@dataclass
class GenerationRequest:
model_family: Literal["gpt_image", "nano_banana", "seedream", "firefly"]
model_name: str
canvas_path: str
prompt: str
mask_path: Optional[str]
reference_paths: List[str]
layout_paths: List[str]
size: Tuple[int, int]
quality: Literal["low", "medium", "high", "auto"]
seed: Optional[int]
metadata: Dict[str, Any]
```
### 10.3 统一响应 schema
```python
from dataclasses import dataclass
from typing import Any, Dict, Optional
@dataclass
class GenerationResult:
raw_image_path: str
model_name: str
request_id: str
revised_prompt: Optional[str]
latency_ms: int
cost_estimate: Optional[float]
safety_status: Optional[str]
metadata: Dict[str, Any]
```
### 10.4 GPT-image-2 Adapter
GPT-image-2 路线适合显式 mask edit、商品图、局部背景替换和前景保护要求高的场景。
伪代码:
```python
def call_gpt_image_2(canvas_path, mask_path, prompt, size, quality):
result = client.images.edit(
model="gpt-image-2-2026-04-21",
image=open(canvas_path, "rb"),
mask=open(mask_path, "rb"),
prompt=prompt,
size=f"{size[0]}x{size[1]}",
quality=quality
)
return decode_and_save(result.data[0].b64_json)
```
实际参数需要按当前 SDK 支持情况调整。
### 10.5 Nano Banana Adapter
Nano Banana 路线适合多参考图、多轮编辑、复杂指令、创意背景和广告视觉。
伪代码:
```python
def call_nano_banana(prompt, image_paths, aspect_ratio, resolution):
contents = [prompt] + [Image.open(p) for p in image_paths]
response = client.models.generate_content(
model="gemini-3.1-flash-image",
contents=contents,
config=types.GenerateContentConfig(
response_modalities=["TEXT", "IMAGE"],
response_format={
"image": {
"aspect_ratio": aspect_ratio,
"image_size": resolution
}
}
)
)
return extract_and_save_image(response)
```
模型选择建议:
| 用例 | 推荐 |
|---|---|
| 快速批量候选 | Nano Banana 2 / Gemini Flash Image |
| 专业广告图、复杂文字、复杂构图 | Nano Banana Pro / Gemini Pro Image |
| 低延迟高吞吐 | Nano Banana / Gemini Flash Image |
| 前景严格保护、显式 mask | GPT-image-2 masked edit |
| 多参考图、风格/品牌/人物一致性 | Nano Banana 系列 |
---
## 11. 模块七:Alpha-aware Foreground Restorer
### 11.1 核心原则
不要直接使用商业模型输出作为最终图。商业模型输出 $Y_i$ 只是候选背景和融合提示。
最终结果:
\[
I_i = A_{hard} \odot I_f + (1 - A_{hard}) \odot Y_i
\]
其中 $A_{hard}$ 在核心区域为 1,边界区域可用软 alpha。
推荐实现:
```python
def restore_foreground(raw, fg_rgb, alpha, alpha_core, alpha_soft):
out = raw.copy()
# core: exact copy
core = alpha_core > 0.5
out[core] = fg_rgb[core]
# ring: soft blend
ring = ((alpha_soft > 0.01) & (alpha_core <= 0.5))
a = alpha_soft[..., None]
out[ring] = a[ring] * fg_rgb[ring] + (1 - a[ring]) * raw[ring]
return out
```
### 11.2 三层输出
建议输出:
```text
background.png # raw/restored background without original foreground if recoverable
foreground.png # original foreground RGB
foreground_alpha.png # alpha
final_composite.png # final
contact_shadow.png # optional estimated shadow layer
report.json # metadata
```
### 11.3 旧阴影处理
输入前景可能带原始阴影。如果直接贴到新背景,会造成光照冲突。开发时要区分:
```text
subject_alpha # 主体 alpha
shadow_alpha_old # 旧阴影,如果能分离则不要直接贴
contact_shadow_new # 新背景中生成或修复的阴影
```
推荐策略:
| 输入类型 | 策略 |
|---|---|
| 干净 RGBA,无阴影 | 直接复合 |
| 商品 PNG 带旧阴影 | 尽量分离旧阴影,或让用户选择“保留/去除原阴影” |
| 人像毛发复杂 | 用软 alpha,边界 ring 更宽 |
| 透明/反光物 | 避免完全硬贴,保留部分环境反射区域 |
---
## 12. 模块八:Boundary / Contact / Shadow Refiner
### 12.1 为什么需要第二阶段 refinement
Foreground restoration 解决了前景改写,但可能带来“贴纸感”。因此需要局部修边:
```text
Stage 1: background generation
Stage 2: boundary/contact refinement
```
### 12.2 contact refinement mask
```python
M_refine = dilate(A_contact, r=60) + A_ring
M_refine = M_refine - A_core
```
只允许编辑主体外侧窄区域,不允许改主体内部。
### 12.3 refinement prompt
```text
Refine only the narrow region around the foreground boundary and the contact area.
Add natural contact shadow, ambient occlusion, subtle reflection, and lighting transition.
Do not change the foreground subject itself.
Do not alter silhouette, logo, printed text, texture, face, hands, or object parts.
Remove halo or cutout artifacts if present.
Keep the background scene unchanged.
```
### 12.4 是否使用商业模型做 refinement
推荐两种模式。
**Mode A:GPT-image-2 local edit**
适合显式 mask、局部接触阴影、halo 修复。
**Mode B:本地传统图像处理**
适合批量、低成本、可复现:
```text
shadow = soft elliptical shadow under contact points
color_match = local color transfer
edge_feather = guided filter / poisson blend
halo_suppression = boundary color decontamination
```
实际产品里可以混合:先用本地方法快速修,再对高价值图用 GPT-image-2 或 Nano Banana 做二次修复。
---
## 13. 模块九:Critic & Reranker Agent
### 13.1 总评分
对每个候选 $I_i$,定义:
\[
S_i =
w_f S_f +
w_t S_t +
w_s S_s +
w_l S_l +
w_b S_b +
w_a S_a -
\lambda C_i
\]
其中:
| 分数 | 含义 |
|---|---|
| $S_f$ | Foreground preservation |
| $S_t$ | Text / prompt alignment |
| $S_s$ | Spatial rationality |
| $S_l$ | Lighting / shadow harmony |
| $S_b$ | Boundary quality |
| $S_a$ | Aesthetic / commercial quality |
| $C_i$ | 成本或延迟惩罚,可选 |
默认权重:
```json
{
"foreground_preservation": 0.25,
"prompt_alignment": 0.20,
"spatial_rationality": 0.25,
"lighting_harmony": 0.15,
"boundary_quality": 0.10,
"aesthetic_quality": 0.05
}
```
对电商图可提高 foreground 和 logo 权重;对创意广告可提高 aesthetic 和 prompt 权重。
### 13.2 可计算指标
#### 前景保持
最终图:
\[
E_{fg}^{final} = \| A_{core} \odot (I_i - I_f) \|_1
\]
理论上应接近 0,因为已经强制复合。
更重要的是 raw commercial output:
\[
E_{fg}^{raw} = \| A_{core} \odot (Y_i - I_f) \|_1
\]
它衡量商业模型本身是否尊重前景。
#### 边界异常
```text
BoundaryHaloScore = mean color/brightness discontinuity across A_ring
EdgeGradientMismatch = |∇foreground - ∇background| around boundary
```
#### 文本一致性
可使用:
```text
CLIPScore(image, prompt)
VLM 0-5 prompt alignment score
human pairwise preference
```
#### 空间合理性
更依赖 VLM/human:
```text
object grounded?
scale plausible?
viewpoint consistent?
contact shadow plausible?
support surface plausible?
no duplicate subject?
```
### 13.3 VLM critic prompt
```text
You are a strict evaluator for foreground-conditioned inpainting.
Inputs:
1. Original foreground subject with alpha/mask.
2. Final composite image.
3. User prompt.
4. Scene plan.
Evaluate the final image according to:
- foreground preservation
- prompt alignment
- spatial rationality
- lighting and shadow consistency
- boundary quality
- overall commercial image quality
Pay special attention to:
- whether the subject floats
- whether the subject scale is realistic
- whether the support surface is plausible
- whether the contact shadow/reflection is natural
- whether the foreground silhouette, logo, text, face, hands, texture, and pose are unchanged
- whether there are duplicated subjects or hallucinated parts
Return strict JSON:
{
"scores": {
"foreground_preservation": 0,
"prompt_alignment": 0,
"spatial_rationality": 0,
"lighting_harmony": 0,
"boundary_quality": 0,
"aesthetic_quality": 0,
"overall": 0
},
"failure_tags": [],
"must_fix": [],
"nice_to_fix": [],
"short_reason": "",
"accept": true
}
```
### 13.4 failure tags
固定标签集:
```text
foreground_changed
logo_changed
printed_text_changed
face_changed
hand_changed
duplicate_subject
extra_parts
floating
wrong_scale
wrong_perspective
bad_contact
missing_shadow
wrong_shadow_direction
bad_reflection
halo
hard_cutout
background_prompt_mismatch
overwhelming_background
overstylized
unsafe_or_policy_issue
low_resolution
compression_artifact
```
---
## 14. 模块十:Repair Planner Agent
### 14.1 修复动作空间
```python
RepairAction = Literal[
"increase_foreground_protection",
"expand_boundary_ring",
"shrink_boundary_ring",
"add_contact_shadow_refinement",
"rewrite_prompt_more_literal",
"rewrite_prompt_more_spatial",
"reduce_background_complexity",
"switch_generator_model",
"use_gpt_masked_edit",
"use_nano_multi_reference",
"increase_candidate_count",
"change_canvas_layout",
"manual_review_required",
"stop_accept"
]
```
### 14.2 失败到动作映射
| failure tag | repair action |
|---|---|
| `foreground_changed` | `increase_foreground_protection` + 强制复合 + prompt 加重 |
| `logo_changed` | 扩大 logo 区保护;prompt 显式保护文字/logo |
| `printed_text_changed` | 前景硬保护;critic 单独检查文字区域 |
| `floating` | `add_contact_shadow_refinement` + prompt 增加 support surface |
| `wrong_scale` | prompt 加真实尺寸、参照物、摄影角度 |
| `wrong_perspective` | 加地平线、相机高度、镜头、透视线 |
| `missing_shadow` | 局部 contact mask 二次修复 |
| `wrong_shadow_direction` | 从 foreground analyzer 继承光照方向重写 prompt |
| `halo` | 调整 A_ring;做边界 color decontamination |
| `duplicate_subject` | prompt 加 “no extra copies”;降低背景复杂度 |
| `background_prompt_mismatch` | 改写 scene plan,减少抽象词 |
| `overstylized` | 降低风格强度,使用 photorealistic/literal prompt |
| `overwhelming_background` | 使用 minimal prompt variant |
### 14.3 迭代策略
```text
T = 1 demo 模式
T = 2 标准模式
T = 3 离线高质量模式
```
停止条件:
```python
accept == True
or best_score >= threshold
or budget_exhausted
or no_improvement_for_two_rounds
or policy_or_safety_blocked
```
---
## 15. 完整算法
### Algorithm 1:Commercial-FCI-Agent
```python
def commercial_fci_agent(
input_image,
input_alpha,
user_prompt,
reference_images=None,
layout_hint=None,
models=("gpt-image-2-2026-04-21", "gemini-3.1-flash-image"),
K=8,
T=2,
budget=None
):
# 1. Asset normalization
asset = normalize_asset(input_image, input_alpha)
masks = build_masks(asset.alpha)
canvas = build_condition_canvas(asset, layout_hint)
# 2. Foreground understanding
fg_info = foreground_analyzer(
foreground_rgb=asset.fg_rgb,
alpha=asset.alpha
)
# 3. Scene planning
scene_plan = scene_planner(
user_prompt=user_prompt,
foreground_info=fg_info,
references=reference_images,
layout_hint=layout_hint
)
history = []
best = None
for t in range(T):
# 4. Prompt ensemble
prompt_list = make_prompt_ensemble(
scene_plan=scene_plan,
fg_info=fg_info,
previous_failures=history,
K=K
)
# 5. Mask/layout preparation
condition_package = make_condition_package(
canvas=canvas,
masks=masks,
references=reference_images,
layout_hint=layout_hint,
scene_plan=scene_plan
)
round_candidates = []
for prompt in prompt_list:
# 6. Generator routing
gen_request = route_model(
prompt=prompt,
condition_package=condition_package,
models=models,
scene_plan=scene_plan,
budget=budget
)
raw = call_commercial_generator(gen_request)
# 7. Hard foreground restoration
restored = restore_foreground(
raw_image=raw.image,
foreground_rgb=asset.fg_rgb,
alpha_core=masks.alpha_core,
alpha_soft=masks.alpha_soft
)
# 8. Optional boundary/contact refinement
refined = maybe_refine_boundary_contact(
restored=restored,
raw=raw.image,
asset=asset,
masks=masks,
scene_plan=scene_plan,
budget=budget
)
# 9. Critic scoring
score_report = critic_score(
original_foreground=asset.fg_rgb,
alpha=asset.alpha,
raw_image=raw.image,
final_image=refined,
user_prompt=user_prompt,
scene_plan=scene_plan,
fg_info=fg_info
)
candidate = {
"final": refined,
"raw": raw.image,
"prompt": prompt,
"model": raw.model_name,
"score": score_report,
"metadata": raw.metadata
}
round_candidates.append(candidate)
history.append(candidate)
# 10. Rerank
round_candidates.sort(
key=lambda c: c["score"]["scores"]["overall"],
reverse=True
)
if best is None or round_candidates[0]["score"]["scores"]["overall"] > best["score"]["scores"]["overall"]:
best = round_candidates[0]
# 11. Stop or repair
if should_accept(best["score"]):
break
repair_action = repair_planner(
best_score=best["score"],
history=history,
scene_plan=scene_plan,
masks=masks
)
scene_plan, masks, canvas, models = apply_repair_action(
repair_action,
scene_plan,
masks,
canvas,
models
)
# 12. Export
return export_result(best, asset, masks, history)
```
---
## 16. `report.json` 设计
每次输出必须可复查、可复现。
```json
{
"task_id": "fci_20260602_0001",
"input": {
"foreground_path": "foreground.png",
"alpha_path": "alpha.png",
"user_prompt": "rainy Tokyo street at night",
"canvas_size": [1536, 1024]
},
"models": [
{
"name": "gpt-image-2-2026-04-21",
"role": "masked_background_generator",
"requests": 8
},
{
"name": "gemini-3.1-flash-image",
"role": "multi_reference_generator",
"requests": 4
}
],
"foreground_analysis": {},
"scene_plan": {},
"masks": {
"alpha_core": "alpha_core.png",
"alpha_soft": "alpha_soft.png",
"background_edit": "mask_bg.png",
"boundary_ring": "mask_ring.png",
"contact": "mask_contact.png"
},
"best_candidate": {
"candidate_id": 5,
"model": "gpt-image-2-2026-04-21",
"prompt": "...",
"score": {
"foreground_preservation": 5,
"prompt_alignment": 4,
"spatial_rationality": 5,
"lighting_harmony": 4,
"boundary_quality": 4,
"aesthetic_quality": 4,
"overall": 4.55
},
"failure_tags": []
},
"all_candidates": [
{
"candidate_id": 0,
"model": "...",
"prompt": "...",
"raw_path": "...",
"final_path": "...",
"score": {},
"failure_tags": ["missing_shadow"]
}
],
"export": {
"final_composite": "final.png",
"background": "background.png",
"foreground": "foreground.png",
"alpha": "alpha.png",
"contact_shadow": "shadow.png"
}
}
```
---
## 17. 实验设计
### 17.1 Baselines
必须包含以下 baseline:
| Baseline | 描述 |
|---|---|
| `GPT-raw` | 直接 GPT-image-2 masked edit,不重贴前景 |
| `GPT+Restore` | GPT-image-2 + 原前景强制复合 |
| `GPT+Restore+Rerank` | 生成 K 个候选后 rerank |
| `GPT+Restore+Refine` | 加 boundary/contact refinement |
| `GPT-Agent` | 完整 repair loop |
| `Nano-raw` | Nano Banana 多参考图直接编辑 |
| `Nano+Restore` | Nano Banana + 原前景复合 |
| `Nano-Agent` | Nano Banana + critic + repair |
| `Hybrid-Agent` | GPT 做显式 mask edit,Nano 做复杂多参考或风格候选 |
| `Open-source Inpainting` | BrushNet / PowerPaint / SD inpainting / Pinco 等 |
### 17.2 Ablation
重点消融:
```text
w/o foreground restoration
w/o boundary ring
w/o contact refinement
w/o prompt planner
w/o prompt ensemble
w/o VLM critic
w/o repair loop
GPT-only vs Nano-only vs Hybrid
K=1 vs K=4 vs K=8 vs K=16
T=1 vs T=2 vs T=3
```
### 17.3 Benchmark 组成
建议构造 **Commercial-FCI-Bench**:
| 类别 | 样本数建议 | 难点 |
|---|---:|---|
| 商品硬边 | 100 | logo、文字、反射、接触阴影 |
| 人像 | 100 | 脸、手、头发、衣服纹理 |
| 动物 | 80 | 毛发、地面接触 |
| 车辆 | 60 | 轮胎接触、尺度、透视 |
| 家具 | 60 | 支撑脚、室内透视 |
| 透明/反光物 | 60 | 玻璃、金属、反射 |
| 复杂边界 | 60 | 羽毛、树枝、蕾丝 |
| 多前景 | 80 | 相对位置、遮挡、尺度 |
每个前景配 5 个背景 prompt:
```text
studio product photography
outdoor natural scene
night city / rainy street
luxury commercial advertisement
indoor table/floor scene
```
### 17.4 主指标
| 指标 | 说明 |
|---|---|
| Human Preference Win Rate | 与 baseline 成对比较 |
| Foreground Preservation Score | 人工/VLM + raw foreground deviation |
| Prompt Alignment Score | VLM/CLIP/human |
| Spatial Rationality Score | 是否漂浮、尺度、透视、接触 |
| Boundary Quality Score | halo、硬边、融合自然度 |
| Lighting Harmony Score | 阴影方向、色温、反射 |
| Diversity | 同一前景同一 prompt 下合理候选多样性 |
| Cost-quality curve | API 成本/延迟 vs 质量 |
不要只用 FID。该任务的核心不是整体图像分布,而是条件一致性、空间合理性和前景保持。
---
## 18. 工程实现建议
### 18.1 代码结构
```text
commercial_fci_agent/
configs/
default.yaml
gpt_image_2.yaml
nano_banana.yaml
eval.yaml
core/
asset_normalizer.py
mask_builder.py
canvas_builder.py
compositor.py
shadow_refiner.py
agents/
foreground_analyzer.py
scene_planner.py
prompt_ensemble.py
critic.py
repair_planner.py
generators/
base.py
openai_gpt_image.py
google_nano_banana.py
router.py
eval/
metrics.py
vlm_eval.py
human_eval_export.py
pipelines/
run_single.py
run_batch.py
run_benchmark.py
schemas/
request.py
result.py
report.py
outputs/
```
### 18.2 配置示例
```yaml
canvas:
width: 1536
height: 1024
background: neutral_gray
align_to_multiple: 16
mask:
threshold: 0.5
r_core: 3
r_dilate: 8
sigma: 1.0
contact_radius: 80
generation:
K: 8
T: 2
models:
- gpt-image-2-2026-04-21
- gemini-3.1-flash-image
quality: high
max_parallel_requests: 4
rerank:
accept_threshold: 4.2
weights:
foreground_preservation: 0.25
prompt_alignment: 0.20
spatial_rationality: 0.25
lighting_harmony: 0.15
boundary_quality: 0.10
aesthetic_quality: 0.05
repair:
enable: true
max_rounds: 2
enable_boundary_refine: true
switch_model_on_repeated_failure: true
export:
save_raw_candidates: true
save_masks: true
save_report_json: true
```
### 18.3 API 成本与并发
开发时要把 candidate generation 做成异步队列:
```text
Queue:
task_id
candidate_id
model
prompt
mask
canvas
status
retry_count
result_path
request_id
```
推荐:
```text
Preview mode:
K=4, quality=medium/auto, T=1
Production mode:
K=8, quality=high, T=2
Offline benchmark:
K=16, quality=high, T=2~3
```
### 18.4 版本锁定
尽量记录:
```text
model snapshot
API date
SDK version
prompt template version
mask builder version
critic prompt version
```
闭源模型会更新。如果 API 支持 snapshot,应优先使用 snapshot 以提高实验复现性。
---
## 19. 失败模式与解决策略
| 失败 | 原因 | 解决 |
|---|---|---|
| 前景被改 | 商业模型重画主体 | 强制复合;扩大 A_core;prompt 加 preserve constraints |
| logo/文字变形 | 模型生成式重绘 | logo 区硬保护;critic 单独检查 |
| 主体漂浮 | 缺接触阴影/地面 | contact refinement;scene plan 加 support surface |
| 尺度不对 | prompt 参照不足 | 加真实尺寸、镜头、参照物 |
| 透视不对 | 没有 horizon/camera | layout guide + camera prompt |
| 阴影方向错 | 背景光照与前景不一致 | Foreground Analyzer 提取光照,repair prompt 指定 |
| halo 白边 | alpha/mask 边界差 | A_ring 软融合;color decontamination |
| 背景过乱 | prompt 过开放 | minimal/conservative prompt |
| 出现复制主体 | 模型把前景当 prompt 对象 | negative constraints + mask guide + rerank |
| 多轮编辑漂移 | conversation edit 累积误差 | 每轮都从原始前景和原始 canvas 重新生成,而不是连续改最终图 |
---
## 20. 推荐论文结构
```text
Title:
Commercial-FCI-Agent: Training-Free Foreground-Conditioned Inpainting with Commercial Multimodal Image Models
Abstract
1. Introduction
- Foreground-conditioned inpainting 的实用价值
- 开源模型训练成本高,闭源模型强但不可控
- 我们提出 agentic black-box protocol
2. Related Work
- Text-guided inpainting
- Foreground-conditioned inpainting: Anywhere, Pinco, InpaintDPO
- Commercial multimodal image models
- VLM-based evaluation and agentic generation
3. Problem Formulation
- 输入输出
- 前景保持、背景一致性、空间合理性
4. Method
4.1 Asset normalization and mask decomposition
4.2 Foreground analyzer
4.3 Scene planner
4.4 Commercial generator router
4.5 Alpha-aware foreground restoration
4.6 Critic-guided reranking and repair
5. Benchmark and Metrics
- Commercial-FCI-Bench
- 主客观指标
6. Experiments
- Baselines
- Quantitative results
- Human preference
- Ablation
- Cost-quality tradeoff
7. Limitations
- 闭源不可复现性
- API 成本
- 安全策略和可用性
- 极复杂透明/反射/多物体仍困难
8. Conclusion
```
---
## 21. 最小可行产品版本
MVP 只需要做:
```text
1. 输入 RGBA 前景 + prompt
2. 构造 canvas 和 background mask
3. 调 GPT-image-2 masked edit 生成 K=4 候选
4. 用原始 alpha 强制贴回前景
5. 用 VLM critic 打分
6. 返回最高分 final.png + report.json
```
MVP 的价值已经很强,因为它能证明:
```text
raw commercial model < commercial model + foreground restoration < commercial model + restoration + rerank
```
---
## 22. 开发里程碑
### Milestone 1:单模型可跑通
- 支持 RGBA 输入。
- GPT-image-2 masked edit。
- 前景强制复合。
- 输出 final 和 report。
- 人工检查 20 个样本。
### Milestone 2:critic 和 rerank
- K=8 候选。
- VLM critic JSON。
- 自动排序。
- 输出 candidate grid 和分数表。
### Milestone 3:repair loop
- failure tags。
- prompt repair。
- contact-shadow refinement。
- halo 修复。
- T=2 自动迭代。
### Milestone 4:Nano Banana adapter
- mask visualization 输入。
- 多参考图输入。
- GPT vs Nano vs Hybrid 对比。
### Milestone 5:benchmark
- 500–800 个前景。
- 每个 5 个 prompt。
- Human preference 标注。
- ablation 和 cost-quality curve。
---
## 23. 实现原则
1. **永远保存原始前景并最终重贴。**
不要相信闭源模型会严格保护前景。
2. **让商业模型生成背景,而不是决定最终图。**
它是 candidate generator,不是 constraint solver。
3. **把 foreground preservation、spatial rationality、boundary quality 分开评估。**
单一美学分数会掩盖漂浮、尺度错误、logo 改写等关键问题。
4. **从第一天就记录 `report.json`。**
没有日志就无法写论文,也无法定位失败。
5. **每轮 repair 从原始前景和原始 canvas 重新开始。**
不要在已漂移的图上连续编辑,否则错误会累积。
6. **把 prompt、mask、layout 和模型版本都当作实验变量记录。**
这对复现、ablation 和成本分析都很重要。
---
## 24. 一句话版方法
> **Commercial-FCI-Agent treats commercial multimodal image models as black-box background proposal generators, then enforces foreground preservation through alpha-aware restoration and improves spatial realism through VLM-guided reranking, failure diagnosis, and iterative repair.**
这套方法最 promising 的地方在于:它不和 GPT-image-2 / Nano Banana 比拼底层生成能力,而是利用它们的强生成能力,同时用系统设计补齐闭源模型在 **精确前景保护、空间关系可靠性、可复现评测和产品级可控性** 上的短板。
---
## 25. 参考资料
以下参考资料用于定位相关工作与商业模型能力。具体 API 参数、模型名称和可用能力会更新,工程实现时应以官方最新文档为准。
1. OpenAI GPT-image-2 model documentation
<https://developers.openai.com/api/docs/models/gpt-image-2>
2. OpenAI Image generation and image edit guide
<https://developers.openai.com/api/docs/guides/image-generation>
3. Google Gemini image generation / Nano Banana documentation
<https://ai.google.dev/gemini-api/docs/image-generation>
4. Anywhere: A Multi-Agent Framework for Reliable and Diverse Foreground-Conditioned Image Generation
<https://arxiv.org/abs/2404.18598>
5. Pinco: Position-induced Consistent Adapter for Diffusion Transformer in Foreground-conditioned Inpainting
<https://openaccess.thecvf.com/content/ICCV2025/html/Lu_Pinco_Position-induced_Consistent_Adapter_for_Diffusion_Transformer_in_Foreground-conditioned_Inpainting_ICCV_2025_paper.html>
6. InpaintDPO: Spatial Relationship Hallucinations in Image Inpainting
<https://arxiv.org/abs/2512.15644>
7. BrushNet: A Plug-and-Play Image Inpainting Model
<https://arxiv.org/abs/2403.06976>
8. PowerPaint: A Versatile Image Inpainting Model
<https://powerpaint.github.io/>
9. LayerDiffuse: Transparent Image Layer Diffusion
<https://arxiv.org/abs/2402.17113>
10. LASAGNA: Layered Scene Generation with Visual Effects
<https://arxiv.org/abs/2601.15507>
|