13
$\begingroup$

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

$\endgroup$
  • $\begingroup$ If you just want information about the components (centroid, caliper length), ComponentMeasurements should be more useful than SelectComponents $\endgroup$ – Niki Estner Dec 7 '12 at 13:59
  • $\begingroup$ No, I want to know how you can use these functions to count the cell (examples) $\endgroup$ – Glenn Dec 7 '12 at 14:04
  • 3
    $\begingroup$ Have you looked at MorphologicalComponents ? $\endgroup$ – image_doctor Dec 7 '12 at 14:11
  • $\begingroup$ I have an impression that this is not the original image. What is the very original image you start from? $\endgroup$ – Vitaliy Kaurov Dec 7 '12 at 17:13
  • $\begingroup$ 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` $\endgroup$ – Vitaliy Kaurov Dec 9 '12 at 9:03
17
$\begingroup$

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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