Python count crystals (total and by color)

Oscar J. Delgado oscarjdm19 at gmail.com
Tue Apr 28 15:28:21 EDT 2015



Good morning to all,

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 examples in the "skimage" gallery,  but 
I have a big issue as the crystals color and the background color (an 
alcohol solution) are almost the same (transparent). So far I have 
successfully segmented the particles using the following code:
import matplotlib.pyplot as plt
import numpy as np

from skimage.morphology import disk
from skimage.filters import rank, threshold_adaptive
from skimage.util import img_as_ubyte
from skimage.measure import label
from skimage.color import label2rgb

import pylab
from PIL import Image

path = r".../11-3.jpg"

img = pylab.array(Image.open(path).convert('L'))
image = img_as_ubyte(img)


# denoise image
denoised = rank.median(image, disk(10))

#local gradient
gradient = rank.gradient(denoised, disk(2))

#threshold_adaptive filter
threshold = threshold_adaptive(gradient, 15000)

# label image regions
label_image = label(threshold)
image_label_overlay = label2rgb(label_image, image=image)


# display results
fig, axe = plt.subplots(ncols=1, figsize=(10,5))
axe.imshow(image, cmap=plt.cm.gray, interpolation='nearest')
axe.imshow(gradient, interpolation='nearest', cmap=plt.cm.spectral, alpha=
0.2)
axe.imshow(threshold, interpolation='nearest', cmap=plt.cm.binary_r, alpha=
0.2)
axe.imshow(label_image, alpha=0.2)

axe.axis('off')
fig.subplots_adjust(hspace=0.01, wspace=0.01, top=1, bottom=0, left=0, right
=1)

plt.show()


Please note I had to increase the threshold_adaptive to more than 10,000 in 
order to get the crystals, but this is really slow.  


I am still working on how identify if the particles segmented are blue 
tinted (nothing yet!).


I really really will 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:

[image: Cell Image]

Best!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20150428/281f7adf/attachment.html>


More information about the scikit-image mailing list