Thresholding and measuring intensity in fluorescence images

Hi everybody

I am running immunofluorscence staining on human sections. The plan is to measure mean fluorescence intensity in 2D images. In previous studies I used to use imageJ to measure the mean value (open image—>analyze—>measure). Now as I need to measure the intensity in many images, I am trying to develop an automated method in image J to threshold and measure the intensity. I am still not experienced with writing macros in imageJ, however, I have recorded the below simple macro where I first apply “color threshold” then I measure the intensity in single images.

run(“Color Threshold…”);

I have few questions in this regards

1- Is applying threshold suitable method to exclude the the black physical holes in the images?
2- Is measuring mean value the best way to get feedback about the fluorescence intensity (thereby the protein levels) in the region of interest?
3- When I want to threshold an image, I usually go to (image–adjust–color threshold), then I select a thresholding method “f.x Huang”. Is that all what I need to do or do I need afterwards to click “select” in order to apply the selected thresholding method to the opened image?
4- As my study include several groups (control vs disease), how can I set the same threshold to all images?
5- How can I threshold and measure the mean value in batch of images automatically without the need to manually open single images one by one, which is very time consuming?.

Fluoscence image before thresholding.tif (4.0 MB)


Hi Abdel,

welcome to the forum! If I get this right, your images do have a foreground and a background and you want to measure the mean/max/min/median grey value of pixels in the foreground?

The ImageJ Macro way to do this could look something like this:

run("Set Measurements...", "mean min median display redirect=None decimal=2");

directory = "C:/pathtoyourimages/";
images = getFileList(directory);  // this returns a list of all files in the directory
flag = true;

// go through all images
for (i = 0; i < images.length; i++) {

	// exclude non-tif files
	if (!endsWith(images[i], "tif");) {

	open(directory + images[i]);

	// this is only done for the first image
	if (flag) {
		setAutoThreshold(method);  // method can be Huang, Default, etc - any of the ImageJ methods
		getThreshold(lower, upper);  // memorize the threshold values from first image
		flag = false;

	setThreshold(lower, upper);
	run("Create Selection");  // create a ROI around the areas above the threshold


The catch here is obviously that you’re images are RGB images. Have these images been acquired with a colorcamera? Or is this a signal from some fluorescent dye? In the second case, you are somehow converting your images into RGB format along the way, which is not desirable for analysis. I would expect that your images are originally in 16bit format - I would recommend you to leave that untouched.

An alternative solution for you could be to use Ilastik for a segmentation of foreground and background. You can train this segmentation on multiple images so that it should work for all of your images. You could then write a little script to segment all your images and measure the fluorescence intensity within the segmented areas.