Color image segmentation with Python
Question: I have many pictures as below: ![target picture
example](http://i.stack.imgur.com/C31sn.jpg)

My objective is to identify those "beads", try to mark it with a circle, and
count the detected numbers.

I tried to use image segmentation algorithms via Python and the source codes
are as below:

    
    
    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()
    

The best results obtained so far are still unsatisfactory: ![One of the
results obtained](http://i.stack.imgur.com/bV6xD.png)

How can I improve it ?


Answer: You could use Gimp or Photoshop and test some filters and colors changes to
differentiate the circles from the background. Brightness and Contrast
adjustments may work. Then you can apply an Edge detector to detect the
circles.

