add a set of point coordinates to ROI manager

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

add a set of point coordinates to ROI manager

adiro
This post was updated on .
I have a set of point (I have their x,y pixel coordinates) that I would like to add to the ROI manager. how do I do that?
Reply | Threaded
Open this post in threaded view
|

Re: add a set of point coordinates to ROI manager

Marcel
Here is a small code snippet:

**************************************
ImagePlus imp = IJ.getImage();

/*Create a Polygon ROI!*/

int[] xp = { 5, 50, 100, 150, 200, 250, 300 };
int[] yp = { 100, 200, 200, 200, 200, 100 };
PolygonRoi polRoi = new PolygonRoi(xp, yp, 6, Roi.POLYGON);
imp.setRoi(polRoi);

/*Add the ROI to the ROI Manager!*/

RoiManager manager = RoiManager.getInstance();
  if (manager == null)
     {
        manager = new RoiManager();
     }
manager.addRoi(polRoi);

*************************************

For different ROI types see:

http://rsbweb.nih.gov/ij/developer/api/ij/gui/Roi.html

Reply | Threaded
Open this post in threaded view
|

Re: add a set of point coordinates to ROI manager

adiro
Hi, 
So sorry but I'm a newbie... where do I put this code?


2014-08-18 9:55 GMT+03:00 Bio7 [via ImageJ] <[hidden email]>:
Here is a small code snippet:

**************************************
ImagePlus imp = IJ.getImage();

/*Create a Polygon ROI!*/

int[] xp = { 5, 50, 100, 150, 200, 250, 300 };
int[] yp = { 100, 200, 200, 200, 200, 100 };
PolygonRoi polRoi = new PolygonRoi(xp, yp, 6, Roi.POLYGON);
imp.setRoi(polRoi);

/*Add the ROI to the ROI Manager!*/

RoiManager manager = RoiManager.getInstance();
  if (manager == null)
     {
        manager = new RoiManager();
     }
manager.addRoi(polRoi);

*************************************

For different ROI types see:

http://rsbweb.nih.gov/ij/developer/api/ij/gui/Roi.html




If you reply to this email, your message will be added to the discussion below:
http://imagej.1557.x6.nabble.com/add-a-set-of-point-coordinates-to-ROI-manager-tp5009232p5009246.html
To unsubscribe from add a set of point coordinates to ROI manager, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: add a set of point coordinates to ROI manager

Marcel
Hello,

1. Start ImageJ and create a new Java Plugin: Plugins->New->Plugin
2. Paste the code below in the ImageJ editor (overwrite the default code)
3. Save the file in the ImageJ plugins directory
4. Open an example image
5. Compile and run the plugin from the text editor: File->Compile and Run


import ij.IJ;
import ij.ImagePlus;
import ij.gui.PolygonRoi;
import ij.gui.Roi;
import ij.plugin.PlugIn;
import ij.plugin.frame.RoiManager;

public class My_Plugin implements PlugIn {

        public void run(String arg) {
                ImagePlus imp = IJ.getImage();
                int[] xp = { 5, 50, 100, 150, 200, 250, 300 };
                int[] yp = { 100, 200, 200, 200, 200, 100 };
                PolygonRoi polRoi = new PolygonRoi(xp, yp, 6, Roi.POLYGON);
                imp.setRoi(polRoi);

                RoiManager manager = RoiManager.getInstance();
                if (manager == null){
                        manager = new RoiManager();
                }
                manager.addRoi(polRoi);

        }

}


Read the ImageJ documentation for more details about plugins:

http://imagej.nih.gov/ij/docs/guide/146-16.html#toc-Section-16

Reply | Threaded
Open this post in threaded view
|

Re: add a set of point coordinates to ROI manager

adiro
nice! thanks it works :)


2014-08-29 9:57 GMT+03:00 Bio7 [via ImageJ] <[hidden email]>:
Hello,

1. Start ImageJ and create a new Java Plugin: Plugins->New->Plugin
2. Paste the code below in the ImageJ editor (overwrite the default code)
3. Save the file in the ImageJ plugins directory
4. Open an example image
5. Compile and run the plugin from the text editor: File->Compile and Run


import ij.IJ;
import ij.ImagePlus;
import ij.gui.PolygonRoi;
import ij.gui.Roi;
import ij.plugin.PlugIn;
import ij.plugin.frame.RoiManager;

public class My_Plugin implements PlugIn {

        public void run(String arg) {
                ImagePlus imp = IJ.getImage();
                int[] xp = { 5, 50, 100, 150, 200, 250, 300 };
                int[] yp = { 100, 200, 200, 200, 200, 100 };
                PolygonRoi polRoi = new PolygonRoi(xp, yp, 6, Roi.POLYGON);
                imp.setRoi(polRoi);

                RoiManager manager = RoiManager.getInstance();
                if (manager == null){
                        manager = new RoiManager();
                }
                manager.addRoi(polRoi);

        }

}


Read the ImageJ documentation for more details about plugins:

http://imagej.nih.gov/ij/docs/guide/146-16.html#toc-Section-16




If you reply to this email, your message will be added to the discussion below:
http://imagej.1557.x6.nabble.com/add-a-set-of-point-coordinates-to-ROI-manager-tp5009232p5009412.html
To unsubscribe from add a set of point coordinates to ROI manager, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: add a set of point coordinates to ROI manager

vincer
In reply to this post by Marcel
Hello,

i tried to run the code but i get an Macro error saying there is an undefinded variable in line 1 (import ij.IJ; )
How can I fix this?

Thank you