14
$\begingroup$

I am looking for an easy method to count individual particles in a microscopic image. It is quite difficult for Mathematica to detect them, because they are touching each other. I am quite a beginner in Mathematica and can't figure out how I can remove the white centers of the particles. I know there are some similar questions around, but non where the particles have bright centers AND are touching each other.

This is the image:

enter image description here

Thanks a lot in advance.

$\endgroup$
2
  • 3
    $\begingroup$ Try this blog post: blog.wolfram.com/2012/01/04/… $\endgroup$ Apr 29, 2015 at 16:19
  • $\begingroup$ That is what I did first. But my image is too crowded with particles. Too many background spaces are clustered together and I just get a very big particle. $\endgroup$
    – user28123
    Apr 29, 2015 at 16:34

2 Answers 2

20
$\begingroup$

The simplest thing that can work is to search white blobs instead of black blobs, and ignore the ones that have low circularity (calculated from the area/perimeter^2 ratio):

img = Import["https://i.stack.imgur.com/LaMAg.jpg"]
img = ColorConvert[img, "Grayscale"];
components = 
  ComponentMeasurements[
   MorphologicalBinarize[Closing[img, DiskMatrix[5]]], {"Centroid", 
    "Circularity", "EquivalentDiskRadius"}, #2 > 0.75 &];

Show[img, 
 Graphics[{Red, Thick, Circle @@@ components[[All, 2, {1, 3}]]}]]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ At first glance I thought you were the original poster. Odd coincidence of monikers there. (And a nice answer to a nice question, both of which get votes from me.) $\endgroup$ Apr 30, 2015 at 14:05
2
$\begingroup$

Preprocess like this:

ClusteringComponents[
  Erosion[Binarize[mySpheres, {.5, .98}], DiskMatrix[1]]] // Colorize

enter image description here

$\endgroup$
5
  • $\begingroup$ This doesn't help in my case. Maybe my question was unclear. I would like to get a binarizes image where the particles are black (also the centers) and the background is white. From there, I think I know what to do, but I just can't get the particles to be all filled black. $\endgroup$
    – Niki
    Apr 30, 2015 at 9:25
  • $\begingroup$ Oh.... then just use ColorNegate[]. $\endgroup$ Apr 30, 2015 at 10:20
  • $\begingroup$ But then my particles are not their original size, but smaller!? $\endgroup$
    – Niki
    Apr 30, 2015 at 10:47
  • $\begingroup$ So what? You're counting them. $\endgroup$ Apr 30, 2015 at 10:48
  • $\begingroup$ Yes, but I want to determine the equivalent sphere diameter in the end and sphericity and so on ... of the original particle size $\endgroup$
    – Niki
    Apr 30, 2015 at 11:06

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .