# 非局部均值

非局部均值（NL-means）是一种图像去噪算法，它将每个像素估计为图像中许多像素的加权平均，权重由这些像素周围小图像块的相似度决定。该算法旨在克服局部邻域滤波器的局限，例如SUSAN滤波器（1995年）和[双边滤波器](https://www.edgepedia.org/zh/bilateral-filter)（1998年），这些滤波器在固定的空间邻域内运作，双边滤波器同时以空间距离和与参考像素的强度相似度进行加权；而NL-means则比较图像块，并可能搜索更远的区域。<sup>[1](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)</sup> 由于与给定像素最相似的像素未必在空间上接近，该算法可能会扫描图像的大部分区域以寻找相似窗口，故称“非局部”。<sup>[1](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)</sup><sup> • </sup><sup>[2](https://www.ipol.im/pub/art/2011/bcm_nlm/article.pdf)</sup> 该方法利用了自然图像的高度冗余性：自然图像中的每个小窗口在同一图像的其他位置都有许多相似窗口。<sup>[3](https://link.springer.com/rwe/10.1007/978-3-642-27795-5_26-5)</sup>

| 关键事实 | 值 |
|---|---|
| 估计方式 | 所有像素的加权平均，权重来自图像块相似度<sup>[1](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)</sup> |
| 权重函数 | \( w(p,q) = \exp(-\max(d^2 - 2\sigma^2, 0)/h^2) \)<sup>[2](https://www.ipol.im/pub/art/2011/bcm_nlm/article.pdf)</sup> |
| 原始参数 | 7×7相似性图像块，21×21搜索窗口<sup>[1](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)</sup> |
| 原始复杂度 | 对于\( N^2 \)像素的图像，约为\( 49 \times 441 \times N^2 \)<sup>[1](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)</sup> |
| 提出者 | A. Buades, B. Coll, J.-M. Morel, CVPR 2005<sup>[4](https://bishtref.com/articles/10.1109/cvpr.2005.38)</sup> |
| 滤波参数 | \( h = k\sigma \)，参考实现中\( k \)介于0.30与0.55之间<sup>[2](https://www.ipol.im/pub/art/2011/bcm_nlm/article.pdf)</sup> |
| 最强的经典竞争者 | BM3D（块匹配、变换阈值化、维纳滤波）<sup>[5](https://www.math.ucdavis.edu/~saito/data/acha.read.s11/buades-coll-morel-siamrev.pdf)</sup> |

## 工作原理

对于含噪图像\( v \)，像素\( i \)处的去噪值为加权平均\( \mathrm{NL}v(i) = \sum_{j \in I} w(i,j)\, v(j) \)，对图像中所有像素\( j \)求和（实际中在搜索窗口内求和）。<sup>[1](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)</sup> 相似度是在整个邻域之间度量的，而非单一强度：在作者的综述表述中，\( \mathrm{NL}(u)(x) = \frac{1}{C(x)} \int e^{-(G_a * |u(x+\cdot) - u(y+\cdot)|^2)(0)/h^2}\, u(y)\, dy \)，其中\( G_a \)是标准差为\( a \)的高斯核，\( h \)是滤波参数，\( C(x) \)对权重进行归一化。<sup>[5](https://www.math.ucdavis.edu/~saito/data/acha.read.s11/buades-coll-morel-siamrev.pdf)</sup> IPOL参考实现使用\( w(p,q) = \exp(-\max(d^2 - 2\sigma^2, 0)/h^2) \)，其中\( d^2 \)是图像块距离的平方，\( \sigma \)是噪声标准差；平方距离低于\( 2\sigma^2 \)的图像块获得权重1，因为这样的差异仅可归因于噪声。<sup>[2](https://www.ipol.im/pub/art/2011/bcm_nlm/article.pdf)</sup>

由于指数核衰减很快，大的欧几里得图像块距离产生近乎为零的权重，起到自动阈值的作用。<sup>[1](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)</sup> 参考像素自身的权重设为其邻域内权重的最大值，从而避免在平均中自身权重过大。<sup>[2](https://www.ipol.im/pub/art/2011/bcm_nlm/article.pdf)</sup> 比较整个图像块而非单个像素，正是该滤波器能够从纹理图像中去除噪声而不破坏精细纹理结构的原因。<sup>[6](https://cvg.cit.tum.de/_media/spezial/bib/brox_cremers_ssvm07_denoising.pdf)</sup>

## 实现方式

原始实验使用7×7的相似性邻域和21×21的搜索窗口，对于标准差为\( \sigma \)的添加噪声，\( h \)固定为\( 10\sigma \)。<sup>[1](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)</sup> 作者后来的参考实现则将\( h \)设为\( k\sigma \)，其中\( k \)随图像块尺寸增大而减小，因为对于较大的图像块，两个纯噪声图像块之间的距离更紧密地集中在\( 2\sigma^2 \)附近：对于灰度图像，\( h \)从3×3图像块的\( 0.40\sigma \)降至11×11图像块的\( 0.30\sigma \)；对于彩色图像，从\( 0.55\sigma \)降至\( 0.35\sigma \)，搜索窗口随噪声增大从21×21增至35×35。<sup>[2](https://www.ipol.im/pub/art/2011/bcm_nlm/article.pdf)</sup>

软件默认值各有不同。OpenCV建议滤波强度\( h \approx 10 \)，模板窗口为7，搜索窗口为21（均为奇数），并提供针对单幅图像和图像序列的灰度与彩色变体。<sup>[7](https://docs.opencv.org/4.11.0/d5/d69/tutorial_py_non_local_means.html)</sup> scikit-image默认patch_size为7，patch_distance为11，\( h = 0.1 \)，并提供一个\( \texttt{estimate\_sigma} \)函数为设置\( h \)提供起点。<sup>[8](https://github.com/scikit-image/scikit-image/blob/v0.13.1/skimage/restoration/non_local_means.py)</sup><sup> • </sup><sup>[9](https://scikit-image.org/docs/stable/auto_examples/filters/plot_nonlocal_means.html)</sup>

## 起源

作者将该方法置于更早的邻域滤波器背景中：Yaroslavsky滤波器，其知名度不如其较新的版本SUSAN滤波器（1995年）和双边滤波器（1998年），后者权衡与参考像素的空间距离，而非使用固定的空间邻域。<sup>[1](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)</sup> 第二个源头在于纹理合成：Efros和Leung于1999年发表的开创性论文《非参数采样的纹理合成》，在科孚岛举行的IEEE国际计算机视觉会议上展示，同样利用了图像自相似性，通过匹配局部邻域来采样新像素以进行合成，而非对相似图像块求平均以去噪；作者认为，该论文首次利用了图像自相似性——即数字图像中相似窗口的集合。<sup>[10](https://www.college-de-france.fr/sites/default/files/documents/pierre-louis-lions/UPL67973_Jean_Michel_MorelTransparents.pdf)</sup><sup> • </sup><sup>[11](https://hal.science/hal-00271147/document)</sup><sup> • </sup><sup>[12](https://www.sciencedirect.com/science/article/abs/pii/S0167865511002066)</sup> 作者的回顾性综述指出，他们关于非局部方法相对于全变分和小波阈值化具有更好去噪性能的结论已被广泛接受。<sup>[5](https://www.math.ucdavis.edu/~saito/data/acha.read.s11/buades-coll-morel-siamrev.pdf)</sup>

## 变体

直接实现对于\( N \times N \)的图像需要\( O(N^2 S^2 K^2) \)次运算，其中搜索窗口为\( S \)，图像块尺寸为\( K \)；原始论文的数据约为\( 49 \times 441 \times N^2 \)。<sup>[13](https://arxiv.org/pdf/1407.2343)</sup><sup> • </sup><sup>[1](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)</sup> 随后出现了若干加速路线：

- 积分图快速NLM：对给定位移计算图像块距离的积分，将复杂度降至\( \text{image.size} \cdot \text{patch\_distance}^{n} \)，代价是两倍的内存；无参数的逐像素变体比逐图像块实现快6至49倍。<sup>[8](https://github.com/scikit-image/scikit-image/blob/v0.13.1/skimage/restoration/non_local_means.py)</sup><sup> • </sup><sup>[14](https://www.ipol.im/pub/art/2014/120/)</sup>
- 可分离NLM：因式分解计算可获得至少300倍于NLM的加速，且PSNR和SSIM始终更优。<sup>[13](https://arxiv.org/pdf/1407.2343)</sup>
- 精确卷积实现：使用卷积的精确NL-means计算比朴素方法获得更低的计算时间。<sup>[15](https://hal.science/hal-00512801v1/document)</sup>
- 逐块聚合：对图像块而非单个像素去噪并聚合重叠结果，可提升PSNR并减少边缘附近的伪噪声振荡；并行化的逐块实现包含\( h \)的自动调优。<sup>[2](https://www.ipol.im/pub/art/2011/bcm_nlm/article.pdf)</sup><sup> • </sup><sup>[13](https://arxiv.org/pdf/1407.2343)</sup>
- 迭代（变分）NLM：迭代表述在规则纹理上优于单次NLM和全变分。<sup>[6](https://cvg.cit.tum.de/_media/spezial/bib/brox_cremers_ssvm07_denoising.pdf)</sup>
- 视频扩展：该框架在“方法噪声”和“噪声到噪声”原则下扩展到电影去噪。<sup>[16](https://dl.acm.org/doi/10.1007/s11263-007-0052-1)</sup>

通往深度学习的概念线索经过自注意力：Wang、Girshick、Gupta和He的《非局部神经网络》（arXiv，2017年）将类注意力层表述为非局部滤波，后来的工作将语言模型中的自注意力机制视为非局部均值的一种形式。<sup>[17](https://doi.org/10.48550/arxiv.1711.07971)</sup><sup> • </sup><sup>[18](https://arxiv.org/html/2604.17453v1)</sup> 近期的变体包括LDNLM，它将NLM的相似度计算和加权平均替换为针对乘性SAR噪声从\( O(n^2) \)线性化到\( O(n) \)的注意力操作；<sup>[19](https://arxiv.org/html/2407.05087)</sup> NL-Ridge，它将BM3D和NL-Bayes重新解释为在\( \kappa \times \kappa \)窗口（\( \kappa = 37 \)）中通过相似含噪图像块的线性组合进行去噪，在不使用任何经过训练的网络的情况下与DnCNN和FFDNet相比具有优势；<sup>[20](https://arxiv.org/pdf/2402.13816)</sup> Trans-NLM，将[Transformer](https://www.edgepedia.org/zh/transformer)架构融入基于NLM的SAR去斑同时保持可解释性；<sup>[21](https://doi.org/10.1109/tgrs.2024.3397325)</sup> 以及NLFeMF，将匹配、协同滤波和聚合的经典三步非局部流程转化为完全可学习的模块用于RAW图像去噪。<sup>[18](https://arxiv.org/html/2604.17453v1)</sup>

## 应用

NL-means的改编版本已被提出用于冷冻电子显微镜、荧光显微镜、MRI、多光谱MRI和扩散张量MRI（DT-MRI）。<sup>[5](https://www.math.ucdavis.edu/~saito/data/acha.read.s11/buades-coll-morel-siamrev.pdf)</sup> 该方法在科学成像中的地位建立在噪声到噪声准则之上，该准则解决了去噪算法从纯噪声出发产生结构化特征的风险；在测量结果不得伪造的场合，算法的中立性至关重要。<sup>[5](https://www.math.ucdavis.edu/~saito/data/acha.read.s11/buades-coll-morel-siamrev.pdf)</sup> 具体在MRI中，自适应NL-means滤波器使用稳健的相似度度量，通过周围像素的加权平均恢复每个像素，适应空间变化的噪声水平。<sup>[22](https://onlinelibrary.wiley.com/doi/10.1002/jmri.22003)</sup> NLM变体也作为组件服务于更强的流程：快速NLM可为BM3D第二阶段使用的[维纳滤波器](https://www.edgepedia.org/zh/wiener-filter)提供初始值，从而获得最先进的结果。<sup>[13](https://arxiv.org/pdf/1407.2343)</sup>

## 局限与替代方法

主要的失效模式源于权重设计。由于窗口比较和指数核，细节和精细结构可能被过度滤波，这是与邻域滤波器共有的“冲击效应”。<sup>[10](https://www.college-de-france.fr/sites/default/files/documents/pierre-louis-lions/UPL67973_Jean_Michel_MorelTransparents.pdf)</sup> 对\( h \)的敏感性随噪声增大而增加：在\( \sigma = 30 \)时，\( h = 0.65\sigma \)、\( 0.7\sigma \)和\( 0.75\sigma \)的设置分别产生同时包含未滤波噪声区域和过度平滑区域的图像，因此在高噪声下不存在理想的全局\( h \)选择。<sup>[6](https://cvg.cit.tum.de/_media/spezial/bib/brox_cremers_ssvm07_denoising.pdf)</sup>

定量而言，在\( \sigma = 8 \)的Boat图像上，[高斯滤波](https://www.edgepedia.org/zh/gaussian-filtering)的均方误差为53，全变分为39，EWF为33，TIHWT（小波阈值化）为28，NL-means为23；在\( \sigma = 20 \)的Airplane图像上，相应的误差分别为159、57.15、78.3、50.97和38.31。<sup>[5](https://www.math.ucdavis.edu/~saito/data/acha.read.s11/buades-coll-morel-siamrev.pdf)</sup> 在经典方法中，作者判定BM3D——结合了块匹配、线性变换阈值化和维纳滤波——可能是性能最好的。<sup>[5](https://www.math.ucdavis.edu/~saito/data/acha.read.s11/buades-coll-morel-siamrev.pdf)</sup> 与双边滤波器的直接对比已有发表，尽管通常基于有限的数据集和噪声模型，而与现代扩散去噪器的比较仍然稀少；2021年的一项比较发现彩色NLM为30.26 dB，CBM3D为31.42 dB，高于所评估的单图像CNN方法。<sup>[23](https://openaccess.thecvf.com/content/CVPR2021/papers/Tachella_The_Neural_Tangent_Link_Between_CNN_Denoisers_and_Non-Local_Filters_CVPR_2021_paper.pdf)</sup>

## References

1. [A non-local algorithm for image denoising (Buades, Coll, Morel, CVPR 2005)](https://csc320.yani.ai/readings/Buades_CVPR2005.pdf)
2. [Non-Local Means Denoising (IPOL, Buades, Coll, Morel; incl. 2022 revision)](https://www.ipol.im/pub/art/2011/bcm_nlm/article.pdf)
3. [Local Smoothing Neighborhood Filters (Springer reference work entry)](https://link.springer.com/rwe/10.1007/978-3-642-27795-5_26-5)
4. [Bibliographic record: A Non-Local Algorithm for Image Denoising (2005)](https://bishtref.com/articles/10.1109/cvpr.2005.38)
5. [A review of image denoising methods, with a new one (Buades, Coll, Morel, SIAM Review)](https://www.math.ucdavis.edu/~saito/data/acha.read.s11/buades-coll-morel-siamrev.pdf)
6. [Nonlocal Image and Movie Denoising / Nonlocal Means Filtering (Brox & Cremers, SSVM 2007)](https://cvg.cit.tum.de/_media/spezial/bib/brox_cremers_ssvm07_denoising.pdf)
7. [Image Denoising, OpenCV tutorial](https://docs.opencv.org/4.11.0/d5/d69/tutorial_py_non_local_means.html)
8. [skimage/restoration/non_local_means.py source](https://github.com/scikit-image/scikit-image/blob/v0.13.1/skimage/restoration/non_local_means.py)
9. [Non-local means denoising for preserving textures, skimage documentation](https://scikit-image.org/docs/stable/auto_examples/filters/plot_nonlocal_means.html)
10. [Non local image processing (J.-M. Morel lecture slides, Collège de France)](https://www.college-de-france.fr/sites/default/files/documents/pierre-louis-lions/UPL67973_Jean_Michel_MorelTransparents.pdf)
11. [NonLocal image and movie denoising (Buades, Coll, Morel, HAL archival version)](https://hal.science/hal-00271147/document)
12. [Analysis of non-local image denoising methods (Pattern Recognition Letters)](https://www.sciencedirect.com/science/article/abs/pii/S0167865511002066)
13. [Fast Separable Non-Local Means](https://arxiv.org/pdf/1407.2343)
14. [IPOL Journal · Parameter-Free Fast Pixelwise Non-Local Means Denoising](https://www.ipol.im/pub/art/2014/120/)
15. [Non-Local Means, exact computation with convolutions (HAL)](https://hal.science/hal-00512801v1/document)
16. [Nonlocal Image and Movie Denoising (International Journal of Computer Vision)](https://dl.acm.org/doi/10.1007/s11263-007-0052-1)
17. [Wang, Xiaolong and colleagues (2017). Non-local Neural Networks. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1711.07971)
18. [Learned Nonlocal Feature Matching and Filtering for RAW Image Denoising (arXiv 2026)](https://arxiv.org/html/2604.17453v1)
19. [Linear Attention Based Deep Nonlocal Means Filtering for Multiplicative Noise Removal (LDNLM, 2024)](https://arxiv.org/html/2407.05087)
20. [NL-Ridge: a unified view of non-local methods for single-image denoising (arXiv 2024)](https://arxiv.org/pdf/2402.13816)
21. [Trans-NLM Network for SAR Image Despeckling (IEEE TGRS, 2024)](https://doi.org/10.1109/tgrs.2024.3397325)
22. [Adaptive non-local means denoising of MR images with spatially varying noise levels (Journal of Magnetic Resonance Imaging)](https://onlinelibrary.wiley.com/doi/10.1002/jmri.22003)
23. [The Neural Tangent Link Between CNN Denoisers and Non-Local Filters (CVPR 2021)](https://openaccess.thecvf.com/content/CVPR2021/papers/Tachella_The_Neural_Tangent_Link_Between_CNN_Denoisers_and_Non-Local_Filters_CVPR_2021_paper.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 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/non-local-means

English original: https://www.edgepedia.org/non-local-means
