How redisplay ImagePlus window after being closed?

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

How redisplay ImagePlus window after being closed?

whoiswho
Hi,

I'm currently working on a plugin for ImageJ but have run into a problem regarding windows.

I currently have an ImagePlus object -- let's name it imp -- containing a stack of images. It pops up nicely using imp.show() the first time. After closing the window (via the close button) associated with this ImagePlus, I try using imp.show() to display the window again, but nothing happens.

I have a few questions about this:

1. What actually happens when you manually close the window (to an ImagePlus)? Same as calling imp.close()?

2. What are the different ways to accomplish displaying the window for the ImagePlus after it's been closed?

3. Is there a way to modify the window close behaviour (for windows obtained by ImagePlus.show()), e.g. hide the window instead of closing it. Preferably _before_ the window has been displayed. For instance, for JFrame there is the setDefaultCloseOperation method that accomplishes this.

Thanks!

Best regards
whoiswho
Reply | Threaded
Open this post in threaded view
|

Re: How redisplay ImagePlus window after being closed?

Michael Schmid
On 19 May 2010, at 02:14, whoiswho wrote:

> I currently have an ImagePlus object -- let's name it imp --  
> containing a
> stack of images. It pops up nicely using imp.show() the first time.  
> After
> closing the window (via the close button) associated with this  
> ImagePlus, I
> try using imp.show() to display the window again, but nothing happens.

Closing an ImageWindow (ImageWindow.close) calls imp.flush(), which  
deletes many class variables of the imp (essentially everything that  
needs significant amounts of memory is set to null).
I guess that the rationale behind it is making these available for  
garbage collection as soon as possible, even if a reference to imp  
still remains somewhere.

If you don't have a stack, a solution would be keeping a reference to  
the ImageProcessor in the imp and keep it instead of imp (also the  
roi). If you have no stack, you could also try to clone the ImagePlus  
to get a copy that can be displayed again - memory consumption for  
cloning would be rather low ('shallow cloning').

For stacks, it would be more complicated: ImageWindow.flush() sets  
the elements of the image array to null. Keeping the stack or a  
shallow clone of the ImagePlus would not help, in addition you would  
need a (shallow) clone of the imageArray.

Michael
Reply | Threaded
Open this post in threaded view
|

Re: How redisplay ImagePlus window after being closed?

whoiswho
Thanks for your reply Michael, and thx to the guy replying directly via email.

I guess it's pretty far-fetched to get my original idea to work -- being able to show an ImagePlus stack after closing it -- especially with it being a rather large stack. Likely I'll abandon that idea.

One of the other questions I had was if there was a possibility in ImageJ to alter the closing mechanism of an ImagePlus so that it hides the window instead of closes it. I've looked up ImageListener for instance, but for that to work you'd need to be able to access the ImageWindow (associated with the ImagePlus), and that isn't available/created until you call the show method for the first time. I guess you could change the listener once show has been called, but perhaps it's more omplicated? I'll look into it...

Best regards
whoiswho
Reply | Threaded
Open this post in threaded view
|

Re: How redisplay ImagePlus window after being closed?

intheclouds089
Hello whoiswho,

I had a similar problem, and for me it was enough to create a new StackWindow out of the ImagePlus instead of calling the show method.

Best,
Christian
Reply | Threaded
Open this post in threaded view
|

Re: How redisplay ImagePlus window after being closed?

intheclouds089
Hello again,

I just realized that this only worked in cases where a copy of the stack was created and then displayed. An existing stack will also be gone after closing the window.
I wonder if creating a deep copy of the stack and then displaying that instead would work. (in Ruby Marshal.load(Marshal.dump()))

Best regards,
Christian