A problem of ROI coordiantes shifting by using getXCoordinates

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

A problem of ROI coordiantes shifting by using getXCoordinates

jiajian shen
 Hi All,

I am writing a pluginfilter, which needs get PolygonRoi coordinates from a
selected ROI.  Here is the code:

 Roi roi_1=imp.getRoi();
 PolygonRoi pr = (PolygonRoi)roi_1;
 int[] xarr = pr.getXCoordinates();
 int[] yarr = pr.getYCoordinates();

I found that the xarr and yarr cooridateds read by the code are
shifted compared with the initial ROI, although the shape is the same.  The
initial ROI is in the center of the image window.  However, the code reading
ROI shifted to the top left corner of the image window.  Anyone knows the
possible reason of this shift?  What is the right way to read the Roi
coordinates?

Thanks a lot,
Jiajian
Reply | Threaded
Open this post in threaded view
|

Re: A problem of ROI coordiantes shifting by using getXCoordinates

Wayne Rasband
> I am writing a pluginfilter, which needs get PolygonRoi coordinates
> from a selected ROI.  Here is the code:
>
>  Roi roi_1=imp.getRoi();
>  PolygonRoi pr = (PolygonRoi)roi_1;
>  int[] xarr = pr.getXCoordinates();
>  int[] yarr = pr.getYCoordinates();
>
> I found that the xarr and yarr cooridateds read by the code are
> shifted compared with the initial ROI, although the shape is the
> same.  The initial ROI is in the center of the image window.
> However, the code reading ROI shifted to the top left corner of the
> image window.  Anyone knows the possible reason of this shift?
> What is the right way to read the Ro coordinates?

The coordinates returned by getXCoordinates() and getYCoordinates()  
are relative to the base of the bounding rectangle, which you can get  
by calling roi.getBounds(x,y,width,height). The easy way to get  
absolute coordinates is to use

     Polygon p = roi.getPolygon();
     int[] xarr = p.xpoints;
     int[] yarr = p.ypoints;

-wayne