Posted by
David Webster on
URL: http://imagej.273.s1.nabble.com/Multiple-ROI-Display-tp3690458p3690461.html
Wayne,
OK, got a plugin that misbehaves. Build it with version 1.43I5. Select run
time option "Use Daily Build" to do the rm.runCommand("Show All") or
otherwise rm.runCommand("Combine"). The "Use Daily Build" option display
nothing until you select or something like
"Number of Circles = 15". The non daily build option doesn't care.
David Webster
import ij.*;
import ij.process.*;
import ij.gui.*;
import ij.plugin.filter.PlugInFilter;
import ij.plugin.frame.RoiManager;
public class TestDraw_ implements PlugInFilter
{
ImagePlus imp;
public int setup(String arg, ImagePlus imp) {
this.imp = imp;
return DOES_ALL;
}
public void run(ImageProcessor ip)
{
GenericDialog gd = new GenericDialog("Circle Params", IJ.getInstance());
gd.addNumericField("Number of circles", 3, 0);
gd.addCheckbox("Use Daily Build", false);
gd.showDialog();
int cmax = (int)gd.getNextNumber();
boolean usedb = gd.getNextBoolean();
int x[] = new int[cmax]; int y[] = new int[100]; int r[] = new int[100];
for(int k = 0; k < cmax; k++)
{
x[k] = 20*k+20; y[k] = 100; r[k]=10;
}
drawEllipticalOutline( ip, x,y,r, usedb);
}
void drawEllipticalOutline( ImageProcessor ip, int x[], int y[], int r[],
boolean usedb)
{
ImagePlus imp2 = new ImagePlus(x.length+" Circles Found", ip);
imp2.show();
RoiManager rm = new RoiManager();
int numdrawn = 0;
for(int k = 0; k < x.length; k++)
{
IJ.makeOval(x[k]-r[k], y[k]-r[k], 2*r[k]+1,2*r[k]+1);
rm.runCommand( "Add");
numdrawn++;
}
if( usedb == true)
rm.runCommand("Show All");
else
rm.runCommand("Combine");
rm.close();
}
}
On Sat, Nov 14, 2009 at 9:45 PM, Wayne Rasband <
[hidden email]> wrote:
> Wayne,
>>
>> I tried rm.runCommand("Show All") but am getting one/off buggy
>> behavior. Sometime my circles get displayed and sometimes not.
>> For example, if I turn on the macro recorder, then my circles seem
>> to be displayed. When it's off, I get nothing. There alos seems to
>> be some relationship to how many circles I try to display. Too few,
>> and I get nothing.
>>
>> David Webster
>>
>
> Try displaying the circles in an overlay. Here is a JavaScript example that
> displays 50 circular ROIs at random locations and in random colors as an
> overlay.
>
> -wayne
>
> if (IJ.getVersion()<"1.43k")
> IJ.error("Requires ImageJ 1.43k or later");
> n = 50;
> w = 1000, h = 700;
> imp = IJ.createImage("Demo","8-bit Ramp",w,h,1);
> imp.show();
> ran = new Random();
> list = new Vector();
> size = w/10;
> for (i=0; i<n; i++) {
> x = ran.nextFloat()*(w-size);
> y = ran.nextFloat()*(h-size);
> roi = new OvalRoi(x,y,size,size);
> color = new Color(ran.nextFloat(),ran.nextFloat(),ran.nextFloat());
> roi.setStrokeColor(color);
> roi.setStrokeWidth(2);
> list.addElement(roi);
> }
> imp.setDisplayList(list);
> IJ.wait(2000);
> IJ.run(imp,"Hide Overlay","");
> IJ.wait(2000);
> for (i=0; i<n; i++)
> list.get(i).setStrokeWidth(8);
> IJ.run(imp,"Show Overlay","");
>