1. 本际云推荐 - 专业推荐VPS、服务器,IDC点评首页
  2. 云主机运维
  3. VPS运维

python数字图像处理之图像自动阈值分割示例

图像控制管理及时的python数字图像处理方法

作为本际云服务器推荐网的小编小本本,我想利用python数字图像技术对图像进行处理,主要包括对阈值等相关情况进行分割等处理方法。具体方法和内容如下。

python数字图像处理之图像自动阈值分割示例

阈值分割方法

阈值分割方法是图像处理中常见的方法之一,主要根据阈值将像素点进行分类,在python中可以通过threshold_otsu、threshold_yen、threshold_li、threshold_isodata、threshold_adaptive等方法进行实现。

具体实现方法

以下为不同阈值分割方法的具体实现方法,其中参数image指灰度图像。

threshold_otsu

函数调用格式:skimage.filters.threshold_otsu(image,nbins=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()

threshold_yen

函数调用格式:thresh=filters.threshold_yen(image)。返回一个阈值。

thresh=filters.threshold_yen(image)

threshold_li

函数调用格式:thresh=filters.threshold_li(image)。返回一个阈值。

thresh=filters.threshold_li(image)

threshold_isodata

阈值计算方法:threshold=(image[image<=threshold].mean()+image[image>threshold].mean())/2.0 。

函数调用格式:thresh=filters.threshold_isodata(image)。返回一个阈值。

thresh=filters.threshold_isodata(image)

threshold_adaptive

函数调用格式:skimage.filters.threshold_adaptive(image,block_size,method=’gaussian’)。

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

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

该函数直接访问一个阈值后的图像,而不是阈值。

dst=filters.threshold_adaptive(image,15)#返回一个阈值图像

结语

通过以上不同阈值分割方法的介绍,相信大家对python数字图像处理有了更深入的了解。希望这篇文章可以对大家有所帮助。

原创文章,作者:小编小本本,如若转载,请注明出处:https://www.benjiyun.com/yunzhujiyunwei/vps-yunwei/6815.html