python skimage圖像處理(二)

python skimage圖像處理(二)

 

This blog is from: https://www.jianshu.com/p/66e6261f0279 css

 

圖像簡單濾波

對圖像進行濾波,能夠有兩種效果:一種是平滑濾波,用來抑制噪聲;另外一種是微分算子,能夠用來檢測邊緣和特徵提取。
skimage庫中經過filters模塊進行濾波操做。
一、sobel算子
sobel算子可用來檢測邊緣
函數格式爲:html

skimage.filters.sobel(image, mask=None) 
from skimage import data,filters import matplotlib.pyplot as plt img = data.camera() edges = filters.sobel(img) plt.imshow(edges,plt.cm.gray) 
 

二、roberts算子python

roberts算子和sobel算子同樣,用於檢測邊緣
調用格式也是同樣的:bash

edges = filters.roberts(img)

三、scharr算子
功能同sobel,調用格式:函數

edges = filters.scharr(img)

四、prewitt算子
功能同sobel,調用格式:編碼

edges = filters.prewitt(img)

五、canny算子
canny算子也是用於提取邊緣特徵,但它不是放在filters模塊,而是放在feature模塊
函數格式:spa

skimage.feature.canny(image,sigma=1.0)

能夠修改sigma的值來調整效果翻譯

from skimage import data,filters,feature import matplotlib.pyplot as plt img = data.camera() edges1 = feature.canny(img) #sigma=1 edges2 = feature.canny(img,sigma=3) #sigma=3 plt.figure('canny',figsize=(8,8)) plt.subplot(121)plt.imshow(edges1,plt.cm.gray) plt.subplot(122)plt.imshow(edges2,plt.cm.gray) plt.show() 

 

 


從結果能夠看出,sigma越小,邊緣線條越細小。
六、gabor濾波
gabor濾波可用來進行邊緣檢測和紋理特徵提取。
函數調用格式:3d

 

skimage.filters.gabor_filter(image, frequency) 

經過修改frequency值來調整濾波效果,返回一對邊緣結果,一個是用真實濾波核的濾波結果,一個是想象的濾波核的濾波結果。code

from skimage import data,filters import matplotlib.pyplot as plt img = data.camera() filt_real, filt_imag = filters.gabor_filter(img,frequency=0.6) plt.figure('gabor',figsize=(8,8)) plt.subplot(121) plt.title('filt_real') plt.imshow(filt_real,plt.cm.gray) plt.subplot(122) plt.title('filt-imag') plt.imshow(filt_imag,plt.cm.gray) plt.show() 
 

 

以上爲frequency=0.6的結果圖。

 

 

 

以上爲frequency=0.1的結果圖

七、gaussian濾波
多維的濾波器,是一種平滑濾波,能夠消除高斯噪聲。
調用函數爲:

skimage.filters.gaussian_filter(image, sigma) 

經過調節sigma的值來調整濾波效果

from skimage import data,filters import matplotlib.pyplot as plt img = data.astronaut() edges1 = filters.gaussian_filter(img,sigma=0.4) #sigma=0.4 edges2 = filters.gaussian_filter(img,sigma=5) #sigma=5 plt.figure('gaussian',figsize=(8,8)) plt.subplot(121) plt.imshow(edges1,plt.cm.gray) plt.subplot(122) plt.imshow(edges2,plt.cm.gray) plt.show() 

 

 


可見sigma越大,過濾後的圖像越模糊
8.median
中值濾波,一種平滑濾波,能夠消除噪聲。
須要用skimage.morphology模塊來設置濾波器的形狀。

 

from skimage import data,filters import matplotlib.pyplot as plt from skimage.morphology import disk img = data.camera() edges1 = filters.median(img,disk(5)) edges2= filters.median(img,disk(9)) plt.figure('median',figsize=(8,8)) plt.subplot(121) plt.imshow(edges1,plt.cm.gray) plt.subplot(122) plt.imshow(edges2,plt.cm.gray) plt.show() 
 

 

從結果能夠看出,濾波器越大,圖像越模糊。

九、水平、垂直邊緣檢測

上邊所舉的例子都是進行所有邊緣檢測,有些時候咱們只須要檢測水平邊緣,或垂直邊緣,就可用下面的方法。

