Code line to change treshold colour in macro

Hello everyone,

I come here asking for your help about what I think would be a simple task for a lot of you,

I would like to add a line in my macro that would change the default color of treshold from “Red” to “B&W”, exactly that action on the picture:

treshold bw

When I make it myself trough the “record” function, that line appears:

call(“ij.plugin.frame.ThresholdAdjuster.setMode”, “B&W”);

But unfortunately, when launched as a macro, that code line does not do anything on the treshold settings.

Would you know another function or another way to set the treshold color through a code line ?

Thank you in advance,


Hi @Theoporosite,

call(“ij.plugin.frame.ThresholdAdjuster.setMode”, “B&W”);

changes the color mode of the active ThresholdAdjuster instance. It does not change the default value. If you call it when the ThresholdAdjuster is open it works.

The default value is in IJ_Prefs.txt. Use

dir = call('ij.Prefs.getPrefsDir');

to find the file in your system.

You can set it from a macro with

call("ij.Prefs.set", "threshold.mode", "B&W");

This is not permanent, i.e. not saved to the Prefs-file. You can save it to the file from a macro with:


Hi Volker,

Oh okay that explains why it would not change !

Allright I got it, and it works, thank you really much !!

Have a nice day !