Cell counting - macro missing file name - Batch processing order

Hi everybody! Again I struggle with a problem concerning cell counting with FIJI / IMAGEJ. Unfortunately I do not have big knowledge about working with Fiji, but need to do some analysis for my PhD.

I copied and adjusted following macro that is counting cells after splitting a RGB picture. The results (live cells, dead cells and viability) is presented in the results table.

Issue: When I run the counting macro in a batch process of many files, the results won’t appear in the order of the files on my pc. Is seems like there isn’t any logical running order (alphabetic, size, …) at all …

Some month ago a forum user showed me the solution for an other macro by adding a further column in the results table with file name. In order of that, I am able to copy my results into an excel sheet and arrange them in the proper order (alphabetically) right there. Is there a possibility to add that also to the macro above?

Thank you very much! Best, Sebastian

I also uploaded three example images I am working with.

//// this macro caluclates live and dead cells 
////and % of live cells from live/dead assay using single RGB image.

//clears previous results
run("Clear Results")
if (isOpen("Results")) { 
selectWindow("Results"); 
run("Close"); 
}

//set initial number of live and dead cells to 0
liveno=0;
deadno=0;

originalTitle = getTitle(); 
run("Split Channels");
selectWindow(originalTitle + " (blue)");
run("Close"); 

////red channel////
selectWindow(originalTitle + " (red)");  
run("8-bit");

//put your min and max values here to adjust brightness and contrast of the red channel
setMinAndMax(80, 180);
run("Apply LUT");
setAutoThreshold("Moments dark");
run("Convert to Mask");
run("Watershed");
selectWindow(originalTitle + " (red)"); 

//you can adjust size of the particles to detect in the red channel below 
run("Analyze Particles...", "size=280.0-Infinity circularity=0.00-1.00 show=Nothing include add in_situ");
deadno=roiManager("count");
if (deadno>0) {

roiManager("Show All with labels");
roiManager("Show All");
array1 = newArray("0");
for (i=1;i<roiManager("count");i++){
	array1 = Array.concat(array1,i);
}
roiManager("select", array1);
roiManager("Delete");
}
run("Out [-]");
run("Out [-]");


////green channel////
selectWindow(originalTitle + " (green)"); 
run("8-bit");

//put your min and max values here to adjust brightness and contrast of the green channel
setMinAndMax(80, 180);
setAutoThreshold("Moments dark");
run("Convert to Mask");
run("Watershed");
selectWindow(originalTitle + " (green)");

//you can adjust size of the particles to detect in the green channel below 
run("Analyze Particles...", "size=280.0-Infinity circularity=0.00-1.00 show=Nothing include add in_situ");
liveno=roiManager("count");
roiManager("Show All with labels");
roiManager("Show All");
array1 = newArray("0");
for (i=1;i<roiManager("count");i++){
	 array1 = Array.concat(array1,i);
	}
roiManager("select", array1);
roiManager("Delete");
run("Out [-]");
run("Out [-]");

//prints results
print("live: ", liveno , "; dead: ", deadno , "; total: ", liveno+deadno, "; %live: ", liveno/(liveno+deadno));

Do I understand correctly: all you want is to add the filename to the result?

As far as I understand your macro the results are printed to the log window by this:

print("live: ", liveno , "; dead: ", deadno , "; total: ", liveno+deadno, "; %live: ", liveno/(liveno+deadno));

I guess you then save the log window…
You have a variable there that contains the image window:

originalTitle = getTitle(); 

If the title of the window is good enough for you then you would just add that variable to the print statement:

print("filename: ", originalTitle , "; live: ", liveno , "; dead: ", deadno , "; total: ", liveno+deadno, "; %live: ", liveno/(liveno+deadno));

Would that work for you?
If you want a different filename you can just replace the variable originalTitle with a different variable.

Thank you very much for your fast answer!

Maybe my problem is a bit more complicated because of the way the results are presented by my macro (like you say, saving the log window?) ?

Now, with adding your code to my macro, the results are presented likes this:
But for my usage (arrange alphabetically with excel) I need the results in different columns, as in the second picture (wich seems to be the results table not the log window?)

Is there a possibility to transfer my counting results via setting thresholds from the log window to results table?

Excuse me for me confusing problem :see_no_evil:

Ok to solve this for one image is easy.
Assuming the green belongs with the counts for the liveno and the red belongs with the count of the deadno you would add this to the macro:

run("Set Measurements...", "  redirect=None decimal=3");
redTitle = originalTitle + " (red)";
greenTitle = originalTitle + " (green)";

//liveno belongs to greenTitle
setResult("Label", 0, greenTitle);
setResult("Count", 0, liveno);

//deadno belongs to greenTitle
setResult("Label", 1, redTitle);
setResult("Count", 1, deadno);

This answers your specific question.
If you want to do this for more images then you need to rewrite the macro a bit more.

1 Like

Hey @schmiedc that run’s perfectly, thank you! But as you remarked, only for one image … Can you give an advice how to change my macro, when I would like to run a batch process with several images?

Thank you very much! Best Sebastian

You can put the macro into the batch plugin or modify the batch macro:

To make this work you need to delete this part first:

//clears previous results
run("Clear Results")
if (isOpen("Results")) { 
selectWindow("Results"); 
run("Close"); 
}

otherwise a new results table will be created.