Measuring fluorescent area with heterogeneous images

Hello guys ;
I’m totally new with the ImageJ software…
I tried to determine the covering surface of a biofilm colored by Acridine orange.
I have some photos which I can exploit with a macro to transform this :
60 1 6.tif (14.4 MB)

into this :
60 1 6.tif (red).tif (4.8 MB)

with this macro :

imageTitle = getTitle();
run("Fast Filters", "link filter=[background from minima] x=5 y=5 preprocessing=none offset=128");
run("Split Channels");
selectWindow(imageTitle + " (green)");
selectWindow(imageTitle + " (blue)");
selectWindow(imageTitle + " (red)");
run("Auto Threshold...", "method=Intermodes ignore_black white");
run("Set Measurements...", "area area_fraction display redirect=None decimal=2");

But I have some trouble with this kind of pictures :
15 2 7.tif (14.4 MB)

My macro can’t work and find “a lot of” biofilm (97% coverage)…
15 2 7.tif (red).tif (4.8 MB)

Do you guys have some advices ?
Thanks a lot for your reply !

Nobody can help me ?
I tried Cellprofiler but the problem still there …

Do you have any control over the acquisition? It looks to me like the pictures were taken with automatic gain adjustment? So image 15-2-7, which I assume should be blank, has a much higher gain than 60-1-6? Your analysis problem could be a lot easier if you can configure the acquisition to use a fixed gain so that only fields that actually have fluorescent cells have significant contrast.

Thanks for your reply !
You’re alright, Pictures were taken with an automatic gain adjustement.
Is it possible to use (determine with an automatic threshold, area covered by biofilms) pictures with this pparameter on ?
I already made a thousand of pictures with this parameter on … And I can’t make those experiments another time with the parameter off …

It looks very difficult to me. I tried a few things liking looking at color differences, high pass filtering and edge detection but nothing works very well.

Maybe the images have some metadata that would enable you to figure out the gain and/or integration time for each image? I checked your example images but I didn’t see anything in the tiff tags.

Dear LouisD,
I tried Bandpass filter + H_watershed the results are very nice for your bateria and your blank
BUT when the fluorescence is too big I still have some problems. Can you try this macro?
This is the result I have. Don’t forget to remove the space in the folder name and file name. Do use the same folder for input and output.
The macro in the output will save the mask and an CSV file with the total area
bacteria :


1 Like

Dear LouisD,
I send you the macro and I will help you to use it to answer to your email.
Please download Fiji (Fiji is just Image J but contain more plugins)
Then download H_watershed plugin and install it
You can download my macro (zip) and unzip it (1,2 Ko)
then open fiji and drag and drop the macro and clic Run
the macro will ask you where are your files in .tif (input) and where you want to save the mask and .Csv
Please don’t forget to remove the space in the name of your folders and subfolders and files name (don’t use Louis D but use Louis_D or 60 01 19 but use 60_01_19).
And don’t use the same location for the input and output or don’t create a subfolder in the input.

////// This macro was written in january 2020 by Alexandre Hego for Louis D
////// This macro will segment the bacteria in RED and count automatically the total area
////// This macro will run in batch mode and need H_watershed pluggin to run
////// If you need more informations please contact
////// Please remove the space in the folder name and file name

#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix
#@ Integer (label = "Seed Dynamic", value = "10") hMin
#@ Integer (label = "Intensity threshold", value = "118") thresh
#@ Integer (label = "Peak Flooding", value = "100") peakFlooding

// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
	list = getFileList(input);
	list = Array.sort(list);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + File.separator + list[i]))
			processFolder(input + File.separator + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output,  list[i]);
function processFile(input, output,  file) {
run("Bio-Formats Importer", "open=[" + input  + File.separator + list[i] + "] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
run("Split Channels");
selectImage("C2-" + imagesName);
selectImage("C3-" + imagesName);
selectImage("C1-" + imagesName);
run("Bandpass Filter...", "filter_large=40 filter_small=3 suppress=None tolerance=5 autoscale saturate");
run("Gaussian Blur...", "sigma=10");
run("H_Watershed", "impin=["+getTitle()+"] hmin="+hMin+" thresh="+thresh+" peakflooding="+peakFlooding + " outputmask=true allowsplitting=false");
run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Li dark");
run("Set Measurements...", "area redirect=None decimal=3");
run("Analyze Particles...", "size=0-80000 show=Masks display clear summarize add");
saveAs("Measurements", output + File.separator + imagesName +"_area.csv");
selectImage("Mask of H_watershed");
run("Invert LUT");
saveAs("Tiff", output + File.separator + imagesName);
selectWindow("ROI Manager");


print("the macro ends");
1 Like