# Cell counting from an image file [closed]

I have a lot of cell culturing pictures. One of the example is as follows:

Every black dot represents a cell, and I need to count only the cells on the image.

I have a code to detect and count the number of cells.

locate = SystemDialogInput["FileOpen"];
img = Import[locate];
b = FillingTransform[ColorNegate[Binarize[img]]];
disT = DistanceTransform[b, Padding -> 0];
w = WatershedComponents[GradientFilter[b, 3], marker, Method -> "Rainfall"];
cells = SelectComponents[w, "Count", 0 < # < 500 &]; (*Pixel interval*)
measures = ComponentMeasurements[cells, {"Centroid", "EquivalentDiskRadius", "Label"}];
Grid[{{Style["Number of Cell is " <> ToString[Dimensions[measures][[1]]] <>
".", "Title"],
Button["Save it?",Export[DirectoryName[locate] <> FileBaseName[locate] <> ".txt","Number of Cell is " <> ToString[Dimensions[measures][[1]]] <>".     " <> DateString[]]]}, {Show[img,Graphics[{Blue, Circle @@ # & /@ (measures[[All, 2, 1 ;; 2]]), MapThread[Text, {measures[[All, 2, 3]], measures[[All, 2, 1]]}]}]]}}]


Here is the source for the code above.

Problem about this code, it detects the things are not cell. You can see in the following picture how it detect the edges and texts.

To sum up, I need to do two main things:

• to detect the cells only
• to make it user friendly for non-Mathematica users

Thank you for any help. If you need more explanation, please feel free to ask it.

## closed as off-topic by Karsten 7., Niki Estner, Dr. belisarius, Öskå, ciaoMar 17 '15 at 22:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "The question is out of scope for this site. The answer to this question requires either advice from Wolfram support or the services of a professional consultant." – Karsten 7., Niki Estner, Dr. belisarius, Öskå, ciao
If this question can be reworded to fit the rules in the help center, please edit the question.

• Just crop the image to the area with cells only. – Karsten 7. Mar 17 '15 at 16:28
• @Karsten7. "I have a lot of cell culturing pictures" and the specific requirement "to detect the cells only" strongly suggests that it is not an option to do this manually. – C. E. Mar 17 '15 at 16:51
• @Pickett If this is a laboratory setup where the position of the camera is fixed relative to the cell cultures, it only has to be done manually onces. If the relative position is not fixed, the black line encircling the area with the cells could be used to crop the image automatically. – Karsten 7. Mar 17 '15 at 17:04
• I think this question is out of scope for this site as finding a correct reliable solution requires access to all images and a detailed discussion when one dark area is counted as one or multiple cells and how to decide how many cells there are in the case of multiple cells. – Karsten 7. Mar 17 '15 at 17:14
• Just a note, your image quality isn't high enough to get a good count. The smaller cells are not clearly resolved, and some of the larger cells blur together. You need more resolution to resolve them. However, the limiting factor is not the number of pixels on your camera's sensor, but the quality of the camera's optics (the blur is spread over multiple pixels). I would suggest either using one or more of the following: stopping down your lens to f/8 or more, taking separate closeups of each cell group, or a lens with less distortion (I use the 40 mm Micro-NIKKOR for micrographs). – 2012rcampion Mar 17 '15 at 18:06