Login  Register

Re: ImageJ undo notification

Posted by Michael Schmid on Jul 10, 2007; 10:01am
URL: http://imagej.273.s1.nabble.com/ImageJ-undo-notification-tp3698860p3698861.html

Hi Jon,

> Just wondering if there is any way my plugin can find out if
> undo has been done on an image.
In Undo.java, the whatToUndo variable is private, so you can't
use it to determine whether undo has been done or not.

I see one possibility for a workaround:

If you have a PlugInFilter that does not specify NO_CHANGES or
NO_UNDO, and you are working on a single image (not a full stack), a
snapshot (copy of the pixels) will be created when you run the filter.
If your filter really changes the image (if it is not a "null"
operation such as adding zero), the snapshot will be different
from the image after filtering, but equal to the image after
undo. So something like the following may work:
boolean undoDone = java.utils.Arrays.equals(ip.getPixels(),  
ip.getSnapshotPixels())
An easier (though not 100% safe) way would be to remember a
hashcode of the pixels array after each operation and see whether
it has changed or been reverted to the previous state.

> More generally I'd like to know the sequence of ImageJ commands
> that have been performed on an image.  Does ImageJ keep a log
> of this somewhere?
No, unless the Macro Recorder is active. As far as I understand
the Recorder.java code, the recorder has no public methods that
would allow reading what it has recorded.

Even in case we had a method like
   public String Recorder.getRecordedText()
you should not expect to get the history of an image from the
recorder: Some operations are not recorded, e.g. selecting an
image by clicking onto it. So you never know which image a
command was acting on.

For your own plugins, you can of course store a log of each
operation in the info of the ImagePlus.

Having such a feature in ImageJ would be nice, but I fear it
would be a hell of work to implement it (more than 20 source
files make calls to the Recorder).
Also, a really proper recording of the workflow would be close
to impossible. E.g., processing may need several images,
involve duplicating or the Image Calculator (or plugins)
combining images, etc.

Regards,

Michael