# Count Elements in Image

I have the following image: img1

I'm trying to count al these colored cells and draw a circle around them. I really don't now how I can use SelectComponents for this image. And EdgeDetect has the following result: img2

Maybe some tips or examples.

Greetings

• If you just want information about the components (centroid, caliper length), ComponentMeasurements should be more useful than SelectComponents Dec 7 '12 at 13:59
• No, I want to know how you can use these functions to count the cell (examples) Dec 7 '12 at 14:04
• Have you looked at MorphologicalComponents ? Dec 7 '12 at 14:11
• I have an impression that this is not the original image. What is the very original image you start from? Dec 7 '12 at 17:13
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign Dec 9 '12 at 9:03

I will follow algorithm described in the following blog, but will have to modify some parameters for your case. You can also drop FillingTransform from the blog code because you don't have holes in your regions.

rbc = ImageCrop[   Import["http://i.stack.imgur.com/wOJps.png"], {300, 340}];

b = DeleteSmallComponents[ColorNegate[Binarize[rbc, .81]], 50];
distT = DistanceTransform[b, Padding -> 0];
Method -> "Rainfall"];

cells = SelectComponents[w, "Count", 500 < # < 3000 &];
measures =
ComponentMeasurements[
Show[rbc,
Graphics[{Blue, Circle @@ # & /@ (measures[[All, 2, 1 ;; 2]]),
MapThread[Text, {measures[[All, 2, 3]], measures[[All, 2, 1]]}]}]]


Then bare number of circled cells can be computed with

measures // Length
`

16

• I have used the blog you referred to. Thank you for your help! Dec 9 '12 at 12:08
• @Glenn please register your account. Then you will be able to use the 41 "reputation" points you already have to post comments. Dec 9 '12 at 13:22