kali281
kali281

Reputation: 115

Fiji error: "No images file selected" when using a macro that calls the plugin 'Average Images'

I would like to create a macro with Fiji, that then I would run by using matlab.

I would like to average 3 images by using the Plugins>Stacks>Average Images.

I used first Plugins>Macro>Record... to get an idea what to use. Here is the result:

run("Average Images", "add=D:\\Corinne\\diabetes_paper_meas\\2013_01_29\\Measurement.007_cb\\Measurement._cb_frame0_pvar-8bit_combined.tif add=D:\\Corinne\\diabetes_paper_meas\\2013_01_29\\Measurement.007_cb\\Measurement._cb_frame1_pvar-8bit_combined.tif add=D:\\Corinne\\diabetes_paper_meas\\2013_01_29\\Measurement.007_cb\\Measurement._cb_frame2_pvar-8bit_combined.tif");
saveAs("Tiff", "D:\\Corinne\\diabetes_paper_meas\\2013_01_29\\Measurement.007_cb\\test.tif");

However, even when I run this macro I got an error: No images file selected. However, in Fiji you do not need to open any images to run the plugin but you add the files through a window interface... So of course, since just running the macro is not working I get the same error when I use the following macro:

file = getArgument;
if (file=="") exit ("No argument!");
setBatchMode(true);
file_vasc = file;

file_vasc_frame_0 = file;
file_vasc_frame_1 = replace(file, "\\_frame0_pvar-8bit_combined.tif", "_frame1_pvar-8bit_combined.tif");
file_vasc_frame_2 = replace(file, "\\_frame0_pvar-8bit_combined.tif", "_frame2_pvar-8bit_combined.tif");


run("Average Images", "add=file_vasc_frame_0 add=file_vasc_frame_1 add=file_vasc_frame_2");
file_vasc_out = replace(file, "frame0_pvar-8bit_combined.tif", "_vasc_averaged.tif");
saveAs("Tiff", file_vasc_out);

Somebody has an idea what should I do?

Thanks

Upvotes: 0

Views: 497

Answers (1)

Jan Eglinger
Jan Eglinger

Reputation: 4090

The Average Images plugin is using dialogs in a non-standard way and therefore is not scriptable: when running the plugin in Fiji with the macro recorder active (Plugins>Macros>Record... and then Plugins>Stacks>Average Images), you will see Fiji complain as soon as you add a second file to the list:

Duplicate keyword:

Command: "Average images"

Keyword: "add"

Value: /path/to/your/file

Add an underscore to the corresponding label in the dialog to make the first word unique.

This clearly is a bug in the plugin (it makes multiple use of the same OpenDialog thereby recording duplicate keywords in the macro recorder). You can report it via Help>Report a bug, however I fear that this plugin is not actively maintained at the moment.

In any case, there is a simple alternate way to average images in ImageJ without requiring this plugin, using the Image>Stacks>Images to Stack and Image>Stacks>Z Project... commands:

setBatchMode(true);
open("/path/to/first-image.tif");
open("/path/to/second-image.tif");
run("Images to Stack", "name=stack title=[]");
run("Z Project...");
saveAs("Tiff", "/path/to/new-file-name.tif");

Upvotes: 1

Related Questions