ROI structure

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ROI structure

Ewing James
Dear List:

I’m writing some C code to read out the points in an ImageJ-defined ROI. I’m having trouble reading the list of x,y coordinates in a freehand ROI, which I believe should be short integers (16 bits).  Is there a description of the header and points format for an ImageJ ROI somewhere?  I have an old header description, which seems to work, but I’m not reading the list of x, y coordinates correctly.


  *   Jim Ewing


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ROI structure

Wayne Rasband-2
> On Sep 18, 2019, at 10:35 PM, James Ewing <[hidden email]> wrote:
>
> Dear List:
>
> I’m writing some C code to read out the points in an ImageJ-defined ROI. I’m having trouble reading the list of x,y coordinates in a freehand ROI, which I believe should be short integers (16 bits).  Is there a description of the header and points format for an ImageJ ROI somewhere?  I have an old header description, which seems to work, but I’m not reading the list of x, y coordinates correctly.

The .roi file format is described at the beginning of RoiDecoder.java:

    https://imagej.nih.gov/ij/source/ij/io/RoiDecoder.java

-wayne
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ROI structure

Wayne Rasband-2
In reply to this post by Ewing James
> On Sep 18, 2019, at 10:35 PM, James Ewing <[hidden email]> wrote:
>
> Dear List:
>
> I’m writing some C code to read out the points in an ImageJ-defined ROI. I’m having trouble reading the list of x,y coordinates in a freehand ROI, which I believe should be short integers (16 bits).  Is there a description of the header and points format for an ImageJ ROI somewhere?  I have an old header description, which seems to work, but I’m not reading the list of x, y coordinates correctly.

The following JavaScript code decodes and displays an .roi file containing a freehand ROI. The constants (TOP, LEFT, etc.) are from https://imagej.nih.gov/ij/source/ij/io/RoiDecoder.java. This example requires the latest daily build (1.52r5), which adds the IJ.openAsByteBuffer() method.

-wayne

  TOP = 8;
  LEFT = 10;
  N_COORDINATES = 16;
  COORDINATES = 64;
  bb = IJ.openAsByteBuffer("");
  if (bb.getInt(0)!=1232041332)
     IJ.error("This is not an ImageJ ROI");
  xbase = bb.getShort(LEFT);
  ybase = bb.getShort(TOP);
  n = bb.getShort(N_COORDINATES);
  polygon= new Polygon();
  for (i=0; i<n; i++) {
     x = xbase+bb.getShort(COORDINATES+i*2);
     y = ybase+bb.getShort(COORDINATES+2*n+i*2);
     polygon.addPoint(x,y);
  }
  roi = new PolygonRoi(polygon, Roi.FREEROI);
  img = IJ.createImage("tmp","8-bit black",500,500,1);
  img.setRoi(roi);
  img.show();

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html