Label in batch processing

Hi everyone, I’m new to Image J and would greatly appreciate any help. I’m using a macro for image analysis to calculate fraction area stained. When I run the batch process, in the resulted Excel file the result is numbered as 1, 2, 3 and so on but without a label. I just need to add the original tiff image name with each calculated area fraction (simply to know this area belongs to which image). Many thanks.
This is the macro I’m using

dir1 = getDirectory("Choose source directory"); 
list = getFileList(dir1); 
dir2 = getDirectory("Choose destination directory"); 
setBatchMode(true);
for (i=0; i<list.length; i++) { 
 	file = dir1+list[i]; 
	open(file); 
	title1= getTitle; 
	title2 = File.nameWithoutExtension; 
	run("Subtract Background...", "rolling=50 light");
	run("8-bit");
	setThreshold(0, 180); 
	run("Convert to Mask"); 
	run("Set Measurements...", "area min max mean area_fraction redirect=None decimal=2"); 
	run("Measure");
	saveAs("tiff", dir2+"Threshold of "+title2+".tiff"); 
	}
	selectWindow("Results");
	run("Summarize");
	saveAs("txt", dir2+"DAB.xls");
	run("Close")
	run("Close All");

Hi @Dr.Zahraa_Jawad,

The line: run(“Set Measurements…”, “area min max mean area_fraction redirect=None decimal=2”); is the culrpit. If you want the image label, you need to activate it using Analyze > Set Measurements…
But that line above deactivates the label. Replace it with

run(“Set Measurements…”, “area min max mean area_fraction display redirect=None decimal=2”);

Adding display is like activating the “Display Label” checkbox from the Set Measurements… menu

2 Likes

Hi @oburri,
It works like magic! thank you very much :grinning: you saved me, I spent two days searching the internet without helpful answer (I already activated Display Label but it didn’t help).
I wanna add a step (color deconvolution) to this macro to make it work for another slides, can you help with this? Should I add it as a new topic? All the best.

Hi,
I have a similar problem as described above but enabling the “Display label” checkbox in the Set Measurements function does not solve the problem. Here is my problem: I do batch analysis of several images to count cell nuclei and the macro works fine. However, in the summary table the images are labeled “threshold” instead of the original file name. Despite activating “Display label” I also tried adding “rename (title)” and “setMetadata (label, string)” to the macro but nothing has solved the problem.
Here is the macro:

run("Split Channels");
run("Grays");
run("Enhance Local Contrast (CLAHE)", "blocksize=127 histogram=256 maximum=2 mask=*None* fast_(less_accurate)");
run("Nucleus Counter", "smallest=50 largest=5000 threshold=Otsu smooth=[Mean 5x5] watershed add show");
roiManager("Show All with labels");
roiManager("Show All");
selectWindow("Summary");
saveAs("Results", "U:/My Documents/Seneszenz Assay/20190204_Seneszenz mit Rohinis Donoren in 24 Wells/Versuch 1/SA-b-Gal Staining/Tif/DAPI/DAPI results/Summary.tsv"); 

I am very grateful for help!