ImageJ undo

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

ImageJ undo

Jon Harman-3
Hi,
I am having a problem getting undo to work in my plugin.  This is my code:

imp.trimProcessor();
Undo.setup(Undo.COMPOUND_FILTER, imp);
hueClean(imp, nnbrs);
IJ.showStatus("Cleaning Finished");
imp.getProcessor().resetMinAndMax();
imp.updateAndDraw();
if(!IJ.showMessageWithCancel("Hue Mask","Keep cleaned image?")){
        Undo.undo();
        }

This works the first time.  But if undo is chosen then the second time
(and subsequent times) through this code my hueClean routine doesn't
change the image.

I have no clue.

Jon

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ undo

Michael Schmid
Hi Jon,

a few points, maybe one of them will help:

- COMPOUND_FILTER is needed only if the operations of your plugin modify
the snapshot (the copy used for undo) of the ImageProcessor; e.g. if you
have several operations in succession, and any of these operations (except
the first) uses the snapshot. Operations that work on single pixels
(Process>Math>...), the RankFilters (Median, Mean, Minimum, Maximum) and
Guassian Blur of the full image (no ROI) do not use the snapshot.

- When using Undo.setup(Undo.COMPOUND_FILTER, imp), you should terminate
the plugin with Undo.setup(Undo.COMPOUND_FILTER_DONE, imp). Otherwise you
will keep a copy of your image in memory forever.

- Another simple method for undo is the following: create a copy of your
ImagePorcessor with
  ImageProcessor copyOfIp = ip.duplicate();
and if you want to undo the operations, use imp.setProcessor(copyOfIp). If
your operations have only affected the image data, not the threshold,
etc., you can also use ip.setPixels(copyOfIp.getPixels()) [I guess that
the latter method won't work for stacks!]
The Garbage Collector will know that it can discard your copyOfIp after
your plugin has finished (unless you declare it static).

Michael
___________________________________________________________

On Fri, March 1, 2013 21:59, Jon Harman wrote:

> Hi,
> I am having a problem getting undo to work in my plugin.  This is my code:
>
> imp.trimProcessor();
> Undo.setup(Undo.COMPOUND_FILTER, imp);
> hueClean(imp, nnbrs);
> IJ.showStatus("Cleaning Finished");
> imp.getProcessor().resetMinAndMax();
> imp.updateAndDraw();
> if(!IJ.showMessageWithCancel("Hue Mask","Keep cleaned image?")){
> Undo.undo();
> }
>
> This works the first time.  But if undo is chosen then the second time
> (and subsequent times) through this code my hueClean routine doesn't
> change the image.
>
> I have no clue.
>
> Jon
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ undo

Jon Harman-3
In reply to this post by Jon Harman-3
Hi,
Thanks Wayne.  The "dup=imp.getProcessor().duplicate()" way works.  I
can't get the other to work.

Jon

Rasband, Wayne (NIH/NIMH) [E] wrote:

> Hi Jon,
>
> I don't know what your hueClean() method is doing but this JavaScript version, where hueCode() adds 50 to the image, seems to work as expected. I also tried using  "dup=imp.getProcessor().duplicate()" to create a backup of the image and "imp.setProcessor(dup)" to restore (undo) it, and that also worked as expected.
>
> Best regards,
>
> -wayne
>
> imp = IJ.getImage();
> for (i=0; i<5; i++) {
>    Undo.setup(Undo.COMPOUND_FILTER, imp);
>    hueClean(imp);
>    imp.updateAndDraw();
>    if (!IJ.showMessageWithCancel("Hue Mask","Keep cleaned image?"))
>        Undo.undo();
> }
>
> function hueClean(imp) {
>    ip = imp.getProcessor();
>    ip.add(50);
> }
>
>
> On Mar 1, 2013, at 3:59 PM, Jon Harman wrote:
>
>> Hi,
>> I am having a problem getting undo to work in my plugin.  This is my code:
>>
>> imp.trimProcessor();
>> Undo.setup(Undo.COMPOUND_FILTER, imp);
>> hueClean(imp, nnbrs);
>> IJ.showStatus("Cleaning Finished");
>> imp.getProcessor().resetMinAndMax();
>> imp.updateAndDraw();
>> if(!IJ.showMessageWithCancel("Hue Mask","Keep cleaned image?")){
>> Undo.undo();
>> }
>>
>> This works the first time.  But if undo is chosen then the second time
>> (and subsequent times) through this code my hueClean routine doesn't
>> change the image.
>>
>> I have no clue.
>>
>> Jon
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
>

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