Login  Register

Re: how to copy ROI to new image

Posted by Wayne Rasband on Aug 16, 2005; 9:05pm
URL: http://imagej.273.s1.nabble.com/how-to-copy-ROI-to-new-image-tp3705016p3705017.html

> I have written a small plug-in to calculate the relative
> optical density of selected pixels. However, I am having a
> problem understanding the API. What is the easiest way to
> create a new image from a selection in an existing image?

The easiest way to do this is to run the Image>Duplicate command:

     IJ.run("Duplicate...", "title=[selected region]");

If the existing image is not the current image you would need to make
it the current image:

     WindowManager.setTempCurrentImage(inputImage);
     IJ.run("Duplicate...", "title=[selected region]");

You can also get the image's ImageProcessor, crop it, then open it as a
new image:

     new ImagePlus("selected region",
inputImage.getProcessor().crop()).show();

-wayne