MorphoLib + attribute filtering + macro

I want to run the Gray Scale Attribute Filtering 3D option from the plugin MorphoLib within a for loop for growing minimum volume. See below.

for (i=6; i<100; i++) {
       run ("Gray Scale Attribute Filtering 3D", operation=Opening attribute=Volume min ="i" connectivity=26");

There is an error saying that ‘)’ is missing.

I tried to call another variable “a=i” and I put “a” as the volume min but it brought the same error.
It worked if the volume min was a number, e.g. 5.

I got noticed that “volume min” accepts a variable or a number.

I don’t know java at all, I’m getting used to for ImageJ.

So, what am I supposed to write to make it work with a variable for the volume min option ?

Thank you,

PhD student in hydropedology
ULg, Gx-ABT, Belgium

The syntax highlighting in Fiji’s Script Editor helps to solve issues like yours.

You’ll see that you have an uneven number of double-quotes (") leading to your last closing parenthesis not being recognized (it’s inside a quoted string that never ends).
The macro function run should be call with two String parameters, the command name and the options argument:

run("Command", "option1=value1 option2=value2");

In order to insert variables into the option string, you have to use String concatenation. Try something like this:

run ("Gray Scale Attribute Filtering 3D", "operation=Opening attribute=Volume min=" + i + " connectivity=26");

Have a look at the documentation how to use the run command for further information.


It works. I thougt well that it was a syntax error…
Thanks you for your quick answer!

1 Like