NOTICE! This is a static HTML version of a legacy Fiji BugZilla bug.

The Fiji project now uses GitHub Issues for issue tracking.

Please file all new issues there.

Bug 528 - SaveAs and LOCI Exporter do not function correctly on consecutive Macro calls
SaveAs and LOCI Exporter do not function correctly on consecutive Macro calls
Status: RESOLVED FIXED
Product: Fiji
Classification: Unclassified
Component: Other
unspecified
PC Windows
: P5 enhancement
Assigned To: ImageJ Bugs Mailing List
Depends on:
Blocks:
 
Reported: 2012-11-09 13:58 CST by vito smolej
Modified: 2013-07-07 10:09 CDT
4 users (show)

See Also:


Attachments
see redma.1st in the zip file (3.28 KB, application/zip)
2012-11-09 13:58 CST, vito smolej

Description vito smolej 2012-11-09 13:58:27 CST
Created attachment 81
see redma.1st in the zip file

To make it simple, here's is a batch windows file, 
set IJ=ImageJ
%IJ% -macro macro1.ijm
pause
%IJ% -macro macro2.ijm
pause
%IJ% -macro macro3.ijm
pause

consisting of consecutive calls of three macros. which are identical...

    if (getMetadata("Info") == "")
        saveAs("Tiff", "image1.tif");
    else
        {
        args = "save=[image1.ome.tif] compression=Uncompressed";
         run("Bio-Formats Exporter", args);
        }

... save for file names (image1 in macro1, image2 in macro2 and image3 in macro3). After running this sequence one would expect to end up with three images saved. This is not so: the second and third macro do not save automatically as requested.Instead of that they open a SaveAs dialog (resp LOCI Exporter dialog) with a suggestion for the file name provided in the previous macro (see log file for details). Note pause statements - it is not due to command getting executed to fast. 

Versions: ImageJ 1.46r and Fiji current snapshot

Corrolary question: any suggestion for a more robust test of whether the image is 2D or multidimensional - i.e. to bes tored via LOCI? TiA
Comment 1 Curtis Rueden 2012-11-09 18:49:45 CST
I can reproduce this problem with Fiji on OS X as well.

I posted some files demonstrating the issue at:
    https://gist.github.com/4047102

Steps to reproduce:
1) Change paths in the script & macros to your liking.
2) Launch Fiji.
3) Open Blobs.
4) Run go.sh from the console.
Comment 2 Melissa Linkert 2012-11-13 02:23:56 CST
I don't fully understand why, but adding '/bin/sleep 60' immediately after the 'read' command in go.sh solves the problem (at least for me, on Linux, with a fully up-to-date Fiji).

So maybe this really is a timing issue?  In any case, it appears to be something deep in ImageJ, and not something to be fixed in the Bio-Formats plugins.
Comment 3 vito smolej 2012-11-13 09:56:10 CST
Hi Melissa, Curtis:

Re "not something to be fixed in the Bio-Formats plugins." I can confirm that: the same behavior is seen for plain 2d images, where SaveAs and not the bioformats exporter is used. Looks like the cause is somewhere below both the generic SaveAs command and Bio-Formats exporter.

I thought the possible cause could be that the one and the same active image is addressed on consecutive calls. So I loaded three images in the "mother" instance and changed macros to close the current active image after it has been saved. Again the first call went by OK and the following two came up with the Save As dialog, with identical arguments as before.

I also interspersed consecutive SaveAs*.ijm macro calls with <IJ> -macro - i.e. with a do nothing requests. No change in behavior. 

Looks like a "first-time-only" kind of a problem to me. I'll try the suggestion by Melissa next;

out = "/Users/curtis/Desktop/image1.tif";
sleep 60;
saveAs("Tiff", out);

Will keep you posted.Thanks everybody for helping out.

Vito
Comment 4 vito smolej 2012-11-13 11:00:42 CST
I changed the macros as follows

  // save the image either as tif (simple 2D) or as
    // a ome.tif image - to be imported later on
	argsA = "image1.tif";
	argsB = "image1.ome.tif";
	wait(100);
    if (getMetadata("Info") == "")
        saveAs("Tiff", argsA);
    else
        {
        args = "save=["+argsB+"] compression=Uncompressed";
         run("Bio-Formats Exporter", args);
        }
   
it worked on the first or second execution of the batch file and then it reverted to the described behavior for the rest - could be  just luck/stochastics.

This applies to BioFormats branch as well - there 100 ms were not enough as it took the first macro a minute or so to store a 55MB zstack - in this case the second request for the macro execution was not even detected by Fiji(!). 

Switching to ImageJ 1.47e and changing wait to a messageBox: save OK in macro1, in macro2 I got back the SaveAs dialog.

Summarizing, it does not look that sleeps make any difference. At least not the desired difference.

Regards

Vito
Comment 5 vito smolej 2012-11-16 09:50:17 CST
we have replaced the macro with java injection as suggested here

http://stackoverflow.com/questions/12699463/have-imagej-automatically-overwrite-when-using-saveas

The problems for us are thus gone, which could be an additional hint at the cause of the problem reported. 

Im putting the status to WORKFORME. Reopen it and/reassign it as deemed useful.

Thanks everybody for comments.

Regards

Vito
Comment 6 Wayne Rasband 2012-11-16 19:05:53 CST
This bug is fixed in the ImageJ 1.47f8 daily build.