Auto-thresholding, macro functions, and incorrect mode

I’m trying to write a macro that will perform an auto-threshold. So far, it seems to mostly work. Below is the single line of code I think should work:

setAutoThreshold("Default dark B&W");

The thresholding is applied - however, the image appears to be in “Red” mode, not “Black and White” as I declared. The reason I say this is because all the under-threshold pixels are red, not white.

However, when I run the command call("ij.plugin.frame.ThresholdAdjuster.getMode"); the log records “B&W”

When I manually open the Threshold dialog (Image>Adjust>Threshold) and select “Default” “B&W” from the drop downs, along with checking the “Dark background option” the image is thresholded and the colors are black and white. When I again run the command call("ij.plugin.frame.ThresholdAdjuster.getMode"); the log records “B&W”

Is this potentially a bug in the software? Or, am I missing a command in my macro script? Any help would be greatly appreciated.

I tried recording an auto threshold operation, and the recorder produces:

setAutoThreshold("Default dark");

Regardless of the mode selected.

So, I don’t think you can pass the mode as a parameter to that function.

It also doesn’t look like you can set it programatically; ThresholdAdjuster does not have a public static void setMode(String mode) method.

As an aside: I think the proper way (from the docs) to ask for the current threshold mode is:


But there does not appear to be a way to programmatically set the thresholding mode. Perhaps @Wayne will add one in the future.

1 Like

The latest ImageJ daily build (1.50g3) adds the call(“ij.plugin.frame.ThresholdAdjuster.setMode”,mode) macro function and the ThresholdAdjuster.setMode(mode) method, where ‘mode’ is “Red”, “B&W” or “Over/Under”. Both are recordable.

1 Like