水平邊緣檢測:sobel_h, prewitt_h, scharr_h 垂直邊緣檢測: sobel_v, prewitt_v, scharr_v
from skimage import data,filters import matplotlib.pyplot as plt img = data.camera() edges1 = filters.sobel_h(img) edges2 = filters.sobel_v(img) plt.figure('sobel_v_h',figsize=(8,8)) plt.subplot(121) plt.imshow(edges1,plt.cm.gray) plt.subplot(122) plt.imshow(edges2,plt.cm.gray) plt.show() 
 

 

上邊左圖爲檢測出的水平邊緣,右圖爲檢測出的垂直邊緣。

十、交叉邊緣檢測

可以使用Roberts的十字交叉核來進行過濾,以達到檢測交叉邊緣的目的。這些交叉邊緣其實是梯度在某個方向上的一個份量。
其中一個核:

0 1 -1 0

對應的函數:

roberts_neg_diag(image)

例:

from skimage import data,filters import matplotlib.pyplot as plt img =data.camera() dst =filters.roberts_neg_diag(img) 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) 
 

 

另一個核:

1 0 0 -1

對應函數爲:

roberts_pos_diag(image)
from skimage import data,filters import matplotlib.pyplot as plt img =data.camera() dst =filters.roberts_pos_diag(img) 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) 
 

圖像自動閾值分割

圖像閾值分割是一種普遍應用的分割技術,利用圖像中要提取的目標區域與其背景在灰度特性上的差別,把圖像看做具備不一樣灰度級的兩類區域(目標區域和背景區域)的組合,選取一個比較合理的閾值,以肯定圖像中每一個像素點應該屬於目標區域仍是背景區域,從而產生相應的二值圖像。
在skimage庫中,閾值分割的功能是放在filters模塊中。
咱們能夠手動指定一個閾值,從而來實現分割。也可讓系統自動生成一個閾值,下面幾種方法就是用來自動生成閾值。

一、threshold_otsu
基於Otsu的閾值分割方法,函數調用格式:

skimage.filters.threshold_otsu(image, nbins=256)

參數image是指灰度圖像,返回一個閾值。

from skimage import data,filters import matplotlib.pyplot as plt image = data.camera() thresh = filters.threshold_otsu(image) #返回一個閾值 dst =(image <= thresh)*1.0 #根據閾值進行分割 plt.figure('thresh',figsize=(8,8)) plt.subplot(121) plt.title('original image') plt.imshow(image,plt.cm.gray) plt.subplot(122) plt.title('binary image') plt.imshow(dst,plt.cm.gray) plt.show() 

返回閾值爲87,根據87進行分割得下圖:

 

 

 

二、threshold_yen
使用方法同上:

thresh = filters.threshold_yen(image)

返回閾值爲198,分割以下圖:

 

 

 

三、threshold_li
使用方法同上:

thresh = filters.threshold_li(image)

返回閾值64.5,分割以下圖:

 

 

 

四、threshold_isodata
閾值計算方法:

threshold = (image[image <= threshold].mean() +image[image > threshold].mean()) / 2.0

使用方法同上:

thresh = filters.threshold_isodata(image)

返回閾值爲87,所以分割效果和threshold_otsu同樣。
五、threshold_adaptive
調用函數爲:

skimage.filters.threshold_adaptive(image, block_size, method='gaussian')

block_size: 塊大小,指當前像素的相鄰區域大小,通常是奇數(如3,5,7。。。)
method: 用來肯定自適應閾值的方法,有'mean', 'generic', 'gaussian' 和 'median'。省略時默認爲gaussian
該函數直接訪問一個閾值後的圖像,而不是閾值。

from skimage import data,filters import matplotlib.pyplot as plt image = data.camera() dst =filters.threshold_adaptive(image, 15) #返回一個閾值圖像 plt.figure('thresh',figsize=(8,8)) plt.subplot(121) plt.title('original image') plt.imshow(image,plt.cm.gray) plt.subplot(122) plt.title('binary image') plt.imshow(dst,plt.cm.gray) plt.show() 
 

 

你們能夠修改block_size的大小和method值來查看更多的效果。如:

