Python如何对图像二值化(li算法)
的有关信息介绍如下:图像二值化是对图片进行识别的一种主要的技术手段之一,Python中有常用的图像二值化函数,li算法是其中一个比较常用的方法之一。
打开IDLE,即Python shell界面;
载入相关的库文件:
from skimage import data,color,filters
import matplotlib.pyplot as plt
读取一个图片,这里读取包内的图片文件,并将其灰度化处理:
image=color.rgb2gray(data.camera())
对图片进行li算法运算,采用以下代码:
thresh = filters.threshold_li(image)
dst =(image <= thresh)*1.0
采用下面的代码查看,二值化以后的图片:
plt.imshow(dst,plt.cm.gray)
plt.show()
查看我们的图片效果如下。