Posted by
Wayne Rasband on
Dec 05, 2009; 2:04am
URL: http://imagej.273.s1.nabble.com/Multiple-Image-sequence-open-commands-in-a-macro-tp3689974p3689975.html
> I would like to improve a macro by which I open several image
> sequences from one directory.
>
> This macro contains multiple command lines like:
>
> run("Image Sequence...", "+((open)+ number=stack_size starting=1
> increment=1 scale=100 file=r00 sort use)");
> run("Image Sequence...", "+((open)+ number=stack_size starting=1
> increment=1 scale=100 file=r01 sort use)");
> run("Image Sequence...", "+((open)+ number=stack_size starting=1
> increment=1 scale=100 file=r02 sort use)");
>
> when I run the macro with, e.g. eight run("Image Sequence...",
> lines, the File.open dialog is opened eight times.
>
> Since, ***any** image file in the directory can be chosen
> (double-clicked) during each dialog (the macro handles the file
> selection), it should be sufficient to choose a file only once (i.e.
> by
> the firs dialog only, or by a previous dialog) .
>
> Such a file name can be queried from the user by:
> path = File.openDialog("Select a File");
> I tried to pass this "path" to the run("Image Sequence...", )
> lines but this did not work yet.
>
> How can I pass the path and filename to all the run("Image
> Sequence...",)
> instances to have all the other file sequences opened automatically?
Use code something like this:
path = "/Users/wayne/Downloads/stack/";
run("Image Sequence...", "open=&path file=r00 sort use");
run("Image Sequence...", "open=&path file=r01 sort use");
run("Image Sequence...", "open=&path file=r02 sort use");
The "number=stack_size", "starting=1", "increment=1" and "scale=100"
options can be omitted (the default values are used).
The "&path" notation for passing variables like 'path' requires ImageJ
1.43 or later. With earlier versions you have to use string
concatenation:
run("Image Sequence...", "open=["+path+"] file=r00 sort use");
run("Image Sequence...", "open=["+path+"] file=r01 sort use");
run("Image Sequence...", "open=["+path+"] file=r02 sort use");
The brackets ("[" and "]") are required if the path can contain spaces.
-wayne