dst1 =filters.threshold_adaptive(image,31,'mean') dst2 =filters.threshold_adaptive(image,5,'median')

兩種效果以下:

 

 

基本圖形的繪製

圖形包括線條、圓形、橢圓形、多邊形等。
在skimage包中,繪製圖形用的是draw模塊,不要和繪製圖像搞混了。
一、畫線條
函數調用格式爲:

skimage.draw.line(r1,c1,r2,c2) 

r1,r2: 開始點的行數和結束點的行數
c1,c2: 開始點的列數和結束點的列數
返回當前繪製圖形上全部點的座標,如:

rr, cc =draw.line(1, 5, 8, 2)

表示從(1,5)到(8,2)連一條線,返回線上全部的像素點座標[rr,cc]

from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc =draw.line(1, 150, 470, 450) img[rr, cc] =255 plt.imshow(img,plt.cm.gray) 
 

 

若是想畫其它顏色的線條,則可使用set_color()函數,格式爲:

skimage.draw.set_color(img, coords, color) 

例:

draw.set_color(img,[rr,cc],[255,0,0]) 

則繪製紅色線條。

from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc =draw.line(1, 150, 270, 250) draw.set_color(img,[rr,cc],[0,0,255]) plt.imshow(img,plt.cm.gray) 
 

二、畫圓
函數格式:

skimage.draw.circle(cy, cx, radius) 

cy和cx表示圓心點,radius表示半徑

from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc=draw.circle(150,150,50) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray) 
 

 

三、多邊形
函數格式:

skimage.draw.polygon(Y,X) 

Y爲多邊形頂點的行集合,X爲各頂點的列值集合。

from skimage import draw,data import matplotlib.pyplot as plt import numpy as np img=data.chelsea() Y=np.array([10,10,60,60]) X=np.array([200,400,400,200]) rr, cc=draw.polygon(Y,X) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray) 
 

 

我在此處只設置了四個頂點,所以是個四邊形。
四、橢圓
格式:

skimage.draw.ellipse(cy, cx, yradius, xradius) 

cy和cx爲中心點座標,yradius和xradius表明長短軸。

from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc=draw.ellipse(150, 150, 30, 80) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray) 
 

 

五、貝塞兒曲線
格式:

skimage.draw.bezier_curve(y1,x1,y2,x2,y3,x3,weight) 

y1,x1表示第一個控制點座標
y2,x2表示第二個控制點座標
y3,x3表示第三個控制點座標
weight表示中間控制點的權重,用於控制曲線的彎曲度。

from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc=draw.bezier_curve(150,50,50,280,260,400,2) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray) 
 

 

六、畫空心圓
和前面的畫圓是同樣的,只是前面是實心圓,而此處畫空心圓,只有邊框線。
格式:

skimage.draw.circle_perimeter(yx,yc,radius) 

yx,yc是圓心座標,radius是半徑

from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc=draw.circle_perimeter(150,150,50) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray) 
 

 

七、空心橢圓
格式:

skimage.draw.ellipse_perimeter(cy, cx, yradius, xradius) 

cy,cx表示圓心
yradius,xradius表示長短軸

from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc=draw.ellipse_perimeter(150, 150, 30, 80) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray) 
 

基本形態學濾波

對圖像進行形態學變換。變換對象通常爲灰度圖或二值圖,功能函數放在morphology子模塊內。

一、膨脹(dilation)

原理:通常對二值圖像進行操做。找到像素值爲1的點,將它的鄰近像素點都設置成這個值。1值表示白,0值表示黑,所以膨脹操做能夠擴大白色值範圍,壓縮黑色值範圍。通常用來擴充邊緣或填充小的孔洞。
功能函數:

skimage.morphology.dilation(image, selem=None) 

selem表示結構元素,用於設定局部區域的形狀和大小。

