Trouble setting threshold to count particles

Good day image experts,

I am having trouble setting the threshold on an image to be used to count particles. The particles in the image are protein particles that were stained with a fluorescent dye.

I was successful at thresholding the image and count the particles ONCE, but when I tried to duplicate the steps I get a blank image and only one or two particles that are being counted.

original image no processing:
with insert original.tif (7.9 MB)

image with threshold:
with insert original with filter.tif (3.9 MB)

image after analyse particles:
blank analyze particles.tif (3.9 MB)

These are the steps I took and it worked one time, but I haven’t being able to duplicate the results.

  1. Gaussian blur to remove noise from image
  2. LUT invert
  3. Threshold
  4. Analyze particles.

Any guidance will be appreciated as well as explanation as to why it might have worked once and not continued to work.

Thank you,
Cindy

Did you invert the LUT back?

If you are macroing this, the macro recorder sometimes only records a threshold comment, not the actual threshold set, and that needs to be edited in the text or copied in another way.

@Research_Associate, I did not set the LUT back in my original process, but I tried again reverting the LUT and still no luck. I’m not using a macro. I’m setting the threshold via the slider.

1 Like

You may want to generate a macro then so that we can see what you are doing :slight_smile: I have no idea what your size exclusion or other types of settings might be on analyze particles or any of the other steps.

I used the macro recorder to record the steps I’m doing:

run(“Gaussian Blur…”, “sigma=2”);
run(“Invert LUT”);
setAutoThreshold(“Default dark”);
//run(“Threshold…”);
setOption(“BlackBackground”, false);
run(“Convert to Mask”);
run(“Close”);
run(“Analyze Particles…”, " show=Outlines display clear add");
selectWindow(“Drawing of with insert original.tif”);

Using something similar without any inverting I got:

selectWindow("with insert original.tif");
run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Default dark");
//run("Threshold...");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Close");

run("Analyze Particles...", "  show=Outlines display exclude add");
selectWindow("Drawing of with insert original.tif");



I did not invert anything.
Note that I did not include the exact threshold value in the macro. ~7765

If your threshold step looks like this:


The red is everything you are trying to keep.
Your image with threshold that you posted looks like it should work, though. Unless the LUT is inverted. You need the white spots to be where they are without the LUT being inverted.

I think I figured what I was doing wrong looking at the macro. The macro has run(“Convert to Mask”), but I never ran through this step to convert to mask. I went ahead and ran: process >binary>convert to mask and it worked.

Do you have to take this additional step (process >binary>convert to mask) in order for the analyze particles to work? This is the only thing I did different.

Convert to mask is part of the thresholding step, when you hit apply.

Also, makeBinary is dangerous, so make sure you understand how it functions, and how it’s function might change depending on your image.

When I do thresholding then I select apply I close the threshold window then go to analyze particles. This gives me a black image. But if I threshold, then make binary and analyze particles it does give me the results you showed above. What might be the cause of not creating a mask when I threshold?

It does threshold, you are just thresholding in the wrong direction. High vs low, so you get one big object, which is all of the empty space in your original image. Make binary defaults to “less stuff” is foreground.

Maybe a cleaner way to put it is your original image with threshold should look like this, and you should not invert it.

1 Like

Hi @Research_Associate,

This worked! Thanks a lot!

1 Like

I would also recommend checking Exclude on border to get rid of stuff like the line on the top of the image (in analyze particles).

1 Like

Great tip, thanks!

I have some areas that are more intense than others. Is there a way to separate the brighter from the less brighter? And separately count these?

1 Like

I am more familiar with other software, unfortunately. You could certainly do it as 2 steps, first thresholding from X to Y, and then from Y->max.

Notice in the last image above that the second bar is all the way to the right, which results in all objects being picked up. If you changed it from 65535 to 30000, you would only pick up objects of intermediate brightness (or any value, I made 30000 up).
The second time you run through the steps, you would set the first value to 30001 and the second value to 65535.

1 Like

Will try that. Thanks again!

1 Like

Hi Cindy,

why do you use thresholding in the first place? You could use FindMaxima to find the peak position of the particles followed by Gaussian fitting to get their intensity and size.

Best, Daniel.

Hi Daniel,

I’m a beginner to imageJ/FIJI and have seen this is the usual for counting particles.

Can you please elaborate further on FindMaxima and Gaussian fitting? I know of the gaussian filter. Is this the same as gaussian fitting?

Thanks,
Cindy