python skimage圖像處理(二)


python skimage圖像處理(二)

 

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

 

圖像簡單濾波

對圖像進行濾波,可以有兩種效果:一種是平滑濾波,用來抑制噪聲;另一種是微分算子,可以用來檢測邊緣和特征提取。
skimage庫中通過filters模塊進行濾波操作。
1、sobel算子
sobel算子可用來檢測邊緣
函數格式為:

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) 
 

2、roberts算子

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

edges = filters.roberts(img) 

3、scharr算子
功能同sobel,調用格式:

edges = filters.scharr(img) 

4、prewitt算子
功能同sobel,調用格式:

edges = filters.prewitt(img) 

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

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越小,邊緣線條越細小。
6、gabor濾波
gabor濾波可用來進行邊緣檢測和紋理特征提取。
函數調用格式:

 

skimage.filters.gabor_filter(image, frequency) 

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

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的結果圖

7、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() 
 

 

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

9、水平、垂直邊緣檢測

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

水平邊緣檢測: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() 
 

 

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

10、交叉邊緣檢測

可使用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模塊中。
我們可以手動指定一個閾值,從而來實現分割。也可以讓系統自動生成一個閾值,下面幾種方法就是用來自動生成閾值。

1、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進行分割得下圖:

 

 

 

2、threshold_yen
使用方法同上:

thresh = filters.threshold_yen(image) 

返回閾值為198,分割如下圖:

 

 

 

3、threshold_li
使用方法同上:

thresh = filters.threshold_li(image) 

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

 

 

 

4、threshold_isodata
閾值計算方法:

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

使用方法同上:

thresh = filters.threshold_isodata(image) 

返回閾值為87,因此分割效果和threshold_otsu一樣。
5、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模塊,不要和繪制圖像搞混了。
1、畫線條
函數調用格式為:

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) 
 

2、畫圓
函數格式:

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) 
 

 

3、多邊形
函數格式:

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) 
 

 

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

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) 
 

 

5、貝塞兒曲線
格式:

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) 
 

 

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

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) 
 

 

7、空心橢圓
格式:

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子模塊內。

1、膨脹(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) 

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

2、腐蝕(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) 

用此函數比處理灰度圖像要快。
3、開運算(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) 

用此函數比處理灰度圖像要快。
4、閉運算(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) 

用此函數比處理灰度圖像要快。
5、白帽(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') 
 

 

6、黑帽(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模塊來設定。

1、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) 

 

 


2、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) 
 

3、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) 
 

4、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) 

 

 


5、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) 
 

 

6、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) 
 

 

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數字圖像處理


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM