1.概念:从一幅图像中利用阈值分割出我们需要的物体部分(当然这里的物体可以是一部分或者整体)。这样的图像分割方法是基于图像中物体与背景之间的灰度差异,而且此分割属于像素级的分割。
2.代码实现:
from skimage import data,filters
import matplotlib.pyplot as plt
import cv2
# image = data.camera()
image=cv2.imread('./test.jpg',1)
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()3.算法效果:

参考博客:http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/imgproc/threshold/threshold.html
本文介绍了一种基于灰度差异的图像分割方法——阈值分割,并通过Python代码实现了该技术。这种方法能有效地区分图像中的目标物与背景,适用于像素级别的图像处理任务。

2843

被折叠的 条评论
为什么被折叠?



