> 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