Counting # of foci per nucleus

I’m trying to count the # of red foci per blue nucleus for this image here.

And the problem is that on imageJ it overestimates the area of the nucleus because it thinks the surrounding red dots around the nucleus is also part of the nucleus, as imageJ converts images to black and white

:

I did the following to try to do automated counting of nucleus:
-Plugins > Feature Extraction > Feature J Lapalcain
-Image > Adjust> Threshold
-Process > Binary > Make Binary
-Process > Binary > Fill Holes
-Process > Binary > Dilate
-Watershed (what I’m going to do next…)
-Analyze Particles


As you can see in this picture, the nuclei nuclei appear to be larger than they actual should be (compare with the blue nuclei in the colored picture), because imageJ erroneously involve the red dots surrounding the nuclei also. How can I prevent this from happening? I only want to count the blue area and disregard the red area. I would really appreciate your help. Thank you.

Hi @amagais

First, I would not go via the Laplacian filtering in this case. For nuclei, mostly a small median filter does a decent job.
Thereafter, in the course of your post-processing procedure on the binary image it is recommendable to include a watershed for nuclear separation. You could also test Watershed Irregular Features or the Adjustable Watershed.

To analyze the spots per nucleus you also need to extract the spots similarly as to your nuclei (with different pre-processing steps) and then you can apply the Speckle Inspector. There are other possibilities like Find Maxima but the latter you would need to run recursively by restricting it to the individual nuclear areas which is initially more tricky if you are not so experienced with any scripting.

Nevertheless you can try to use the Find Maxima with the “maxima with tolerance” as output option chosen. This might give you a simple possibility to extract the spots.

In general, I would also recommend to make your features of interest (nuclei, spots) showing up in white and the background in black. This is the most common representation as asumed by many plugins in IJ.
First check if your image is shown by using an inverted LUT (you see this in the upper part of the image). If yes, test how the image looks like when you apply Image►Lookup Tables►Invert LUT. If no inverted LUT is shown but your features are displayed in black run Edit►Invert.

Hope this helps you in getting started

1 Like

Hi @biovoxxel
Thank you for your response. I tried your way of nuclear counting by using small median filter (with radius of 15 pixels) instead of using Laplacian filtering. Then, I did watershed and inversion. And it looks like this:

I think I am still having the same issue being that the area of the nucleus is overestimated, since it also counts the red region that surrounds the blue nucleus (compare with the colored image). Can you please tell me what I’m still doing wrong? Also, I’m having a hard time accurately separating the nuclei (watershed is inaccurately dividing the nucleus)…

can you post a link with the original image, then we could try to help you more specifically

Yes! This is the original image:

Ok, just to get it straight, I thought you are interested in the foci per nucleus, but is it rather like this, that you want to count the foci per cell (complete area of the cells)?
Because depending on the question we would take either the DAPI channel or the red channel of the cellular staining. In the latter case it will be rather difficult to get a nice separation of cells due to the diffuse dim signal and proximity.
Potentially, you can also give the Trainable Weka Segmentation a try.

1 Like

Yes, I want foci per nucleus. The nucleus is the area that is stained in blue with DAPI. The red dots around the blue nucleus are not part of the nucleus. So only doing the DAPI channel would definitely work, because it would only look at the blue nucleus, which is what I want. But I don’t know how to do this because on imageJ it converts the image to black and white?

Then we need the channel with only the nuclei in addition of the combined image of the two channels (best as a composite image… a stack with individual accessable channels). Because I would then extract the area of only the nuclei which is way easier compared to the whole cell area and it is what you finally want to analyze.
The red channel we need only to segment the spots for final counting.

Edit: or can you provice a link to the very original image in a dropbox folder or something similar? That would make it easiest

1 Like

Here’s a drop box link:

Please let me know if you can view this. I can try sending it again if it doesn’t work.

**It’s a tiff image and it appears to be completely black --to view the image it has to be opened on imageJ.

I actually figured it out by getting help from @biovoxxel !! I used ROI manager and stacked the only DAPI filtered image with the image that has both channels (with the red dots).

I know that Find Maxima will count all the foci on the image, but I now just want to count the foci within the yellow circle… Does anyone know how to do that? Please let me know. Thank you again for your help.

**note: I accidentally started to analyze a different picture from here and on…

1 Like

So, for all interested in the topic…
here is a rather simple macro which does the job of spot counting for the images from @amagais.

var tolerance = 30;

originalImage = getTitle();
run("8-bit");
run("Overlay Options...", "stroke=red width=1 fill=none set");
run("Median...", "radius=6");
run("Subtract Background...", "rolling=125 sliding");
run("Auto Threshold", "method=Default white");
roiManager("Reset");
run("Analyze Particles...", "pixel exclude clear add");

waitForUser("Select the image for spot counting");
run("8-bit");

run("Gaussian Blur...", "sigma=1");
run("Subtract Background...", "rolling=25");

for(i=0; i<roiManager("count"); i++) {
	roiManager("select", i);
	run("Find Maxima...", "noise="+tolerance+" output=[Count]");
	run("Find Maxima...", "noise="+tolerance+" output=[Point Selection]");
	run("Add Selection...");
}

And this is how it looks like:

5 Likes

Roi.contains(x, y)
Returns “1” if the point x,y is inside the current selection or “0” if it is not. Aborts the macro if there is no selection. Requires 1.49h. See also: selectionContains.

from https://imagej.net/developer/macro/functions.html

ROI functions

I also want to include the foci on the surface of the nuclei for my count. Is it possible to change the coding a little bit to make this happen? Thank you so much for all the help.

What do you mean when talking about “surface” on a 2-dimensional image?

If you also want to measure the immediate periphery of each object, you can dilate each object before measuring. The necessary code can be obtained by running the macro recorder while performing Process > Binary > Dilate:

run("Dilate");
1 Like

Yes, I mean the immediate periphery of each object. I tried “dilating” by adding it to the code, but I think it’s in the wrong part of the code? Because now it only recognizes two particles out of the many particles (shown on picture in the bottom). Where should I place the “dilate” function in the code?

var tolerance = 30;

originalImage = getTitle();
run("8-bit");
run("Overlay Options...", "stroke=red width=1 fill=none set");
run("Median...", "radius=6");
run("Subtract Background...", "rolling=125 sliding");
run("Auto Threshold", "method=Default white");
run("Dilate");
roiManager("Reset");
run("Analyze Particles...", "pixel exclude clear add");

waitForUser("Select the image for spot counting");
run("8-bit");

run("Gaussian Blur...", "sigma=1");
run("Subtract Background...", "rolling=25");

for(i=0; i<roiManager("count"); i++) {
	roiManager("select", i);
	run("Find Maxima...", "noise="+tolerance+" output=[Count]");
	run("Find Maxima...", "noise="+tolerance+" output=[Point Selection]");
	run("Add Selection...");
}

1 Like

I’d suggest to put it into the for loop, just after selecting the ROI in the ROI Manager.

To understand what each line of the macro that @biovoxxel set up for you is doing, I suggest to run the commands one by one from the menu, that gives a good impression of what is going on. You can use the command finder (Plugins > Utilities > Find commands… or type L) to find the menu commands corresponding to each run() command.

2 Likes

Could you show a little detail how to get results form? how to select the Label and count?
My result form showed that there are no count number in the blue channel label. How to select only label (green) with count number or only green only. One label with RawIntDen and count number.

image

Thank you