Setting threshold and batch processing in ImageJ (FIJI)

I’m trying to apply a same Thresholding to multiple images using the “BATCH> Macro” Function, but the results were not satisfactory…

My approach has been to try and automate all the steps/ do batch processing but I have been having a hard time adapting what I have written to work based on instructions found online. Instead I’ve been just opening every image in the directory one by one and applying the macro that I wrote, then saving the results manually. Obviously this is a tedious approach so any help would be much appreciated!

Can you post your macro and a couple of images that caused your concern so we have a better idea how to assist you. Reproducible examples make it easier on everyone…

makeRectangle(0, 0, 1024, 661);
run(“Crop”);
setAutoThreshold(“Default”);
//run(“Threshold…”);
//setThreshold(0, 52);
setOption(“BlackBackground”, false);
run(“Convert to Mask”);
run(“Close”);

When I apply this MACRO in the PROCESS>BATCH>MACRO , my results do not repeat.

001_003_5_11.tif (795.1 KB) 001_003_5_11 - Quantificação Ariane WEKA.tif (660.1 KB)

This picture show what I expected.

The problem is that the macro recorder can be misleading at times. Let me illustrate. I made a small change to your macro to use script parameters to specify the directory. I am entering the script between two sets of three backtics to keep the upload from changing characters (your paste added unicode characters I needed to strip out). Here is what I used:

@String(label="Image Directory", style="") img_dir
path = img_dir + "/001_003_5_11.tif";

open(path);
makeRectangle(0, 0, 1024, 661);
run("Crop");
setAutoThreshold("Default");
//run("Threshold...");
//setThreshold(0, 52);
setOption("BlackBackground", false);
run("Convert to Mask");
// run("Close");

I commented out the last run("Close") to keep the processed image open. This is what I got:

I’m sure this is not what you wanted. The macro recorder had commented out the threshold you wanted

//run(“Threshold…”);
//setThreshold(0, 52);

and just run the default AutoThreshold. When I un-comment those lines and run again,
this uses what the default autothreshold actually measured on this image. Then I got the following image:

Which is what I suspect you really wanted. I played around with some of the other options.
Try this on your series:

@String(label="Image Directory", style="") img_dir
path = img_dir + "/001_003_5_11.tif";
run("Close All");
open(path);
makeRectangle(0, 0, 1024, 661);
run("Crop");
setAutoThreshold("Intermodes");
getThreshold(lower, upper);
run("Convert to Mask");

Hope this helps.

Best regards,
John Minter