日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Programming Computer Vision with Python (学习笔记八)

發布時間:2025/3/21 python 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Programming Computer Vision with Python (学习笔记八) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

圖像去噪(Image Denoising)的過程就是將噪點從圖像中去除的同時盡可能的保留原圖像的細節和結構。這里講的去噪跟前面筆記提過的去噪不一樣,這里是指高級去噪技術,前面提過的高斯平滑也能去噪,但高斯平滑去噪的同時也把邊緣模糊化了,另外使用形態學的方法去噪是指去除一些粗的椒鹽噪聲。對于一幅密布噪點的圖像,如果使其變得清晰又保留邊緣細節,這是高級去噪技術所要解決的問題。

全變差

全變差去噪(Total variation denoising)是一種常用的去噪模型。全變差(或叫總變差)大概是指圖像梯度的范數(norm)的積分。
一幅圖像的細節(噪聲或是干擾的不必要的)過多,全變差的值越高,所以讓全變差最小化,去掉噪聲和沒用細節的同時,保留邊緣等主要細節,正是這種模型的處理思想。用這種去噪技術產生的圖像有點接近卡通的感覺。
下面要介紹的Chambolle去噪算法就是基于全變差去噪模型實現的。

chambolle去噪

scipy.ndimage模塊只是提供了基本的圖像處理方法,并沒有提供Chambolle去噪函數,所以就要借助另一個庫——scikit-image。

scikit-image
scikit-image(簡稱skimage)庫是從scipy.ndimage擴展下來的,提供了更豐富的圖像處理函數,去噪函數除了Chambolle還有Bilateral算法,比如邊緣檢測還有以前簡單提過的Canny算子濾波器。
它也是由 SciPy 社區所開發的,可以跟NumPy等完美配合。

安裝:

sudo apt-get install python-skimage

函數說明:

skimage.restoration.denoise_tv_chambolle(im, weight=50, eps=0.0002, n_iter_max=200, multichannel=False) im: ndarray類型,2維或3維 weight:越大去噪越多,但圖像也會越失真 multichannel:對彩色圖像而言,true表示對每一通道去噪返回去噪后的圖像,ndarray類型。

下面我用看具體的例子,將chambolle和高斯平滑進行對比:

from PIL import Image import numpy as np import matplotlib.pyplot as plt from scipy.ndimage import filters from skimage.filter import denoise_tv_chambolle #for versoin: 0.9.3 #from skimage.restoration import denoise_tv_chambolle #for new versionim = np.array(Image.open('noising.jpg').convert('L'))index = 221 plt.subplot(index) plt.gray() plt.imshow(im) plt.axis('off') plt.title("original")chdnim = denoise_tv_chambolle(im, weight=0.2) plt.subplot(index+1) plt.imshow(chdnim) plt.axis('off') plt.title("chambolle weight=0.2")gs2dnim = filters.gaussian_filter(im, sigma=2) plt.subplot(index+2) plt.imshow(gs2dnim) plt.axis('off') plt.title("gaussion sigma=2")gs3dnim = filters.gaussian_filter(im, sigma=3)plt.subplot(index+3) plt.imshow(gs3dnim) plt.axis('off') plt.title("gaussion sigmal=3")plt.show()

效果對比如下:

明顯感覺使用chambolle的效果要比高斯平滑好很多。

Bilateral濾波器
Bilateral濾波器跟之前介紹過的高斯模糊運算過程相似,而且它也使用了高斯核,但它的特點是在對圖像進行平滑的同時能保留邊緣。因為它在平滑濾波時同時考慮了像素間的幾何距離和色彩距離。具體點說,如果要處理的像素與鄰近像素的歐式距離比較大(即像素值相差比較大)時,那么這些鄰近像素的權重就比較小,從而使得對濾波后的新像素值影響較小。另外,每個濾波后像素點的值,受與他色彩相近并且距離較近的像素點的影響較大,這兩種權值分配方法起到了保護邊緣的作用。

Bilateral去噪函數:

skimage.restoration.denoise_bilateral(image, win_size=5, sigma_range=None, sigma_spatial=1, bins=10000, mode='constant', cval=0)

示例:

from PIL import Image import numpy as np import matplotlib.pyplot as plt from scipy.ndimage import filters from skimage.filter import denoise_bilateral #for versoin: 0.9.3 #from skimage.restoration import denoise_bilateral #for new versionim = np.array(Image.open('noising.jpg').convert('L'))index = 221 plt.subplot(index) plt.gray() plt.imshow(im) plt.axis('off') plt.title("original")plt.subplot(index+1) plt.imshow(denoise_bilateral(im)) plt.axis('off') plt.title("default")plt.subplot(index+2) plt.imshow(denoise_bilateral(im, sigma_range=0.2, sigma_spatial=10)) plt.axis('off') plt.title("0.2/10")plt.subplot(index+3) plt.imshow(denoise_bilateral(im, sigma_range=0.8, sigma_spatial=10)) plt.axis('off') plt.title("0.8/10")plt.show()

效果如圖:

感覺比高斯平滑要好一些,但比Chambolle還是要遜色不少。

小結

因全變差的數學原理比較高深,所以暫時沒去研究,只大概了解下并使用skimage庫的接口進行了一番對比,結論就是使用chambolle去噪效果非常好。

至此,書中第一章的內容結束了。后面將開始下一章節的內容學習——圖像描述。

你還可以查看我的其它筆記。

參考資料

scikit-image.org
scikit denoising example
Bilateral Filtering

總結

以上是生活随笔為你收集整理的Programming Computer Vision with Python (学习笔记八)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。