Multiple ROI Plugin Issues

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

Multiple ROI Plugin Issues

David S
Hey,

I'm trying to make a plugin that will export the coordinates of ROIs to a text file for further analysis in Mathematica. There's no issue deakling with one ROI. Things seem to go wrong when I try multiple (>1) ROIs. The group of ROIs becomes an array of ROIs. However, array[0].contains(x,y) returns false for all coordinates. Keep in mind that I primarily use Mathematica, so my Java programming is quite crude. I'm also not ruling out that I'm just overlooking a simple mistake. Here's the code:

  public int[][] saveXYCoordinates(ImagePlus imp) {
        Roi roi = imp.getRoi();
        int count = 0;
        if (roi==null)
            throw new IllegalArgumentException("ROI required");
        int i, j, height, width;
        height= imp.getHeight();
        width= imp.getWidth();
        int[][] output = new int[height*width][2];
         if (roi instanceof ShapeRoi)   {
       ShapeRoi p = (ShapeRoi)roi;
       Roi[] rois = p.getRois();
        IJ.log(Integer.toString(rois.length)); // returns the correct number of ROIs
         if ((rois[0] instanceof PolygonRoi))
        IJ.log("It's a polygon");                  // Prints this
       if (rois[0]!=null)
        IJ.log("It's not null");                    // This is also printed
        PolygonRoi pr = (PolygonRoi)rois[0];
        Rectangle r = pr.getBounds();        // This part is done so that I don't scan through the whole image
      int xbase = r.x;
     int ybase = r.y;
        int xtop = r.width + xbase;
        int ytop = r.height + ybase;           // All these integers seem correct
       IJ.log(Double.toString(rois[0].getLength()) ); // Both have perimeter > 0
       IJ.log(Double.toString(rois[1].getLength()) );
       for(i=xbase;i<=xtop;i++){
      for(j=ybase;j<=ytop;j++){
       if(pr.contains(i,j)){
       IJ.log("HERE");                             // Never prints this
       output[count][0] = i;
       output[count][1] = j;
       count++;
                                 }
                                                       }
       return shorten(output,count);}
                                                          }

I apreciate any help.

Thanks,
David