python如何对图片二值化处理(isodata算法)

2025-10-19 11:13:56

1、这里要使用winPython软件,且要安装有相关的工具包;

这里首先打开IDLE界面,也就是shell;

导入时的代码(若是报错,则可能没有安装相关的包)

from skimage import color,filters,data

import matplotlib.pyplot as plt

python如何对图片二值化处理(isodata算法)

2、采用以下代码读取一张图片,并灰度化处理,这里用到了包内自带的图片:

image=color.rgb2gray(data.camera())

python如何对图片二值化处理(isodata算法)

3、isodata是具体的算法是比较复杂的方法,这里不介绍理论了,采用以下指令就可以进行灰度化处理:

thresh = filters.threshold_isodata(image)

dst =(image <= thresh)*1.0

python如何对图片二值化处理(isodata算法)

4、采用以下代码查看我著块们的二值化后的图片:

plt.figure('畜罪伐isodata') 

plt.subplot(121) 

plt.title('原图')

plt.imshow(image,plt.cm.gray) 

plt.subplot(122)

plt.title('二值化图') 

plt.imshow(dst,plt.cm.gray) 

plt.show()

python如何对图片二值化处理(isodata算法)

5、查愁联看二值化后的结果如下。

python如何对图片二值化处理(isodata算法)

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