Login  Register

Re: Can't automate copying of polygon ROIs

Posted by Wayne Rasband on Jun 09, 2008; 9:15pm
URL: http://imagej.273.s1.nabble.com/Can-t-automate-copying-of-polygon-ROIs-tp3695935p3695940.html

> I am having trouble copying ROIs that are based on polygons
> (non-rectangular).  If I create a polygon ROI by hand, and do
> Edit->Copy,
> then File->New->Internal Clipboard, I get a new image the same size as
> the
> bounding box of the ROI, but anything NOT inside the ROI is white (or
> whatever the background color is). This is the effect I want, but if I
> do it
> in code:
>
> img.setRoi(p); //Where p is a polygon and img is an ImagePlus
> img.copy(false);
> ImagePlus newImg = new
> ImagePlus("img",ImagePlus.getClipboard().getProcessor().duplicate());
>
> When I do that, I get a new image that contains EVERYTHING inside the
> bounding box of the polygon. this includes a LOT of data that I do not
> want
> in the image. How can I obtain the same effect as edit->copy in my
> code?

You can do this sort of thing easily in a macro:

    makeOval(50, 50, 100, 100);
    run("Copy");
    run("Internal Clipboard");

In a plugin, the code would look something like this:

    img = IJ.getImage();
    img.setRoi(p)
    IJ.run("Copy");
    IJ.run("Internal Clipboard");

-wayne