# python数字图像处理（10）：图像简单滤波

skimage库中通过filters模块进行滤波操作。

1、sobel算子

sobel算子可用来检测边缘

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算子

edges = filters.scharr(img)

4、prewitt算子

edges = filters.prewitt(img)

5、canny算子

canny算子也是用于提取边缘特征，但它不是放在filters模块，而是放在feature模块

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

6、gabor滤波

gabor滤波可用来进行边缘检测和纹理特征提取。

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

7、gaussian滤波

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

8.median

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、水平、垂直边缘检测

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、交叉边缘检测

 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)

posted @ 2016-01-12 18:28  denny402  阅读(...)  评论(...编辑  收藏