an odd image ID problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

an odd image ID problem

Jeremy Adler-2

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
Reply | Threaded
Open this post in threaded view
|

Re: an odd image ID problem

Herbie
Good day Jeremy,

I hope you are aware of the fact that you create a total of three stacks:
"OriginalStack"
"NewOriginalStack"
"NewOriginalStack-1"

Make sure, the latter two don't get confused...

BTW:
after1ID=afterStacktoIm3ID+2;// 2nd image from stack
should read
after1ID=afterStacktoIm3ID+2;// 1st image from stack

Furthermore, I don't think it is a good idea to compute with image IDs.

Regards

Herbie

::::::::::::::::::::::::::::::::::::::::::
Am 05.10.17 um 10:06 schrieb Jeremy Adler:

>
> 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
Reply | Threaded
Open this post in threaded view
|

Re: an odd image ID problem

Cardone, Giovanni
In reply to this post by Jeremy Adler-2
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
Reply | Threaded
Open this post in threaded view
|

Re: an odd image ID problem

Michael Schmid-3
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
Reply | Threaded
Open this post in threaded view
|

Slider: Change Insets

Herbie
Dear experts, especially Wayne!

A minor "cosmetic" problem concerning
Dialog.addSlider(label, min, max, default);

Obviously, the default insets can't be changed by
Dialog.setInsets(top, left, bottom);

Is there any reason for this?

Regards

Herbie

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: an odd image ID problem

Cardone, Giovanni
In reply to this post by Michael Schmid-3
Hi Michael,

my tests were on Windows, but I repeated them on a fresh install of ImageJ on Linux, and the issue remains.
Regarding delays, I don't observe any, the macro runs in less than 200 ms.
I also tested variants of the script and below is the simplest one, showing a consistent result: after 'stack to images' the active image is the last generate before the converted one. This would point to a race conditions like you suspected.

Best,
Giovanni

- script

run("Close All");
print("\\Clear");

newImage("dummy", "32-bit ramp", 64, 32, 3);
dummyID=getImageID();
currentTitle=getTitle();
print("First image: Title: ",currentTitle," ID: ",dummyID);
newImage("OriginalStack", "32-bit ramp", 64, 32, 3);
origStackID=getImageID();
print("origStackID ",origStackID);
print(" - converting stack to images");
run("Stack to Images");
afterStacktoIm3ID=getImageID();// current image
currentTitle=getTitle();
print("active image after stack-to-images: Title: ",currentTitle," ID: ",afterStacktoIm3ID);

- output from script

First image: Title:  dummy  ID:  -550
origStackID  -551
 - converting stack to images
active image after stack-to-images: Title:  dummy  ID:  -550



-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
Sent: Freitag, 6. Oktober 2017 12:04
To: [hidden email]
Subject: Re: an odd image ID problem

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: an odd image ID problem

Michael Schmid-3
Hi Giovanni,

now I could reproduce it with ImageJ under Java 1.6 on an old (and slow)
Mac (MacOS 10.10.5), see the screenshot attached.

It does not help to add up to three seconds waiting time after "Stack to
Images", and even much later the Windows menu shows the 'old' background
file being the current one (screenshot). ImageJ 1.51p and the latest
daily build give the same result. I really wonder why...

Michael
________________________________________________________________
On 06/10/2017 13:04, Cardone, Giovanni wrote:

> Hi Michael,
>
> my tests were on Windows, but I repeated them on a fresh install of ImageJ on Linux, and the issue remains.
> Regarding delays, I don't observe any, the macro runs in less than 200 ms.
> I also tested variants of the script and below is the simplest one, showing a consistent result: after 'stack to images' the active image is the last generate before the converted one. This would point to a race conditions like you suspected.
>
> Best,
> Giovanni
>
> - script
>
> run("Close All");
> print("\\Clear");
>
> newImage("dummy", "32-bit ramp", 64, 32, 3);
> dummyID=getImageID();
> currentTitle=getTitle();
> print("First image: Title: ",currentTitle," ID: ",dummyID);
> newImage("OriginalStack", "32-bit ramp", 64, 32, 3);
> origStackID=getImageID();
> print("origStackID ",origStackID);
> print(" - converting stack to images");
> run("Stack to Images");
> afterStacktoIm3ID=getImageID();// current image
> currentTitle=getTitle();
> print("active image after stack-to-images: Title: ",currentTitle," ID: ",afterStacktoIm3ID);
>
> - output from script
>
> First image: Title:  dummy  ID:  -550
> origStackID  -551
>   - converting stack to images
> active image after stack-to-images: Title:  dummy  ID:  -550
>
>
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
> Sent: Freitag, 6. Oktober 2017 12:04
> To: [hidden email]
> Subject: Re: an odd image ID problem
>
> 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
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

tmp-testImageID.jpg (71K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: an odd image ID problem

Wayne Rasband-2
In reply to this post by Jeremy Adler-2
> On Oct 5, 2017, at 4:06 AM, Jeremy Adler <[hidden email]> wrote:
>
> 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.

This bug is fixed in the latest ImageJ daily build (1.51r20). This fix is only for the "Stack to Images” command. There may be other commands that close images with similar problems.

-wayne


> 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