Login  Register

Re: How redisplay ImagePlus window after being closed?

Posted by Michael Schmid on May 19, 2010; 10:37am
URL: http://imagej.273.s1.nabble.com/How-redisplay-ImagePlus-window-after-being-closed-tp3687861p3687862.html

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