Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have the following image: img1

enter image description here

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

enter image description here

Maybe some tips or examples.

Greetings

share|improve this question
    
If you just want information about the components (centroid, caliper length), ComponentMeasurements should be more useful than SelectComponents –  nikie Dec 7 '12 at 13:59
    
No, I want to know how you can use these functions to count the cell (examples) –  Glenn Dec 7 '12 at 14:04
3  
Have you looked at MorphologicalComponents ? –  image_doctor 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? –  Vitaliy Kaurov 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` –  Vitaliy Kaurov Dec 9 '12 at 9:03
show 1 more comment

1 Answer

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];
marker = MaxDetect[ImageAdjust[distT], 0.02];
w = WatershedComponents[GradientFilter[b, 3], marker, 
   Method -> "Rainfall"];

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

enter image description here

Then bare number of circled cells can be computed with

measures // Length

16

share|improve this answer
    
I have used the blog you referred to. Thank you for your help! –  Glenn 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. –  Mr.Wizard Dec 9 '12 at 13:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.