使用Python进行彩色图像分割

时间:2014-06-09 05:37:19

标签: python-2.7 image-segmentation

我有很多照片如下: target picture example

我的目标是识别那些"珠子",尝试用圆圈标记它,并计算检测到的数字。

我尝试通过Python使用图像分割算法,源代码如下:

from matplotlib import pyplot as plt
from skimage import data
from skimage.feature import blob_dog, blob_log, blob_doh
from math import sqrt
from skimage.color import rgb2gray
from scipy import misc # try

image = misc.imread('test.jpg')
image_gray = rgb2gray(image)

blobs_log = blob_log(image_gray, max_sigma=10, num_sigma=5, threshold=.1)
# Compute radii in the 3rd column.
blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

blobs_dog = blob_dog(image_gray, max_sigma=2, threshold=.051)
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

blobs_doh = blob_doh(image_gray, max_sigma=2, threshold=.01)

blobs_list = [blobs_log, blobs_dog, blobs_doh]
colors = ['yellow', 'lime', 'red']
titles = ['Laplacian of Gaussian', 'Difference of Gaussian',
          'Determinant of Hessian']
sequence = zip(blobs_list, colors, titles)

for blobs, color, title in sequence:
    fig, ax = plt.subplots(1, 1)
    ax.set_title(title)
    ax.imshow(image, interpolation='nearest')
    for blob in blobs:
        y, x, r = blob
        c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
        ax.add_patch(c)

plt.show()

迄今取得的最佳成绩仍不理想: One of the results obtained

我该如何改进?

2 个答案:

答案 0 :(得分:1)

您可以使用Gimp或Photoshop测试一些滤镜和颜色更改,以区分圆圈与背景。亮度和对比度调整可能有效。然后,您可以应用边缘检测器来检测圆圈。

答案 1 :(得分:1)

通过将此图像转换为灰度,您可以有效地抛弃您必须分割珠子的最强大的提示 - 它们独特的绿色。尝试运行相同的代码,但替换

image_gray = rgb2gray(image)

image_gray = image[:,:,1]