run("Make Montage...") from first and last image of a stack

fiji
imagej
macro

#1

Hi guys,

As in the title, I would like to do a Montage with the first and last image of a stack (900 images in this case). When I tried the recorder I got this:

run("Make Montage...", "columns=2 rows=1 scale=1 increment=899 border=5 label use");

and it works, but I would like to set the increment as:

a=nSlices();
increment=a-1

to do not worry about the specific number of the images.

How do I set a variable in the increment? I couldn’t find a way anywhere…

Many thanks for your help!

Mike


#2

Hi @MIKEIII, and welcome back on the forum!

The part:

"columns=2 rows=1 scale=1 increment=899 border=5 label use"

… is an option string of the run() command. You can concatenate (+) strings and variables to build a dynamic option string:

"columns=2 rows=1 scale=1 increment=" + a + " border=5 label use"

In the specific case of the run() macro function, there’s another valid syntax for including variables in the options, using & followed by the variable name:

run("Make Montage...", "columns=2 rows=1 scale=1 increment=&a border=5 label use")

This is explained in more detail in the macro language documentation.


Note that string concatenation (option 1) is more general – it works everywhere in the macro language, and also in most other scripting languages – while the &variable method (option 2) only works in option strings.


#3

Many thanks guys for your help!