interactive plugin

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

interactive plugin

Tony Shepherd
Hi,

I want to make an interactive plugin that asks the user to draw different
ROIs during runtime (instead of using what ever ROI was drawn with ImageJ
before the plugin was executed)

Does anybody have a method for defining a polygon ROI interactively?
It needs to listen to the mouse, populate a vector with co-ordinates where
the mouse is clicked, and stop when the user double clicks (or similar).

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: interactive plugin

Wayne Rasband
> I want to make an interactive plugin that asks the user to
> draw different ROIs during runtime (instead of using what
> ever ROI was drawn with ImageJ before the plugin was
> executed)
>
> Does anybody have a method for defining a polygon ROI
> interactively? It needs to listen to the mouse, populate a
> vector with co-ordinates where the mouse is clicked, and
> stop when the user double clicks (or similar).

A much easier way to do this would be to draw the ROIs, add them to the
ROI Manager, then run the plugin. The plugin would display an error
dialog if the expected number of ROIs are not in the ROI Manger. ImageJ
1.37q will have a new Edit>Selection>Add to Manager command that allows
the user to open the ROI Manager or add an ROI to it by pressing 't',
the shortcut for the new command.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: interactive plugin

William O'Connell
In reply to this post by Tony Shepherd
Hi Tony,
I wrote such a plugin. The code is below with some usage snippets. Be sure to check that an ROI returned by "getCompletedRoi" is non null. It will be null if the wait for user action times out at 120 seconds.

Best, William O'Connell

<snip>
// usage examples
// get ED outline
        Roi edRoi = getCompletedRoi(imp, "Please outline ED region of interest...");
.
.
// get background region
        Roi bgRoi = getCompletedRoi(imp, "Please outline ventricular background");
.
.
<snap>

// Roi routines
        Roi getCompletedRoi(ImagePlus imp, String message){
          Roi roi = null;
          boolean doRoi = true, firstTime = true;
          String s = "Click OK to accept ROI\nCancel to redraw ROI";
          while(doRoi) {
             imp.killRoi(imp); // erase any existing ROI
             if(firstTime) IJ.showMessage(message);
             firstTime = false;
             roi = waitForRoi(imp,120);  // wait for new ROI
             if(roi==null) IJ.log("timed out!");
             else {
                  IJ.log("Type is " + roi.getTypeAsString() + " state is " + roi.getState());
                      doRoi = !IJ.showMessageWithCancel("ROI", s);
                  }
          }  // while
          return roi;
        }

// Waits for an area ROI to complete before returning it to user.
// If elapsed time exceeds user specified limit, waitForRoi returns a null ROI.
                 Roi waitForRoi(ImagePlus imp, int limit){
                  int COMPLETE = 3;
                  int elapsed = 0, interval = 500;
                  int timeOut = 1000*limit;
                  Roi roi = null;
                  while((roi==null) || (!roi.isArea()) ||  (roi.getState()!=COMPLETE))
                     {
                     IJ.wait(interval);
                     roi = imp.getRoi();
                     elapsed += interval;
                     if(elapsed>timeOut) return null;
                     }
                 return roi;
                 }

 

-------------- Original message ----------------------
From: Tony <[hidden email]>

> Hi,
>
> I want to make an interactive plugin that asks the user to draw different
> ROIs during runtime (instead of using what ever ROI was drawn with ImageJ
> before the plugin was executed)
>
> Does anybody have a method for defining a polygon ROI interactively?
> It needs to listen to the mouse, populate a vector with co-ordinates where
> the mouse is clicked, and stop when the user double clicks (or similar).
>
> Thanks
Reply | Threaded
Open this post in threaded view
|

Re: interactive plugin

dscho
In reply to this post by Tony Shepherd
Hi,

On Thu, 24 Aug 2006, Tony wrote:

> Does anybody have a method for defining a polygon ROI interactively?

Yes. I implemented what you need in the Delaunay plugin:

http://wbgn013.biozentrum.uni-wuerzburg.de/ImageJ/delaunay.html

Actually, it defines a point ROI, but since PointROI extends PolygonROI,
it should be easy enough to change.

The important parts are the MouseListener interface, and that you call
addMouseListener().

Ciao,
Dscho