1

I have pictures from a microscope and I am trying to count the total number of crystal as well as those with specific colors (red, blue or yellow). In principle it looks possible to do it just by looking at the picture but considering I have to do it for over 200, I believe a script would be more effective.

My first approach was to follow the suggestions of a very similar problem (Finding number of colored shapes from picture using Python )however, my issue is that the crystal color and the background color (an alcohol solution) are almost the same (transparent), and therefore it has been impossible to get any successful result so far.

I have also checked the "skimage" module (http://scikit-image.org/) but I got the same issues with the crystal/background.

With the following code I can got something that start making sense, but it is still far from my objective:

import scipy
from scipy import ndimage

sand = scipy.misc.imread(img) # gray-scale image
sandf = ndimage.gaussian_filter(sand, 16)
T = 160 # set threshold by hand to avoid installing `mahotas`

# find connected components
#labeled, nr_objects = ndimage.label(sandf> T) #black-white
labeled, nr_objects = ndimage.label(sandf[:,:,0] > T) #colour
print ("Number of objects is %d " % nr_objects)


import matplotlib.pyplot as plt
plt.imshow(labeled)
plt.show()

I will really appreciate if anyone can give me a hand with this. I have tried even modifying the way I take the pictures but nothing. Again, I have two objectives: count the total number of particles and then count those particles that have a tint (red, blue or yellow)

Please find below one typical picture:

Cell Image

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199

3 Answers3

0

This is not an ideal solution but it gives a reasonable answer for the count.

import scipy, pylab, mahotas as mh
from scipy import ndimage

sand = scipy.misc.imread(img)
dnaf = ndimage.gaussian_filter(sand, 4)
T = mh.thresholding.otsu(dnaf)
labeled, nr_objects = ndimage.label(sand > T)
for i in range(20):
    dnaf = ndimage.gaussian_filter(dnaf, 1)
    T = mh.thresholding.otsu(dnaf)
    labeled, nr_objects = ndimage.label(sand < T)

labeled, nr_objects = ndimage.label(sand > T)
pylab.imshow(labeled)
pylab.show()
print(nr_objects)

This is an interesting problem. I'll try and find some more time to tackle it and give you a few other options.

dparadis28
  • 101
  • 2
0

Since your particles reflect a lot of light, wouldn't it be easier to process the images if you put the particles on a dark background? It should then be easier to separate the particles from the background.

kguest
  • 3,804
  • 3
  • 29
  • 31
  • Merci Emmanuelle. I already tried and using a dark background didn't work. You can identify better some bright spots but in general, the contours are merged with the background. – user2846810 Apr 22 '15 at 09:29
0

Transparent items are always difficult. My approach would be:

  • first remove the background/paint it black (as it is fairy uniformly colored) this should be doable.
  • detect and enhance the edges
  • color the edges black as well

Now you should be able to count the components

Rob Audenaerde
  • 19,195
  • 10
  • 76
  • 121