Java command for Color ThreshHold

Hello everyone,
a quick question on the java command to use Image>Adjust>Color Threshold.
Can you explain me or redirect me on some document that explain how the option section of the java command work?
The command is:“Color Threshold…”, “”);
Is there any documents that explain what I have to put in the second arguments?
Thanks in advance

Hello ddewx -

I do not believe that the “Color Threshold…” command makes
use of the options String that is passed as the second argument
to the method.

I don’t know of any explicit documentation for this.

The Method Summary for the documentation for IJ

“Runs an ImageJ command, with options that are passed to the
GenericDialog and OpenDialog classes.”

Looking at the source for, I see no use
of GenericDialog (and no call to Macro.getOptions()),
leading me to conclude that the options String is ignored.

The following is interesting:

Open an image. Then open the macro Recorder,
Plugins > Macro > Record.... Then run
Image > Adjust > Color Threshold..., and click the
“Macro” button at the bottom of the “Threshold Color” dialog.

You will see that doing so populates the macro Recorder not
with a call to “Color Threshold…” (with options passed to it),
but with a bunch of code that varies with what options you
have selected in the “Threshold Color” dialog.

This suggests to me that ColorThresholder was designed
to be inherently interactive, and is probably not easy to fully
automate from code (java or otherwise). (You could use the
code written into the macro Recorder to guide you in writing
your own code that reproduces what “Color Threshold…”

Thanks, mm

There are several options in Java.

If you use the Color Thresholder and apply the ‘Macro’ action you get all the threshold macro code in the macro Recorder.

You can now convert this code to Java (it’s not very hard to do so) or you call the generated macro code (or an external file) directly from Java.

Here a simple plugin example (made with Eclipse where you can simply paste the quoted code into a string):

import ij.IJ;
import ij.plugin.PlugIn;
public class My_Plugin implements PlugIn {

	public void run(String arg) {
		IJ.runMacro("run(\"Leaf (36K)\");\n" + 
				"run(\"Color Threshold...\");\n" + 
				"// Color Thresholder 1.52q\n" + 
				"// Autogenerated macro, single images only!\n" + 
				"min=newArray(3);\n" + 
				"max=newArray(3);\n" + 
				"filter=newArray(3);\n" + 
				"a=getTitle();\n" + 
				"run(\"HSB Stack\");\n" + 
				"run(\"Convert Stack to Images\");\n" + 
				"selectWindow(\"Hue\");\n" + 
				"rename(\"0\");\n" + 
				"selectWindow(\"Saturation\");\n" + 
				"rename(\"1\");\n" + 
				"selectWindow(\"Brightness\");\n" + 
				"rename(\"2\");\n" + 
				"min[0]=0;\n" + 
				"max[0]=255;\n" + 
				"filter[0]=\"pass\";\n" + 
				"min[1]=0;\n" + 
				"max[1]=255;\n" + 
				"filter[1]=\"pass\";\n" + 
				"min[2]=0;\n" + 
				"max[2]=186;\n" + 
				"filter[2]=\"pass\";\n" + 
				"for (i=0;i<3;i++){\n" + 
				"  selectWindow(\"\"+i);\n" + 
				"  setThreshold(min[i], max[i]);\n" + 
				"  run(\"Convert to Mask\");\n" + 
				"  if (filter[i]==\"stop\")  run(\"Invert\");\n" + 
				"}\n" + 
				"imageCalculator(\"AND create\", \"0\",\"1\");\n" + 
				"imageCalculator(\"AND create\", \"Result of 0\",\"2\");\n" + 
				"for (i=0;i<3;i++){\n" + 
				"  selectWindow(\"\"+i);\n" + 
				"  close();\n" + 
				"}\n" + 
				"selectWindow(\"Result of 0\");\n" + 
				"close();\n" + 
				"selectWindow(\"Result of Result of 0\");\n" + 

Of course an externalized maco file (call with IJ.runMacroFile(yourMacroFile)) would avoid a quoting hell.

By the way the next release of Java make this much easier and comfortable with Raw String Literals: