ImagePlus.updateAndDraw() when the underlying stack is virtual doesn't update

Hi @Wayne,

I am wondering if ImagePlus.updateAndDraw() is the right method to call when the underlying virtual stack is updated. According to the code at https://github.com/imagej/imagej1/blob/master/ij/ImagePlus.java#L255 the updateAndDraw() method doesn’t update the pixels of the image when stack.isVirtual() is true. Instead, it refreshes the UI component, but doesn’t create the image new.

What would be the correct method to update an ImagePlus display when the underlying virtual stack has changed?

Thanks.

By the way my current hack is to browse one slice forward and back, programmatically.

Upgrade to the the latest ImageJ daily build (1.52m30) and use the ImagePlus.updateVirtualSlice() method, which is equivalent to

imp.setProcessor(imp.getStack().getProcessor(imp.getCurrentSlice()))

1 Like

Thanks Wayne, I had tried this solution of setting the same processor. The issue is that it seems to reset the min and max, at least for virtual stacks backed up by ImgLib2 volumes, and that is rather surprising.

This problem with the new updateVirtualSlice() method is fixed in the latest daily build (1.52m31). Here is what the method now looks like:

   /** Use to update the image when the underlying virtual stack changes. */
   public void updateVirtualSlice() {
      ImageStack vstack = getStack();
      if (vstack.isVirtual()) {
         double min=getDisplayRangeMin(), max=getDisplayRangeMax();
         setProcessor(vstack.getProcessor(getCurrentSlice()));
         setDisplayRange(min,max);
      } else
         throw new IllegalArgumentException("Virtual stack required");
   }
1 Like