Posted by
Michael Schmid on
Oct 06, 2017; 10:04am
URL: http://imagej.273.s1.nabble.com/an-odd-image-ID-problem-tp5019502p5019509.html
Hi Giovanni, Jeremy,
hummmm, I can't reproduce the problem here. I have ImageJ 1.51r15; Java
1.8.0_112 [64-bit]; Linux 4.4.0-96-generic (Ubuntu 16.04).
Macro results are below. To me, they look fine.
- Which ImageJ version and operating systems do you use?
- Did you experience an unusual delay running the macro (did it take
more than 1.5 seconds for the 'Stack to Images'?)
I guess that there is a race condition. In Java, images are operated
asynchronously; in my experience, the 'windowActivated' of a
windowListener can come before the layout of the window is done and the
window actually appears on the screen. The ImagePlus.show() method
includes code that should work around such problems, but maybe it is not
always effective.
--
Nevertheless, I have also experienced rare cases where the image shown
as foreground image on the screen was not the same one as that
considered foreground image by ImageJ This has happened during
interactive work (no macros) and was not reproducible. I have the
impression that it might be related to closing a window. (It was not
with the current ImageJ version - as I said, it's very rare, and I'm not
sure whether it also happens under Linux - I use many platforms).
Michael
________________________________________________________________
The original macro reports:
origStackID -26
stack-images
after stack-images: current Title: OriginalStack-0003 ID -29
IDs orig -26 after stack-images -29 -28 -27
repeat but include image duplication
NeworigStackID -30
ID of duplicate -31
stack-images
after stack-images: current Title: NewOriginalStack-1-0003
currentID -34
IDs orig -26 after stack-images -34 -33 -32
________________________________________________________________
The revised macro reports:
origStackID -36
- converting stack to images
active image after first stack-to-images: Title: OriginalStack-0003
ID: -39
NeworigStackID -40
- converting new stack to images
active image after second stack-to-images: Title: NewOriginalStack-0004
currentID -44
________________________________________________________________
On 06/10/2017 10:00, Cardone, Giovanni wrote:
> Hi Jeremy,
>
> I could reproduce the issue, and I pinpointed the problem to the "Stack to Images" command.
> I simplified your example, to show that after the second call to "stack to Images" the active Image is the last one generated by the first call, which to me is an unwanted behavior.
> Hopefully this will help to find the problem in the code.
>
> Best,
> Giovanni
>
>
> run("Close All");
> print("\\Clear");
>
> newImage("OriginalStack", "32-bit ramp", 64, 32, 3);
> origStackID=getImageID();
> print("origStackID ",origStackID);
> print(" - conveting stack to images");
> run("Stack to Images");
> afterStacktoIm3ID=getImageID();// current image
> currentTitle=getTitle();
> print("active image after first stack-to-images: Title: ",currentTitle," ID: ",afterStacktoIm3ID);
>
> print(" ");
> newImage("NewOriginalStack", "32-bit ramp", 64, 32, 4);
> NeworigStackID=getImageID();
> print("NeworigStackID ",NeworigStackID);
> print(" - conveting new stack to images");
> run("Stack to Images");
> afterSecondStacktoIm3ID=getImageID();// current image
> currentTitle=getTitle();
> print("active image after second stack-to-images: Title: ",currentTitle," currentID ",afterSecondStacktoIm3ID);
>
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of Jeremy Adler
> Sent: Donnerstag, 5. Oktober 2017 10:06
> To:
[hidden email]
> Subject: an odd image ID problem
>
>
> A small problem with the IDs of images or maybe my assumption that the last created image is the current image.
>
> The macro code creates a stack of 3 images then splits the stack.
> The IDs of the 3 daughter images are obtained by finding the ID of the top image (3rd and last image in the stack).
> This is as it should be.
>
> But (second block of code) when I duplicate the stack before splitting the stack, the duplicate stack gets the expected ID.
> But after splitting the stack the IDs of the daughter images are reported incorrectly.
> The problem seems to be that although the final 3rd image in the stack is still the top image, when I check the current ID and title are those of the original stack.
>
> What am I missing ?
>
> run("Close All");
> print("\\Clear");
>
> newImage("OriginalStack", "32-bit ramp", 64, 32, 3); origStackID=getImageID();print("origStackID ",origStackID); run("Stack to Images");
> print(" stack-images");
> afterStacktoIm3ID=getImageID();// current image currentTitle=getTitle();print("after stack-images: current Title: ",currentTitle," ID ",afterStacktoIm3ID); after2ID=afterStacktoIm3ID+1;// 2nd image from stack after1ID=afterStacktoIm3ID+2;// 2nd image from stack/ print("IDs orig ",origStackID," after stack-images ",afterStacktoIm3ID,after2ID,after1ID);
> selectImage(after2ID);
>
> print(" ");
> print(" repeat but include image duplication");
> newImage("NewOriginalStack", "32-bit ramp", 64, 32, 3); NeworigStackID=getImageID();print("NeworigStackID ",NeworigStackID); run("Duplicate...", "duplicate"); DupImageID=getImageID(); print("ID of duplicate ",DupImageID); run("Stack to Images");
> print(" stack-images");
> afterStacktoIm3ID=getImageID();// current image currentTitle=getTitle();print("after stack-images: current Title: ",currentTitle," currentID ",afterStacktoIm3ID); after2ID=afterStacktoIm3ID+1;// 2nd image from stack after1ID=afterStacktoIm3ID+2;// 2nd image from stack/ print("IDs orig ",origStackID," after stack-images ",afterStacktoIm3ID,after2ID,after1ID);
> selectImage(after2ID);
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html