Threshold settings

Hi all,
I’m trying to analyze a set of immunofluorescence staining images. I already have a short macro to detect the actual signal but now I struggle to measure a background signal for background normalization.
My PI suggested to set a treshold for every picture to measure the mean intensities of the first 3% or 10% of the histogram. However, I have to set this threshold manually for every single image because the histograms are quite different. Is there a way to set the treshold to a set relative value automatically so I can include it into a macro?

Thank you so much in advance!

@5-mC

You can use the Auto Threshold methods … you can actually do a quick ‘test’ by running Auto Threshold using ‘try all ’ - then you’ll get a montage of all the algorithm outputs and you can see which is best for your particular case. You should apply the same method to all images you are processing.

If you want to learn more about the Threshold command and options… read this section of the ImageJ User Guide . This should explain all the functionality.

To get the nth percentile threshold, you need to get the histogram and do the cumulative distribution function to find out at which value you passed the target value.
The macro below assumes that your objects are on the “dark” side of the histogram:

// Percentile threshold
w=getWidth();
h=getHeight();
px=w*h;
p = getNumber("Percentile", 10);
getHistogram(values, counts, 256);
tot=0;
thr=0;
for (i=0;i<256;i++){
  tot=tot+counts[i];  
  if (tot/px*100<p) thr=i;
}

setThreshold(0,thr+1);
print (thr+1);
2 Likes