Using variables in number-only-commands

Hey all,

I am currently using a macro for watershedding.
The line for calling the plugin in a macro reads as follows (given by the authors):

run("Watershed Segmentation", "blurring='1.0'  watershed='1 1 0 190 1 0'   display='0' ");

I want a dialogue at the beginning in which the user can predefine his settings. This dialogue is all set an done and all inputs are assigned to a variable.

However, when I modify the line:

run("Watershed Segmentation", "blurring=vblurring  watershed='1 1 minimumWS maximumWS 1 0'   display='0' ");

ImageJ gives an error message saying “java.lang.NumberFormatException: For input string: “vblurring””

I am confused because this works for other plugins. I used the following line in the past:

run("Analyze Particles...", "size=pixelmin-pixelmax circularity=lowercirc-uppercirc clear summarize add");

Is there any easy way to achieve what I described?
Or do I need to go into the individual .class files?

Thank you for your help!

As a “best practices” suggestion, I would take a look at this section of the macro introduction, and maybe change your line to something like

run("Watershed Segmentation", "blurring=" + vblurring + " watershed='1 1 " + minimumWS+ " " + maximumWS + " 1 0'   display='0' ");

Hopefully I got the quotes correct. I haven’t actually tried to run that. However, you should get the idea. It isn’t consistent with your previous experience running the Analyze Particles command, but I think there will be less trouble, even though the typing effort is a bit more. Also be sure to get your spaces inserted carfully when doing this.

As for the error message, I’m not the Java expert, but maybe you’re sending the wrong Java variable type to your macro. Perhaps your dialog is creating vblurring as a string? It could be you need to replace a Dialog.addString() with a Dialog.addNumber().

If you still have problems, reply with a larger code block and maybe we can help without making guesses.

2 Likes

Hey Jim,

you solved the problem!

Thank you very much. You are the hero of the entire week!

I simply copy/pasted your line and it worked :slight_smile:

Topic closed!