from skimage import data import skimage.morphology as sm import matplotlib.pyplot as plt img=data.checkerboard() dst1=sm.dilation(img,sm.square(5)) #用邊長爲5的正方形濾波器進行膨脹濾波 dst2=sm.dilation(img,sm.square(15)) #用邊長爲15的正方形濾波器進行膨脹濾波 plt.figure('morphology',figsize=(8,8)) plt.subplot(131) plt.title('origin image') plt.imshow(img,plt.cm.gray) plt.subplot(132) plt.title('morphological image') plt.imshow(dst1,plt.cm.gray) plt.subplot(133) plt.title('morphological image') plt.imshow(dst2,plt.cm.gray) 

分別用邊長爲5或15的正方形濾波器對棋盤圖片進行膨脹操做,結果以下:

 

 

 

可見濾波器的大小,對操做結果的影響很是大。通常設置爲奇數。
除了正方形的濾波器外,濾波器的形狀還有一些,現列舉以下:

morphology.square: 正方形 morphology.disk: 平面圓形 morphology.ball: 球形 morphology.cube: 立方體形 morphology.diamond: 鑽石形 morphology.rectangle: 矩形 morphology.star: 星形 morphology.octagon: 八角形 morphology.octahedron: 八面體 

注意,若是處理圖像爲二值圖像(只有0和1兩個值),則能夠調用:

skimage.morphology.binary_dilation(image, selem=None) 

用此函數比處理灰度圖像要快。

二、腐蝕(erosion)

函數:

skimage.morphology.erosion(image, selem=None) 

selem表示結構元素,用於設定局部區域的形狀和大小。
和膨脹相反的操做,將0值擴充到鄰近像素。擴大黑色部分,減少白色部分。可用來提取骨幹信息,去掉毛刺,去掉孤立的像素。

from skimage import data import skimage.morphology as sm import matplotlib.pyplot as plt img=data.checkerboard() dst1=sm.erosion(img,sm.square(5)) #用邊長爲5的正方形濾波器進行膨脹濾波 dst2=sm.erosion(img,sm.square(25)) #用邊長爲25的正方形濾波器進行膨脹濾波 plt.figure('morphology',figsize=(8,8)) plt.subplot(131) plt.title('origin image') plt.imshow(img,plt.cm.gray) plt.subplot(132) plt.title('morphological image') plt.imshow(dst1,plt.cm.gray) plt.subplot(133) plt.title('morphological image') plt.imshow(dst2,plt.cm.gray) 
 

 

注意,若是處理圖像爲二值圖像(只有0和1兩個值),則能夠調用:

skimage.morphology.binary_erosion(image, selem=None) 

用此函數比處理灰度圖像要快。
三、開運算(opening)
函數:

skimage.morphology.openning(image, selem=None) 

selem表示結構元素,用於設定局部區域的形狀和大小。
先腐蝕再膨脹,能夠消除小物體或小斑塊。

from skimage import io,color import skimage.morphology as sm import matplotlib.pyplot as plt img=color.rgb2gray(io.imread('d:/pic/mor.png')) dst=sm.opening(img,sm.disk(9)) #用邊長爲9的圓形濾波器進行膨脹濾波 plt.figure('morphology',figsize=(8,8)) plt.subplot(121) plt.title('origin image') plt.imshow(img,plt.cm.gray) plt.axis('off') plt.subplot(122) plt.title('morphological image') plt.imshow(dst,plt.cm.gray) plt.axis('off') 
 

 

注意,若是處理圖像爲二值圖像(只有0和1兩個值),則能夠調用:

skimage.morphology.binary_opening(image, selem=None) 

用此函數比處理灰度圖像要快。
四、閉運算(closing)
函數:

skimage.morphology.closing(image, selem=None) 

selem表示結構元素,用於設定局部區域的形狀和大小。
先膨脹再腐蝕,可用來填充孔洞。

from skimage import io,color import skimage.morphology as sm import matplotlib.pyplot as plt img=color.rgb2gray(io.imread('d:/pic/mor.png')) dst=sm.closing(img,sm.disk(9)) #用邊長爲5的圓形濾波器進行膨脹濾波 plt.figure('morphology',figsize=(8,8)) plt.subplot(121) plt.title('origin image') plt.imshow(img,plt.cm.gray) plt.axis('off') plt.subplot(122) plt.title('morphological image') plt.imshow(dst,plt.cm.gray) plt.axis('off') 
 

 

