Including filename in output after batch processing macro

imagej
batch-processing
macro

#1

Hi, I’m new to ImaegJ. Just created my first macro see below, and ran it on a number of images in a directory. It seemed to work fine except in the output summary, the results were listed without the file name. How can I have the filename listed in the results (not just the word “mask”), and can this then be send to an excell file?
Most grateful for your help
Matt

Here is my macro. I used the Process>batch from the options menu to run it

run("Gaussian Blur...", "sigma=3");
run("Kuwahara Filter", "sampling=5");
run("Color Threshold...");
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=157;
max[0]=184;
filter[0]="pass";
min[1]=0;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=179;
filter[2]="pass";
for (i=0;i<3;i++){
  selectWindow(""+i);
  setThreshold(min[i], max[i]);
  run("Convert to Mask");
  if (filter[i]=="stop")  run("Invert");
}
run("Create Mask");
run("Fill Holes");
run("Watershed");
run("Analyze Particles...", "size=40-Infinity display clear summarize add");

This is a screenshot of the output


#2

Hi @matthewrpugh

You can add the following code to the top of your macro (so just after the image is opened…):

title = getTitle(); // this saves your image title in the variable called 'title'

And then after you call run("Create Mask");… add this line:

rename(title + "_mask"); // this renames your mask image by concatenating the string held in the variable, 'title', and the string "_mask"

Then if you go to Set Measurements and check the Display Label - you should also see the title of the image. This a round-about way of doing this… but should work?? I haven’t tested anything… so just try it out and see.

Too - I got all those function calls from the Built-In Macro Function page. :slight_smile:

eta