Login  Register

Live update ImagePlus

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Live update ImagePlus

Nikolay
23 posts
Could you please advice, how I can do live update images in one ImagePlus.
When I tried to do this I always saw the last image, may be I need to use
thread somehow to update image window?

buttonPreview.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae) {
            short[] bb = new short[(int)W*H];
            //int counter = 0;
            preview_ip = new ShortProcessor(W,H,bb, null);
            preview = new ImagePlus("Preview Image", preview_ip);
            preview.show();
             //while (counter <10) {
                 p = sdll.previewImages();
         bb = p.getShortArray(0, (int)W*H);
         preview_ip = new ShortProcessor(W,H,bb, null);
         preview.setProcessor("1", preview_ip);
         IJ.wait(555);
         p = sdll.previewImages();
         bb = p.getShortArray(0, (int)W*H);
         preview_ip = new ShortProcessor(W,H,bb, null);
         preview.setProcessor("2", preview_ip);
         //preview.show();
         //counter++;
            //}
            }
        });


Thank you.
--
Rogoshchenkov Nikolay

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

Re: Live update ImagePlus

Michael Schmid
2136 posts
Hi Nikolay,

the easiest way of having preview in ImageJ is writing an ExtendedPlugInFilter.

It should have a showDialog method where the GenericDialog is displayed, there you need to have gd.addPreviewCheckbox and gd.addDialogListener(this) commands.

On each user input, there will be a call to the dialogItemChanged method, where you can read the input from the filter and set global variables.

ImageJ then takes care of calling the ExtendedPlugInFilter's run(ip) method on each input action of the user. The run(ip) method would typically call a method that does the actual calculation, with the global variables from the dialog as parameters.
If there is new user input while the calculation is still running, ImageJ sets the 'interrupred' status for the thread doing the calculation. Thus, for calculations that can take longer than a few tenths of a second, the run(ip) should repeatedly check for Thread.currentThread().isInterrupted() and simply terminate if the thread has been interrupted. ImageJ takes care of the rest, e.g., reverting the image data to the original state if a caculation is interrupted.

Here is an example:
  http://rsb.info.nih.gov/ij/plugins/sigma-filter.html

And here is another text to explain this:

An ExtendedPlugInFilter will be invoked by ImageJ the following way:
(1) Call to setup with the current foreground ImagePlus (image window)
    and the argument string 'arg' specified in the plugins.config file
    or a.jar file that contains it.
    The PlugInFilter returns its flags.
(2) If the currently active image is compatible with the flags (and DONE
    was not specified)  showDialog is called. If the reference to the
    PlugInFilterRunner passed with showDialog is specified as an argument
    to the addPreviewCheckbox method of a GenericDialog, preview will be
    possible and the run method of this ExtendedPlugInFilter will be called
    in the background for preview.
(3) Unless otherwise specified in the flags (DONE or keeping the preview
    as an output for a non-stack ImagePlus), the run method is called.
    For stacks, it is called repeatedly for each slice.
(4) If the FINAL_PROCESSING flag has been set (but not DONE), the
    setup method is invoked with "final" as parameter string.
 ** If this PlugInFilter contains a showAbout() method, its setup method
    may be also called with argument string "about". Then, the filter will
    display a short help message.
   
DialogListener: This PlugInFilter provides the dialogItemChanged method, whoch will
    be called if required by the addDialogListener method of the GenericDialog.
    For preview-enabled ExtendedPlugInFilters, the filter parameters/options
    should be set in the dialogItemChanged method.

---
If you can't do it with an ExtendedPlugInFilter, concerning your code:

I think that it is not a good idea to have everything done in the actionPerformed method - this method runs in the EventQueue thread, thus it blocks all user input until the actionPerformed method has finished. It may also block updating the image. If you want some code like this, actionPerformed should create a new thread where everything is done.

Michael
________________________________________________________________
On Nov 9, 2012, at 23:01, Nikolay Rogoshchenkov wrote:

> Could you please advice, how I can do live update images in one ImagePlus.
> When I tried to do this I always saw the last image, may be I need to use
> thread somehow to update image window?
>
> buttonPreview.addActionListener(new ActionListener(){
>            public void actionPerformed(ActionEvent ae) {
>            short[] bb = new short[(int)W*H];
>        int counter = 0;
>            preview_ip = new ShortProcessor(W,H,bb, null);
>            preview = new ImagePlus("Preview Image", preview_ip);
>            preview.show();
>         while (counter <10) {
>                 p = sdll.previewImages();
>         bb = p.getShortArray(0, (int)W*H);
>         preview_ip = new ShortProcessor(W,H,bb, null);
>         preview.setProcessor("1", preview_ip);
>         IJ.wait(555);
>         p = sdll.previewImages();
>         bb = p.getShortArray(0, (int)W*H);
>         preview_ip = new ShortProcessor(W,H,bb, null);
>         preview.setProcessor("2", preview_ip);
>     preview.show();
>     counter++;
>        }
>            }
>        });
>
>
> Thank you.
> --
> Rogoshchenkov Nikolay
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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