# Analyze touching particles with holes in a microscopic image

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:

• Try this blog post: blog.wolfram.com/2012/01/04/… – dr.blochwave Apr 29 '15 at 16:19
• 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. – user28123 Apr 29 '15 at 16:34

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["http://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}]]}]]


• 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.) – Daniel Lichtblau Apr 30 '15 at 14:05

Preprocess like this:

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


• 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. – Niki Apr 30 '15 at 9:25
• Oh.... then just use ColorNegate[]. – David G. Stork Apr 30 '15 at 10:20
• But then my particles are not their original size, but smaller!? – Niki Apr 30 '15 at 10:47
• So what? You're counting them. – David G. Stork Apr 30 '15 at 10:48
• Yes, but I want to determine the equivalent sphere diameter in the end and sphericity and so on ... of the original particle size – Niki Apr 30 '15 at 11:06