国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python數字圖像處理之高級濾波代碼詳解

2020-01-04 16:16:54
字體:
來源:轉載
供稿:網友

本文提供許多的濾波方法,這些方法放在filters.rank子模塊內。

這些方法需要用戶自己設定濾波器的形狀和大小,因此需要導入morphology模塊來設定。

1、autolevel

這個詞在photoshop里面翻譯成自動色階,用局部直方圖來對圖片進行濾波分級。

該濾波器局部地拉伸灰度像素值的直方圖,以覆蓋整個像素值范圍。

格式:skimage.filters.rank.autolevel(image, selem)

selem表示結構化元素,用于設定濾波器。

from skimage import data,colorimport matplotlib.pyplot as pltfrom skimage.morphology import diskimport skimage.filters.rank as sfrimg =color.rgb2gray(data.lena())auto =sfr.autolevel(img, disk(5)) #半徑為5的圓形濾波器plt.figure('filters',figsize=(8,8))plt.subplot(121)plt.title('origin image')plt.imshow(img,plt.cm.gray)plt.subplot(122)plt.title('filted image')plt.imshow(auto,plt.cm.gray)

python,數字圖像處理,濾波

2、bottomhat 與 tophat

bottomhat: 此濾波器先計算圖像的形態學閉運算,然后用原圖像減去運算的結果值,有點像黑帽操作。

bottomhat: 此濾波器先計算圖像的形態學開運算,然后用原圖像減去運算的結果值,有點像白帽操作。

格式:

skimage.filters.rank.bottomhat(image, selem)

skimage.filters.rank.tophat(image, selem)

selem表示結構化元素,用于設定濾波器。

下面是bottomhat濾波的例子:

from skimage import data,colorimport matplotlib.pyplot as pltfrom skimage.morphology import diskimport skimage.filters.rank as sfrimg =color.rgb2gray(data.lena())auto =sfr.bottomhat(img, disk(5)) #半徑為5的圓形濾波器plt.figure('filters',figsize=(8,8))plt.subplot(121)plt.title('origin image')plt.imshow(img,plt.cm.gray)plt.subplot(122)plt.title('filted image')plt.imshow(auto,plt.cm.gray)

python,數字圖像處理,濾波

3、enhance_contrast

對比度增強。求出局部區域的最大值和最小值,然后看當前點像素值最接近最大值還是最小值,然后替換為最大值或最小值。

函數: enhance_contrast(image, selem)

selem表示結構化元素,用于設定濾波器。

from skimage import data,colorimport matplotlib.pyplot as pltfrom skimage.morphology import diskimport skimage.filters.rank as sfrimg =color.rgb2gray(data.lena())auto =sfr.enhance_contrast(img, disk(5)) #半徑為5的圓形濾波器plt.figure('filters',figsize=(8,8))plt.subplot(121)plt.title('origin image')plt.imshow(img,plt.cm.gray)plt.subplot(122)plt.title('filted image')plt.imshow(auto,plt.cm.gray)

python,數字圖像處理,濾波

4、entropy

求局部熵,熵是使用基為2的對數運算出來的。該函數將局部區域的灰度值分布進行二進制編碼,返回編碼的最小值。

函數格式:entropy(image, selem)

selem表示結構化元素,用于設定濾波器。

from skimage import data,colorimport matplotlib.pyplot as pltfrom skimage.morphology import diskimport skimage.filters.rank as sfrimg =color.rgb2gray(data.lena())dst =sfr.entropy(img, disk(5)) #半徑為5的圓形濾波器plt.figure('filters',figsize=(8,8))plt.subplot(121)plt.title('origin image')plt.imshow(img,plt.cm.gray)plt.subplot(122)plt.title('filted image')plt.imshow(dst,plt.cm.gray)

python,數字圖像處理,濾波

5、equalize

均衡化濾波。利用局部直方圖對圖像進行均衡化濾波。

函數格式:equalize(image, selem)

selem表示結構化元素,用于設定濾波器。

from skimage import data,colorimport matplotlib.pyplot as pltfrom skimage.morphology import diskimport skimage.filters.rank as sfrimg =color.rgb2gray(data.lena())dst =sfr.equalize(img, disk(5)) #半徑為5的圓形濾波器plt.figure('filters',figsize=(8,8))plt.subplot(121)plt.title('origin image')plt.imshow(img,plt.cm.gray)plt.subplot(122)plt.title('filted image')plt.imshow(dst,plt.cm.gray)

python,數字圖像處理,濾波

6、gradient

返回圖像的局部梯度值(如:最大值-最小值),用此梯度值代替區域內所有像素值。

函數格式:gradient(image, selem)

selem表示結構化元素,用于設定濾波器。

from skimage import data,colorimport matplotlib.pyplot as pltfrom skimage.morphology import diskimport skimage.filters.rank as sfrimg =color.rgb2gray(data.lena())dst =sfr.gradient(img, disk(5)) #半徑為5的圓形濾波器plt.figure('filters',figsize=(8,8))plt.subplot(121)plt.title('origin image')plt.imshow(img,plt.cm.gray)plt.subplot(122)plt.title('filted image')plt.imshow(dst,plt.cm.gray)

python,數字圖像處理,濾波

7、其它濾波器

濾波方式很多,下面不再一一詳細講解,僅給出核心代碼,所有的函數調用方式都是一樣的。

最大值濾波器(maximum):返回圖像局部區域的最大值,用此最大值代替該區域內所有像素值。

dst =sfr.maximum(img, disk(5))

最小值濾波器(minimum):返回圖像局部區域內的最小值,用此最小值取代該區域內所有像素值。

dst =sfr.minimum(img, disk(5))

均值濾波器(mean) : 返回圖像局部區域內的均值,用此均值取代該區域內所有像素值。

dst =sfr.mean(img, disk(5))

中值濾波器(median): 返回圖像局部區域內的中值,用此中值取代該區域內所有像素值。

dst =sfr.median(img, disk(5))

莫代爾濾波器(modal) : 返回圖像局部區域內的modal值,用此值取代該區域內所有像素值。

dst =sfr.modal(img, disk(5))

otsu閾值濾波(otsu): 返回圖像局部區域內的otsu閾值,用此值取代該區域內所有像素值。

dst =sfr.otsu(img, disk(5))

閾值濾波(threshhold): 將圖像局部區域中的每個像素值與均值比較,大于則賦值為1,小于賦值為0,得到一個二值圖像。

dst =sfr.threshold(img, disk(5))

減均值濾波(subtract_mean): 將局部區域中的每一個像素,減去該區域中的均值。

dst =sfr.subtract_mean(img, disk(5))

求和濾波(sum) :求局部區域的像素總和,用此值取代該區域內所有像素值。

dst =sfr.sum(img, disk(5))

總結

以上就是本文關于python/272738.html">python數字圖像處理之高級濾波代碼詳解的全部內容,希望對大家有所幫助。


注:相關教程知識閱讀請移步到python教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 耒阳市| 古蔺县| 萨嘎县| 石泉县| 确山县| 镇江市| 宜州市| 密山市| 宜城市| 沙湾县| 长泰县| 新密市| 铅山县| 共和县| 青田县| 北流市| 鄂托克前旗| 特克斯县| 宜君县| 上思县| 称多县| 和平县| 海城市| 富民县| 龙门县| 蓝田县| 衡南县| 昌平区| 正蓝旗| 水城县| 汝城县| 大石桥市| 鄂温| 秦皇岛市| 炎陵县| 彩票| 科技| 浪卡子县| 庄浪县| 托克托县| 屏东市|