Closed Sethur closed 1 year ago
I am not able to reproduce this problem. Could you please share a runnable macro that reproduces the problem. Something like the following macro, which works as expected.
setBatchMode(true);
newImage("First", "8-bit noise", 500, 500, 1);
newImage("Second", "8-bit noise", 500, 500, 1);
for (i = 1; i <= nImages; i++) {
selectImage(i);
IJ.log( getTitle() );
}
@rasband I found that the error only happens when you do some operation to the image inside the loop. For me, it happened when trying to reslice all images. A minimum runnable example to reproduce this error is:
newImage("First", "8-bit noise", 500, 500, 10);
newImage("Second", "8-bit noise", 500, 500, 10);
newImage("Third", "8-bit noise", 500, 500, 10);
setBatchMode(true);
orgImgNo = nImages
for (i = 1; i <= orgImgNo; i++) {
selectImage(i);
title = getTitle();
IJ.log("Title of image " + i + ": " + title);
run("Reslice [/]...", "start=Top avoid");
}
setBatchMode("exit and display");
This works as indented if the first line is commented out, but if setBatchMode(true)
is active, both getTitle()
and the reslice operation work on the first image, instead of the i-th image.
Edit: Fixed the formatting of the code and included newImage for convenience.
Edit 2: Moved the newImage commands before the setBatchMode(true)
line. If the newImage commands are after setBatchMode(true)
, the error is not happening and everything works fine.
This bug is fixed in the ImageJ 1.54c2 daily build.
When opening two or more images in a macro loop and doing any operation on them, such as
getTitle()
, orrun("Reslice...")
, only the first image is selected byselectImage(i)
when batch mode is entered before the loop.Here is a short macro the reproduce the problem.
Edit: Updated code and description to provide an closed, working example, that does not need any already opened images. As stated in the comments, it is important for reproduction that the images are already open when the batch mode is entered.