注意,若是處理圖像爲二值圖像(只有0和1兩個值),則能夠調用:

skimage.morphology.binary_closing(image, selem=None) 

用此函數比處理灰度圖像要快。
五、白帽(white-tophat)
函數:

skimage.morphology.white_tophat(image, selem=None) 

selem表示結構元素,用於設定局部區域的形狀和大小。
將原圖像減去它的開運算值,返回比結構化元素小的白點

from skimage import io,color import skimage.morphology as sm import matplotlib.pyplot as plt img=color.rgb2gray(io.imread('d:/pic/mor.png')) dst=sm.white_tophat(img,sm.square(21)) plt.figure('morphology',figsize=(8,8)) plt.subplot(121)plt.title('origin image') plt.imshow(img,plt.cm.gray) plt.axis('off') plt.subplot(122) plt.title('morphological image') plt.imshow(dst,plt.cm.gray) plt.axis('off') 
 

 

六、黑帽(black-tophat)
函數:

skimage.morphology.black_tophat(image, selem=None) 

selem表示結構元素,用於設定局部區域的形狀和大小。
將原圖像減去它的閉運算值,返回比結構化元素小的黑點,且將這些黑點反色。

from skimage import io,color import skimage.morphology as sm import matplotlib.pyplot as plt img=color.rgb2gray(io.imread('d:/pic/mor.png')) dst=sm.black_tophat(img,sm.square(21)) plt.figure('morphology',figsize=(8,8)) plt.subplot(121) plt.title('origin image') plt.imshow(img,plt.cm.gray) plt.axis('off') plt.subplot(122) plt.title('morphological image') plt.imshow(dst,plt.cm.gray) plt.axis('off') 
 

高級濾波

本文提供更多更強大的濾波方法,這些方法放在filters.rank子模塊內。
這些方法須要用戶本身設定濾波器的形狀和大小,所以須要導入morphology模塊來設定。

一、autolevel
這個詞在photoshop裏面翻譯成自動色階,用局部直方圖來對圖片進行濾波分級。
該濾波器局部地拉伸灰度像素值的直方圖,以覆蓋整個像素值範圍。
格式:

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

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

from skimage import data,color import matplotlib.pyplot as plt from skimage.morphology import disk import skimage.filters.rank as sfr img =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) 

 

 


二、bottomhat 與 tophat
bottomhat: 此濾波器先計算圖像的形態學閉運算,而後用原圖像減去運算的結果值,有點像黑帽操做。

 

bophat: 此濾波器先計算圖像的形態學開運算,而後用原圖像減去運算的結果值,有點像白帽操做。
格式:

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

selem表示結構化元素,用於設定濾波器。
下面是bottomhat濾波的例子:

from skimage import data,color import matplotlib.pyplot as plt from skimage.morphology import disk import skimage.filters.rank as sfr img =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) 
 

三、enhance_contrast

對比度加強。求出局部區域的最大值和最小值,而後看當前點像素值最接近最大值仍是最小值,而後替換爲最大值或最小值。
函數:

enhance_contrast(image, selem)

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

from skimage import data,color import matplotlib.pyplot as plt from skimage.morphology import disk import skimage.filters.rank as sfr img =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) 
 

四、entropy

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

entropy(image, selem)

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

from skimage import data,color import matplotlib.pyplot as plt from skimage.morphology import disk import skimage.filters.rank as sfr img =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) 

 

 


五、equalize
均衡化濾波。利用局部直方圖對圖像進行均衡化濾波。
函數格式:

 

equalize(image, selem)

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

from skimage import data,color import matplotlib.pyplot as plt from skimage.morphology import disk import skimage.filters.rank as sfr img =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) 
 

 

六、gradient
返回圖像的局部梯度值(如:最大值-最小值),用此梯度值代替區域內全部像素值。
函數格式:

gradient(image, selem)

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

from skimage import data,color import matplotlib.pyplot as plt from skimage.morphology import disk import skimage.filters.rank as sfr img =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) 
 

 

七、其它濾波器
濾波方式不少,下面再也不一一詳細講解,僅給出核心代碼,全部的函數調用方式都是同樣的。
最大值濾波器(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數字圖像處理

相關文章
相關標籤/搜索