Login  Register

Re: confusing overlay behavior

Posted by Kenneth Sloan-2 on Nov 29, 2019; 6:57pm
URL: http://imagej.273.s1.nabble.com/confusing-overlay-behavior-tp5022716p5022728.html

Success!
 
mea culpa!  It was my fault.

In my extension to ImagePlus (call it MyImagePlus), someone (perhaps me, perhaps an earlier author) maintained a private copy of an Overlay used to draw a frame and cursor on the image.  The method getOverlay() was overridden to return this cached Overlay.

I suspect that "Duplicate" and friends call MyImagePlus.getOverlay() to get the Overlay, while Plugins->Utilities->Capture Image deals with the image actually displayed on screen.

My user-level code was calling ImagePlus.setOverlay() (which was NOT overridden in MyImagePlus) and changing what was displayed on the screen.  This was invisible to MyImagePlus - and thus invisible to "Duplicate" and friends.

The good news is that I took this opportunity to significantly clean up the Overlay handling code in MyImagePlus and the user-level program.  Most of this cleanup had nothing to do with this issue - but clean-up is always good.   In retrospect, I probably could have fixed this by simply removing the override of getOverlay().  But...I didn't really understand what was going on until AFTER I had cleaned everything up.

Many thanks to Michael for pointing me in the right direction.

My apologies for suggesting that this demonstrated a problem with ImagePlus *sometimes* saving its own copy of an Overlay and *sometimes* pushing it into ImageCanvas.  That may still bear looking into - but I no longer think it was any part of the cause of my problems.

My current approach is to identify ONE location where ImagePlus.setOverlay() needs to be called, and make all other modifications by calling ImagePlus.getOverlay() to fetch the current Overlay and then manipulating the ROIs attached to that Overlay.  No ImagePlus.setOverlay() is necessary - but ImagePlus.updateAndDraw() does seem to be necessary when adding new ROIs.  Overlay.clear() appears to have immediate effect.

--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html