# 图像修复（图像处理）

[图像修复](https://www.edgepedia.org/zh/image-inpainting)是一类图像处理与计算机视觉方法，通过从周围像素或从生成模型学到的先验中合成合理内容，来填补图像中缺失或损坏的区域。已述应用包括修复老照片和受损胶片、去除日期或字幕等叠加文字，以及去除特效中的麦克风或线缆等整个物体。<sup>[1](https://dl.acm.org/doi/10.1145/344779.344972)</sup> 更广泛的应用列表还包括文物修复、遮挡物去除、文字擦除、水印去除和老照片修复。<sup>[2](https://www.mdpi.com/2073-8994/18/1/94)</sup> 关于数字图像修复的大量文献大致可分为三类：基于图像块的、学习生成式的，以及偏微分方程/变分方法。<sup>[3](http://math.univ-lyon1.fr/homes-www/masnou/fichiers/publications/survey.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出 | 一幅完成后的图像，其中掩码区域包含与其周围环境一致的合成内容<sup>[1](https://dl.acm.org/doi/10.1145/344779.344972)</sup> |
| 方法家族 | 偏微分方程/变分、基于图像块、学习生成式（CNN、GAN、Transformer、扩散）<sup>[3](http://math.univ-lyon1.fr/homes-www/masnou/fichiers/publications/survey.pdf)</sup><sup> • </sup><sup>[4](https://link.springer.com/article/10.1007/s11263-023-01977-6)</sup> |
| 传播粒度 | 偏微分方程方法逐像素传播信息；样例方法逐块传播信息<sup>[5](https://iopscience.iop.org/article/10.1088/1742-6596/1818/1/012149/pdf)</sup> |
| 标准指标 | PSNR 和 SSIM（基于像素）；LPIPS 和 FID（感知），在 Places2、CelebA-HQ 和 PSV 上评估<sup>[6](https://link.springer.com/article/10.1007/s10462-024-11075-9)</sup> |
| 实际掩码上限 | 一旦损坏面积超过约 70%，深度 CNN、VAE 和 GAN 方法便难以准确修复<sup>[7](https://www.mdpi.com/2076-3417/13/20/11189)</sup> |
| 扩散控制 | 无分类器引导尺度通常在 1 到 7.5 之间<sup>[8](https://arxiv.org/html/2402.17525v3)</sup> |

## 工作原理

**基于偏微分方程的图像修复**将填充视为一个传播问题。原始算法完成到达孔洞边界的等照度线（等值曲线），将结构延伸到损坏区域，而无需用户输入关于新信息来自何处的信息。<sup>[1](https://dl.acm.org/doi/10.1145/344779.344972)</sup> 其稳态方程 \( \nabla^{\perp} u \cdot \nabla \Delta u = 0 \)，正是二维不可压缩纳维-斯托克斯模型中稳态无粘流所满足的方程。<sup>[3](http://math.univ-lyon1.fr/homes-www/masnou/fichiers/publications/survey.pdf)</sup> 变分方法则改为在损坏图像上最小化一个泛函，并从欧拉-拉格朗日方程推导出填充偏微分方程。<sup>[5](https://iopscience.iop.org/article/10.1088/1742-6596/1818/1/012149/pdf)</sup>

**样例方法**进行复制：它们通过匹配和复制已知区域中的相似图像块来恢复未知区域。<sup>[4](https://link.springer.com/article/10.1007/s11263-023-01977-6)</sup> 这能产生良好的纹理，但结构混乱，且最近邻图像块搜索代价高昂。<sup>[9](https://arxiv.org/html/2208.03382v2)</sup> 一种混合思路将图像分解为有界变差结构分量（用偏微分方程修复）和纹理分量（用埃弗罗斯-梁式纹理合成填充），然后将两者相加还原。<sup>[10](https://www.math.ucla.edu/~lvese/PAPERS/01217265.pdf)</sup>

**学习方法**在掩码去噪或重建目标上训练网络。扩散模型学习逆转一个前向加噪过程：采样从高斯噪声 \( z_{T} \) 开始，迭代采样 \( z_{t-1} \)（\( t = T, \ldots, 1 \)），直到到达 \( z_{0} \)，即编辑后的图像，逆向转移 \( p_{\theta}(z_{t-1} \mid z_{t}) \) 由 UNet 参数化。<sup>[8](https://arxiv.org/html/2402.17525v3)</sup>

## 如何操作

使用者提供一幅图像和一个标记待填充区域的掩码；掩码可以是矩形、自由形状，或由分割得出。架构分为仅使用受损图像的盲式单流网络，以及需要掩码的多流网络——后者接收掩码以及边缘图、语义分割或参考图像等可选输入。<sup>[6](https://link.springer.com/article/10.1007/s10462-024-11075-9)</sup> 对于文本引导的扩散修复，噪声估计网络 \( \varepsilon_{\theta}(z_{t}, t, C) \) 预测噪声，其中 \( C = \psi(P) \) 是文本嵌入，无分类器引导以引导尺度 \( w \)（通常在 \( [1, 7.5] \) 内）组合条件预测和无条件预测。<sup>[8](https://arxiv.org/html/2402.17525v3)</sup> 基于 GAN 的自由形状系统（如门控卷积网络）默认以逐像素 \( \ell_{1} \) 损失和对抗损失按 1:1 平衡训练。<sup>[11](https://ar5iv.labs.arxiv.org/html/1806.03589)</sup> 最后的混合步骤可以改善边界连贯性：BrushNet 模糊掩码，并在像素空间中通过模糊掩码进行复制粘贴。<sup>[12](https://www.ecva.net/papers/eccv_2024/papers_ECCV/papers/03014.pdf)</sup>

## 起源

图像处理语境中的“图像修复”一词以及偏微分方程填充算法，由马塞洛·贝尔塔尔米奥（Marcelo Bertalmío）、吉列尔莫·萨皮罗（Guillermo Sapiro）、维森特·卡塞列斯（Vicent Caselles）和科洛马·巴列斯特尔（Coloma Ballester）在 2000 年 SIGGRAPH 论文中提出，其提出灵感来自真实的绘画修复；存档版本可通过明尼苏达大学数字资源保存库获取。<sup>[1](https://dl.acm.org/doi/10.1145/344779.344972)</sup><sup> • </sup><sup>[3](http://math.univ-lyon1.fr/homes-www/masnou/fichiers/publications/survey.pdf)</sup> 更早的工作以“图像去遮挡”之名处理同一问题，在电信领域则称为丢失图像块的“错误隐藏”。<sup>[3](http://math.univ-lyon1.fr/homes-www/masnou/fichiers/publications/survey.pdf)</sup> 非参数采样[纹理合成](https://www.edgepedia.org/zh/texture-synthesis)作为早期基于图像块的前身，归功于埃弗罗斯和梁（1999）。<sup>[4](https://link.springer.com/article/10.1007/s11263-023-01977-6)</sup> 贝尔塔尔米奥、韦塞、萨皮罗和奥舍于 2003 年在《IEEE 图像处理汇刊》上发表了同时进行结构与纹理分解的方法。<sup>[10](https://www.math.ucla.edu/~lvese/PAPERS/01217265.pdf)</sup> 两篇 2004 年的论文仍是标准参考文献：克里米尼西、佩雷斯和托亚马的基于样例的区域填充与物体去除，<sup>[13](https://doi.org/10.1109/tip.2004.833105)</sup> 以及 特莱亚在《图形工具杂志》上的快速行进方法技术。<sup>[14](https://doi.org/10.1080/10867651.2004.10487596)</sup> 深度学习的转折始于上下文编码器——一个卷积网络，训练其利用重建加对抗损失从周围环境生成任意区域的内容，<sup>[15](https://openaccess.thecvf.com/content_cvpr_2016/html/Pathak_Context_Encoders_Feature_CVPR_2016_paper.html)</sup> 以及通过搜索深度生成模型潜在空间进行的语义修复。<sup>[16](https://doi.org/10.48550/arxiv.1607.07539)</sup>

## 变体

**经典与 GAN 时代。** 纳维-斯托克斯图像修复将图像强度视为流体流动，等照度线为流线；已发表文献对于它是独立方法还是贝尔塔尔米奥传输方程的稳态形式存在分歧，一篇综述报告其计算时间从几分钟改善到几秒，但求解质量没有提高。<sup>[3](http://math.univ-lyon1.fr/homes-www/masnou/fichiers/publications/survey.pdf)</sup> PatchMatch 是一种随机化对应算法，用于近似最近邻图像块匹配，比先前最先进技术快 20-100 倍，支持包括图像补全在内的交互式编辑工具。<sup>[17](https://dl.acm.org/doi/10.1145/3596711.3596777)</sup> 部分卷积将卷积限制在有效像素上以处理不规则孔洞。<sup>[18](https://doi.org/10.48550/arxiv.1804.07723)</sup> 门控卷积用学习到的逐通道、逐位置门控替代该固定规则，\( g = \sigma(w_{g} \cdot x) \)，\( y = \phi(w \cdot x) \odot g \)，并与 SN-PatchGAN 判别器配对。<sup>[11](https://ar5iv.labs.arxiv.org/html/1806.03589)</sup> GMCNN 使用三个具有不同感受野的并行编码器-解码器分支，外加隐式多样化[马尔可夫随机场](https://www.edgepedia.org/zh/markov-random-field)损失。<sup>[19](https://doi.org/10.48550/arxiv.1810.08771)</sup> CoModGAN 以调制随机噪声为条件驱动 StyleGAN2 处理大孔洞，但在基于纹理的图像上表现不佳。<sup>[9](https://arxiv.org/html/2208.03382v2)</sup>

**大掩码专家。** LaMa 使用快速傅里叶卷积捕捉重复模式，其最接近的基线 CoModGAN 和 MADF 使用的参数量分别约为其 4 倍和 3 倍。<sup>[20](https://openaccess.thecvf.com/content/WACV2022/papers/Suvorov_Resolution-Robust_Large_Mask_Inpainting_With_Fourier_Convolutions_WACV_2022_paper.pdf)</sup> GLaMa 增加了联合空间与频率损失。<sup>[21](https://doi.org/10.48550/arxiv.2205.07162)</sup> MAT 是一种面向大孔洞的掩码感知 Transformer。<sup>[22](https://doi.org/10.48550/arxiv.2203.15270)</sup> ZITS++ 将 Transformer 结构恢复器与傅里叶-CNN 纹理恢复器结合，使用零初始化残差加法处理大不规则掩码。<sup>[23](https://doi.org/10.1109/tpami.2023.3280222)</sup>

**扩散模型。** RePaint 复用预训练的 DDPM，从模型采样掩码区域，从给定图像采样非掩码区域。<sup>[24](https://doi.org/10.48550/arxiv.2201.09865)</sup> 潜在扩散模型降低训练成本，并支持 1024 × 1024 分辨率的修复。<sup>[25](https://doi.org/10.48550/arxiv.2112.10752)</sup> Stable Diffusion Inpainting 微调一个扩散模型，其 UNet 接收掩码、加掩码后的图像和含噪潜在表示作为输入；SmartBrush 增加物体掩码预测，以边界信息引导采样。<sup>[12](https://www.ecva.net/papers/eccv_2024/papers_ECCV/papers/03014.pdf)</sup> 相关的文本引导系统包括 Imagen Editor 与 EditBench 基准、<sup>[26](https://doi.org/10.48550/arxiv.2212.06909)</sup> HD-Painter、<sup>[27](https://doi.org/10.48550/arxiv.2312.14091)</sup> Uni-paint、<sup>[28](https://doi.org/10.48550/arxiv.2310.07222)</sup> 和 DAFT-GAN。<sup>[29](https://doi.org/10.48550/arxiv.2408.04962)</sup>

## 应用

除了照片和胶片修复、文字与物体去除以及消费级编辑工具之外，<sup>[1](https://dl.acm.org/doi/10.1145/344779.344972)</sup><sup> • </sup><sup>[2](https://www.mdpi.com/2073-8994/18/1/94)</sup> 图像修复还用于遗产科学：在模拟真实损坏的壁画上，基于扩散的方法通常优于 LaMa，例如在“霉变”损坏上，RePaint 的 SSIM 为 0.901、LPIPS 为 0.043，而 LaMa 为 0.853 和 0.059。<sup>[30](http://www.nature.com/articles/s40494-025-02275-9/tables/1)</sup> 高分辨率流水线将任务扩展到 4K 内容及以上，在一个已报告系统中高达 6200 万像素。<sup>[31](https://www.ecva.net/papers/eccv_2022/papers_ECCV/papers/136770051.pdf)</sup> 在现代相机分辨率下，一个深度网络加引导 PatchMatch 的混合流水线在 FID、P-IDS 和 U-IDS 上以 2.3 到 7.4 倍的幅度优于 LaMa，使用了一个包含 1045 张 4K 或以上照片的数据集。<sup>[31](https://www.ecva.net/papers/eccv_2022/papers_ECCV/papers/136770051.pdf)</sup>

## 局限与替代方案

每个方法家族以不同方式失败。偏微分方程方法对线条和曲线等细孔洞效果良好，但对结构模糊的较大孔洞会产生模糊；TV 和调和修复等二阶偏微分方程无法恢复边缘和角点，而 Euler-Elastica 等高阶方法（其欧拉-拉格朗日方程为四阶）则能成功，且所有偏微分方程和变分方法都难以处理大面积纹理区域。<sup>[9](https://arxiv.org/html/2208.03382v2)</sup> 图像块方法产生良好的纹理，但结构混乱且搜索代价高昂。<sup>[9](https://arxiv.org/html/2208.03382v2)</sup> 当缺失区域变得广泛且连续时，部分卷积可能产生损坏的结构，并且在跨越天空和地面两个分段的大孔洞上失败。<sup>[7](https://www.mdpi.com/2076-3417/13/20/11189)</sup><sup> • </sup><sup>[11](https://ar5iv.labs.arxiv.org/html/1806.03589)</sup> 随着孔洞增大并跨越物体边界，LaMa 会产生逐渐淡出的结构。<sup>[9](https://arxiv.org/html/2208.03382v2)</sup> GAN 训练容易出现模式崩溃或模糊，<sup>[6](https://link.springer.com/article/10.1007/s10462-024-11075-9)</sup> 扩散模型采样缓慢，尽管少步蒸馏在很大程度上克服了这一点：TurboFill（2025）在 DMD2 蒸馏的文本到图像模型上训练修复适配器，采用 3 步对抗方案实现高质量、高效的修复。<sup>[2](https://www.mdpi.com/2073-8994/18/1/94)</sup><sup> • </sup><sup>[9](https://arxiv.org/html/2208.03382v2)</sup> 超过约 70% 的损坏面积后，基于 CNN、VAE 和 GAN 的方法缺乏足够的已知信息进行准确修复，尽管研究表明即使遮挡图像 75% 后修复仍可能实现，这反映了图像中的冗余性。<sup>[7](https://www.mdpi.com/2076-3417/13/20/11189)</sup> 分辨率泛化也区分方法：LaMa 泛化到约 2K，ProFill 到 1K，而该基准中评估的早期深度方法仅到 512 × 512。<sup>[31](https://www.ecva.net/papers/eccv_2022/papers_ECCV/papers/136770051.pdf)</sup>

## References

1. [Image inpainting (SIGGRAPH '00)](https://dl.acm.org/doi/10.1145/344779.344972)
2. [Image Inpainting Methods: A Review of Deep Learning Approaches](https://www.mdpi.com/2073-8994/18/1/94)
3. [Inpainting (Masnou survey)](http://math.univ-lyon1.fr/homes-www/masnou/fichiers/publications/survey.pdf)
4. [Deep Learning-Based Image and Video Inpainting: A Survey (IJCV)](https://link.springer.com/article/10.1007/s11263-023-01977-6)
5. [A Review of PDE Based Local Inpainting Methods](https://iopscience.iop.org/article/10.1088/1742-6596/1818/1/012149/pdf)
6. [Transformer-based image and video inpainting: current challenges and future directions (Artificial Intelligence Review)](https://link.springer.com/article/10.1007/s10462-024-11075-9)
7. [A Review of Image Inpainting Methods Based on Deep Learning (Applied Sciences)](https://www.mdpi.com/2076-3417/13/20/11189)
8. [Diffusion Model-Based Image Editing: A Survey](https://arxiv.org/html/2402.17525v3)
9. [Keys to Better Image Inpainting: Structure and Texture Go Hand in Hand (FcF)](https://arxiv.org/html/2208.03382v2)
10. [Simultaneous structure and texture image inpainting (IEEE TIP 2003)](https://www.math.ucla.edu/~lvese/PAPERS/01217265.pdf)
11. [Free-Form Image Inpainting with Gated Convolution (DeepFill v2, arXiv 1806.03589)](https://ar5iv.labs.arxiv.org/html/1806.03589)
12. [BrushNet: A Plug-and-Play Image Inpainting Model with Decomposed Dual-Branch Diffusion (ECCV 2024)](https://www.ecva.net/papers/eccv_2024/papers_ECCV/papers/03014.pdf)
13. [A. Criminisi, P. Perez, K. Toyama (2004). Region Filling and Object Removal by Exemplar-Based Image Inpainting. IEEE Transactions on Image Processing.](https://doi.org/10.1109/tip.2004.833105)
14. [Alexandru Telea (2004). An Image Inpainting Technique Based on the Fast Marching Method. Journal of Graphics Tools.](https://doi.org/10.1080/10867651.2004.10487596)
15. [Context Encoders: Feature Learning by Inpainting (CVPR 2016)](https://openaccess.thecvf.com/content_cvpr_2016/html/Pathak_Context_Encoders_Feature_CVPR_2016_paper.html)
16. [Yeh, Raymond A. and colleagues (2016). Semantic Image Inpainting with Deep Generative Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1607.07539)
17. [PatchMatch: A Randomized Correspondence Algorithm for Structural Image Editing (reprint in Seminal Graphics Papers, 2023)](https://dl.acm.org/doi/10.1145/3596711.3596777)
18. [Liu, Guilin and colleagues (2018). Image Inpainting for Irregular Holes Using Partial Convolutions. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1804.07723)
19. [Wang, Yi and colleagues (2018). Image Inpainting via Generative Multi-column Convolutional Neural Networks. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1810.08771)
20. [Resolution-Robust Large Mask Inpainting With Fourier Convolutions (LaMa)](https://openaccess.thecvf.com/content/WACV2022/papers/Suvorov_Resolution-Robust_Large_Mask_Inpainting_With_Fourier_Convolutions_WACV_2022_paper.pdf)
21. [Lu, Zeyu and colleagues (2022). GLaMa: Joint Spatial and Frequency Loss for General Image Inpainting. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2205.07162)
22. [Li, Wenbo and colleagues (2022). MAT: Mask-Aware Transformer for Large Hole Image Inpainting. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2203.15270)
23. [Chenjie Cao, Qiaole Dong, Yanwei Fu (2023). ZITS++: Image Inpainting by Improving the Incremental Transformer on Structural Priors. IEEE Transactions on Pattern Analysis and Machine Intelligence.](https://doi.org/10.1109/tpami.2023.3280222)
24. [Lugmayr, Andreas and colleagues (2022). RePaint: Inpainting using Denoising Diffusion Probabilistic Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2201.09865)
25. [Rombach, Robin and colleagues (2021). High-Resolution Image Synthesis with Latent Diffusion Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2112.10752)
26. [Wang, Su and colleagues (2022). Imagen Editor and EditBench: Advancing and Evaluating Text-Guided Image Inpainting. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2212.06909)
27. [Manukyan, Hayk and colleagues (2023). HD-Painter: High-Resolution and Prompt-Faithful Text-Guided Image Inpainting with Diffusion Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2312.14091)
28. [Yang, Shiyuan, Chen, Xiaodong, Liao, Jing (2023). Uni-paint: A Unified Framework for Multimodal Image Inpainting with Pretrained Diffusion Model. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2310.07222)
29. [Lee, Jihoon and colleagues (2024). DAFT-GAN: Dual Affine Transformation Generative Adversarial Network for Text-Guided Image Inpainting. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2408.04962)
30. [Quantitative comparison of inpainting on damaged murals (Heritage Science, Nature)](http://www.nature.com/articles/s40494-025-02275-9/tables/1)
31. [Inpainting at Modern Camera Resolution by Guided PatchMatch (ECCV 2022)](https://www.ecva.net/papers/eccv_2022/papers_ECCV/papers/136770051.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026; Oct 21, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Language and vision AI › Computer vision › Vision methods and geometry › Low-level image analysis

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/inpainting-image-processing

English original: https://www.edgepedia.org/inpainting-image-processing
