Login  Register

Re: In a stack, how can I make a different polygon in each slice and 'Save As' their XYZ coordinates?

Posted by Rasband, Wayne (NIH/NIMH) [E] on Apr 06, 2014; 6:09pm
URL: http://imagej.273.s1.nabble.com/In-a-stack-how-can-I-make-a-different-polygon-in-each-slice-and-Save-As-their-XYZ-coordinates-tp5007218p5007224.html

On Apr 6, 2014, at 1:10 PM, imageJnoob wrote:

> Thanks Wayne but I don't think this is what I'm looking for.
>
> I need a tool that allows me to make a polygon dedicated to the slice it is
> drawn in.

That is what typing "b" (Image>Overlay>Add Selection) does. It creates a polygon that is dedicated to the slice it is drawn in and adds it to the overlay.

> Then when I go to the next slice, the first one disappears
> allowing me to make a new polygon.

You can create a new polygon by clicking outside the existing one. Polygons added to the overlay by pressing "b" will not disappear.

> When all the polygons are drawn, I can
> return a table where each row is an x y z coordinate, where z is the slice
> number, like the following:
>
> 60.9440 45.4150 1
> 68.2690 43.9500 1
> 75.8870 46.8800 1
> 83.5050 50.6890 1
> 90.8300 56.5490 2
> 92.8810 61.5300 2
> 93.1740 76.4730 2
> 90.2440 80.5750 2
> 87.6070 84.3840 2
> 82.0400 87.9000 3
> 74.7150 90.8300 3

You can get a table like this from the overlay using a simple macro:

  print("\\Clear");
  for (i=0; i<Overlay.size; i++) {
    Overlay.activateSelection(i);
    getSelectionCoordinates(x, y);
    slice = getSliceNumber();
    for (j=0; j<x.length; j++)
       print(x[j]+", "+y[j]+", "+slice);
  }

Or using a simple JavaScript:

  print("\\Clear");
  imp = IJ.getImage();
  overlay = imp.getOverlay();
  for (i=0; i<overlay.size(); i++) {
    roi = overlay.get(i);
    p = roi.getFloatPolygon();
    for (j=0; j<p.npoints; j++) {
       slice = roi.getPosition();
       print(p.xpoints[j]+", "+p.ypoints[j]+", "+slice);
    }
  }

> My goal is to use these coordinates to draw out the same polygons in another
> program. The row of z-1s trace out a polygon only for the first slice, row
> of z-2s trace out a polygon for the second slice, and so on.
>
> So far I have to make a polygon, 'save as' xy coordinates, and save the txt
> file with the slice number in the name. I'm doing this for every slice,
> which is very tedious. If I have to save each slice as a .TIFF it would be
> equally as time-consuming, as my stacks are DICOM.

You do not have to save each slice as a TIFF. The overlay containing all the polygons is saved when you save the stack in TIFF format.

> Unfortunately my ImageJ
> doesn't have "List Elements" in Image/Overlay. I did make multiple polygons
> with the "Add Selection" function but its not slice specific.

You need to use the Help>Update ImageJ command to update to the current version of ImageJ (1.48t). Make sure that "Set stack positions" is enabled in Image>Overlay>Overlay Options.

-wayne

> Thanks very much for your suggestion Wayne! My offer to pay anyone to code
> the above function for me still stands!
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/In-a-stack-how-can-I-make-a-different-polygon-in-each-slice-and-Save-As-their-XYZ-coordinates-tp5007218p5007223.html
> Sent from the ImageJ mailing list archive at Nabble.com.

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