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

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

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

imageJnoob
Hi, I am very new to ImageJ here. I am hoping that someone here can point me to a polygon/contouring tool that I have been unable to find from searching. I apologize if I missed it.

My project is centered around mapping out anatomy from CT and MRI scans. I am working with stacks of DICOM images of Knee MRI's, Chest CT's, etc. I need to be able to outline and save the X-Y-Z coordinates of each bone, muscle, artery, vein and nerve in each stack.

The native polygon tool draws out the same polygon for every slice of the stack. This of course doesn't work for me because the shape of each anatomic part changes throughout the stack. I need to be able to draw a separate polygon for each slice as I trace out a femur, for example, then 'Save As' their X-Y-Z coordinates with the Z coordinate representing the slice number. It is much too tedious with the native polygon tool to 'Save As' XY coordinates for every slice.

Can someone please help? If this tool does not exist, I am willing to pay a generous expert for his/her time to write me a plug-in.

Thanks very much!
Reply | Threaded
Open this post in threaded view
|

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

Rasband, Wayne (NIH/NIMH) [E]
On Apr 5, 2014, at 6:16 PM, imageJnoob wrote:

> Hi, I am very new to ImageJ here. I am hoping that someone here can point me
> to a polygon/contouring tool that I have been unable to find from searching.
> I apologize if I missed it.
>
> My project is centered around mapping out anatomy from CT and MRI scans. I
> am working with stacks of DICOM images of Knee MRI's, Chest CT's, etc. I
> need to be able to outline and save the X-Y-Z coordinates of each bone,
> muscle, artery, vein and nerve in each stack.
>
> The native polygon tool draws out the same polygon for every slice of the
> stack. This of course doesn't work for me because the shape of each anatomic
> part changes throughout the stack. I need to be able to draw a separate
> polygon for each slice as I trace out a femur, for example, then 'Save As'
> their X-Y-Z coordinates with the Z coordinate representing the slice number.
> It is much too tedious with the native polygon tool to 'Save As' XY
> coordinates for every slice.

After drawing a polygon, save it in the overlay by pressing "b" (Image>Overlay>Add Selection). All polygons in the overlay will be saved when the image is saved in TIFF format. Activate a polygon in the overlay by long clicking on it. Remove a polygon from the overlay by activating it and pressing the delete key. Use the Image>Overlay>List Elements command to get a list of polygons in the overlay. The "Pos" column in the list shows the slice associated with each polygon.

-wayne


> Can someone please help? If this tool does not exist, I am willing to pay a
> generous expert for his/her time to write me a plug-in.
>
> Thanks very much!
>
>
>
> --
> 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-tp5007218.html
> Sent from the ImageJ mailing list archive at Nabble.com.

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

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

imageJnoob
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. Then when I go to the next slice, the first one disappears allowing me to make a new polygon. 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
94.3460 67.3900 2
94.6390 73.5430 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
67.9760 92.0020 3
57.1350 90.8300 3
47.7590 71.7850 3
46.2940 60.3580 3
51.5680 49.8100 3
56.8420 46.5870 3

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. 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.


Thanks very much for your suggestion Wayne! My offer to pay anyone to code the above function for me still stands!
Reply | Threaded
Open this post in threaded view
|

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

Rasband, Wayne (NIH/NIMH) [E]
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
Reply | Threaded
Open this post in threaded view
|

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

imageJnoob
Wayne, it worked like a charm! Thanks a lot! All I needed was an upgrade :)