Login  Register

restricting drawing to an ROI

Posted by Joe Edwards on May 09, 2016; 11:44pm
URL: http://imagej.273.s1.nabble.com/restricting-drawing-to-an-ROI-tp5016377.html

I reviewed lots of plugins and read over several tutorials.
Including, 'Image Processing with ImageJ' and the ImageJ twiki.
And I've searched the forum.

I have a plugin that defines an ROI and draws to the image.
It is based on plugins that others have shared.

public int setup(String arg, ImagePlus imp) {
  ...
  ...
  imp = IJ.getImage();
  vwt = new Versatile_Wand_Tool();
  vwt.doWand(imp, 172, 172, 0, 0, 0, "");
  sr0 = new ShapeRoi(imp.getRoi());
  imp.killRoi();
  vwt.doWand(imp, 516, 172, 0, 0, 0, "");
  sr1 = new ShapeRoi(imp.getRoi());
  sr = sr0.or(sr1);
  s = sr.getShape();
  imp.setRoi(sr);
  ...
  ...
}

The img has the ROI set.

But, I do not understand how to limit the drawing to the ROI.

I'd like a hint or, better, an example.

I see that Toggle_Paintbrush_.java shows how to handle mouse events in a plugin.

I do not see how to get a Shape to the Graphics2.setClip() method
to restrict drawing. I understand, I think,  that I'll need the
complimentary Shape to draw inside and not outside of the ROI.

Joe Edwards
UWMC, ITS, Senior Computer Specialist

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