restricting drawing to an ROI

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

restricting drawing to an ROI

Joe Edwards
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
Reply | Threaded
Open this post in threaded view
|

Re: restricting drawing to an ROI

Marcel
You can use the latest ImageJ API to iterate over the ROI and set the pixels.

See:

https://imagej.nih.gov/ij/plugins/roi-iterator/index.html

https://imagej.nih.gov/ij/notes.html
Reply | Threaded
Open this post in threaded view
|

Re: restricting drawing to an ROI

Joe Edwards
In reply to this post by Joe Edwards
I could find no straight forward (to me) way to use
existing ImageJ methods to keep the drawing inside our figures.

So I added a few lines to the ImageProcessor & ByteProcessor.
Now I can move on. Thanks for your advice.

in my plugin:
  ip.setShapeRoi(sr);

diff ImageProcessor.java
104,111d103
< protected ShapeRoi shapeRoi;
<
< public void setShapeRoi(ShapeRoi shapeRoi) {
<     this.shapeRoi=shapeRoi;
< }
< public ShapeRoi getShapeRoi() {
<     return shapeRoi;
< }

diff -bBtw ByteProcessor.java
343d342
< if(shapeRoi==null || shapeRoi.contains(x, y)) {
351d349
< }
358d355
< if(shapeRoi==null || shapeRoi.contains(x, y)) {
364d360
< }
369d364
< if(shapeRoi==null || shapeRoi.contains(x, y))

Joe Edwards
UWMC, ITS, Senior Computer Specialist


On Mon, 9 May 2016, Joe Edwards wrote:

>
> 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 do not see how to get a Shape to the Graphics2.setClip() method
> to restrict drawing.

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