python数字图像处理（11）：图像自动阈值分割

1、threshold_otsu

skimage.filters.threshold_otsu(imagenbins=256)

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

2、threshold_yen

`thresh = filters.threshold_yen(image) `

3、threshold_li

`thresh = filters.threshold_li(image)`

4、threshold_isodata

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

`thresh = filters.threshold_isodata(image)`

block_size: 块大小，指当前像素的相邻区域大小，一般是奇数（如3，5，7。。。）

method: 用来确定自适应阈值的方法，有’mean’, ‘generic’, ‘gaussian’ 和 ‘median’。省略时默认为gaussian

```from skimage import data,filters
import matplotlib.pyplot as plt
image = data.camera()

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

```dst1 =filters.threshold_adaptive(image,31,'mean')