Re: Can't automate copying of polygon ROIs
Posted by
Andy-92 on
Jun 10, 2008; 3:07pm
URL: http://imagej.273.s1.nabble.com/Can-t-automate-copying-of-polygon-ROIs-tp3695935p3695941.html
Thanks Wayne,
That has the intended effect (and fixes the problem), however, I am
performing this copy/paste hundreds of times on the same image. So, every
time I call Internal Clipboard, a new image pops up on the screen, I have to
save it, and then hide the image so I can work on the original image again.
It's just messy and I'm wondering why my method of copying using
getClipboard() produces unintended effects. Thanks!
On Mon, Jun 9, 2008 at 5:15 PM, Wayne Rasband <
[hidden email]> wrote:
> 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
>