Question

I have been trying to make a macros for counting the cells in the image. However, I have a hard time removing the overlap between cells and for the program to distinguish between the clumps.

run("8-bit", "stack"); 
run("Subtract Background...", "rolling=5 light sliding stack"); 
run("Median...", "radius=1 stack"); 
run("Unsharp Mask...", "radius=0.8 mask=0.50 stack"); 
run("Invert LUT"); 
run("Auto Threshold", "method=Yen white stack"); 
run("Erode"); 
run("Erode"); 
run ("Watershed"); 
run("Analyze Particles...", "size=200-2000 circularity=0.50-1.00 show=[Count Masks] display exclude clear summarize add in_situ");

I am using the macros on a stack of images.

I also tried using GreyscaleReconstruct but I was not that successful either. I used this code

run("Open..."); 
selectWindow("A.png"); 
setBatchMode(true); 
a=getTitle(); 
run("8-bit"); 
run("Invert LUT"); 
run("Gaussian Blur...", "sigma=2"); 
run("Duplicate...", "title=_seed"); 
run("Minimum...", "radius=3"); 
run("GreyscaleReconstruct ", "mask="+a+" seed=_seed create"); 
imageCalculator("Subtract create", a,"_seed"); 
selectWindow("Result of "+a); 
rename("WhiteTopHatReconstructed"); 
run("Auto Threshold", "method=Otsu white"); 
setBatchMode(false); 
run("Analyze Particles...", "size=200-2000 circularity=0.50-1.00 show=[Count Masks] display exclude clear summarize add in_situ"); 

Pleas help (either with the first or second code!) Thanks! :)

Here is an image of what am I analyzing.enter image description here

Was it helpful?

Solution

Overlapping objects can be a tough problem. The Fiji wiki page on Segmentation discusses two primary ways of approaching image segmentation: the Trainable Weka Segmentation plugin, and a more flexible macro-based workflow. So far, your attempts fall more into the latter category. In your case, I would suggest giving the former a try.

I played a bit with Trainable Weka Segmentation and got some potentially promising, but still-not-yet-good-enough, results:

Trainable Weka Segmentation

I divided the image into four classes: background, the dark area in the center ("blob"), the cells themselves ("class 1") and the median line running through each cell ("class 2"). My idea was to isolate those median lines, since from them it is easier to find cell centers, and your cells are very regular in shape. Once you have the centers the problem of overlapping cells largely disappears. And since the median lines are directional you could even compute angles for cell orientation, if that is useful for your analysis.

Here is a mask of only class 2:

Mask

Unfortunately, on my first attempt the cell borders also trained as class 2, but with a bit more tuning perhaps that problem could be eliminated. You can also control which image features are used for classification in the Settings dialog, which might help the classification.

Once you have a good enough classifier, you can save it (Save classifier) and apply it to many more images in batch (Apply classifier). All of Trainable Weka Segmentation is also usable from scripts and macros, so you can combine it with some preprocessing and/or postprocessing if needed.

If you aren't able to get class 2 to stop identifying membranes in general, you could probably follow up by analyzing the mask itself for that particular shape to boil down the binary cell outline shapes to cell centers. Perhaps there is a morphological operator that will help here, but I am no expert, so I suggest asking on the ImageJ mailing list which several such experts read.

Another project you could check out which might help with your analysis is CellProfiler. It provides an excellent suite of image processing modules and they also have an excellent and responsive forum where you can ask for help with specific data like this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top