CV2.fastNlMeansDenoising(非局部平均去噪)
L-Means的全稱是:Non-Local Means,直譯過來是非局部平均,在2005年由Baudes提出,該算法使用自然圖像中普遍存在的冗余信息來去噪聲。與常用的雙線性濾波、中值濾波等利用圖像局部信息來濾波不同的是,它利用了整幅圖像來進行去噪,以圖像塊為單位在圖像中尋找相似區域,再對這些區域求平均,能夠比較好地去掉圖像中存在的高斯噪聲。與我們以前學習的平滑技術相比這種算法要消耗更多的時間,但是結果很好。對於彩色圖像,要先轉換到 CIELAB 顏色空間,然后對 L 和 AB 成分分別去噪。
1 cv2.fastNlMeansDenoising() - 使用單個灰度圖像 2 cv2.fastNlMeansDenoisingColored() - 使用彩色圖像。 3 cv2.fastNlMeansDenoisingMulti() - 用於在短時間內捕獲的圖像序列(灰度圖像) 4 cv2.fastNlMeansDenoisingColoredMulti() - 與上面相同,但用於彩色圖像。
1 fastNlMeansDenoisingColored( InputArray src, OutputArray dst, 2 float h = 3, float hColor = 3, 3 int templateWindowSize = 7, int searchWindowSize = 21)
共同參數有:
• h : 決定過濾器強度。h 值高可以很好的去除噪聲,但也會把圖像的細節抹去。(取 10 的效果不錯)
• hForColorComponents : 與 h 相同,但使用與彩色圖像。(與 h 相同,10)
• templateWindowSize : 奇數。(推薦值為 7)
• searchWindowSize : 奇數。(推薦值為 21)
1 import numpy as np 2 import cv2 3 import matplotlib.pyplot as plt 4 filePath = r'F:\主題一:遙感圖像場景分類\val\val\水田\paddy-field_00076.jpg'
5 img = cv2.imdecode(np.fromfile(filePath,dtype=np.uint8),-1) 6 dst = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 21) 7
8 plt.subplot(121), plt.imshow(img) 9 plt.subplot(122), plt.imshow(dst) 10 plt.show()