Login  Register

Re: Add ROIs from a list of coordinates in a .CSV file

Posted by Rasband, Wayne (NIH/NIMH) [E] on Aug 26, 2014; 3:11am
URL: http://imagej.273.s1.nabble.com/Add-ROIs-from-a-list-of-coordinates-in-a-CSV-file-tp5009300p5009341.html

On Aug 21, 2014, at 11:49 PM, joshuamarcus wrote:

> Hello!
>
> I am new to writing imageJ macros and could use a little help:
>
> I was able to track nuclei of a field of cells from a time-laps experiment
> using the ImageJ plugin TrackMate. I then converted the .xml file generated
> by the plugin to a .csv file of coordinates. The file lists frame, x
> coordinates, and y coordinates. I would like to write a macro that first
> imports the list of coordinates, then defines ROIs of a specified shape and
> size, with the pixel coordinate representing the center of each ROI, and add
> all of these to the ROI manager. I could then save and manipulate these ROIs
> as I choose.

Consider using an overlay instead of the ROI Manager. An overlay is basically an ROI Manager without the GUI. The following example opens a .csv file with "f", "x" and "y" columns as a Results table, creates circular ROIs based on "x" and "y" and adds them to the overlay using "f" as the ROI stack position. If needed, the overlay can be transferred to the ROI Manager using the Image>Overlay>To ROI Manager command.

  open("/path/to/test.csv");
  for (i=0; i<nResults; i++) {
     frame = getResult("f", i);
     x = getResult("x", i);
     y = getResult("y", i);
     makeOval(x-5, y-5, 10, 10);
     Overlay.addSelection;
     Overlay.setPosition(frame);
  }

The .csv file should look something like this:

   f,x,y
   1,299,240
   1,275,426
   1,306,416
   2,388,165
   2,488,155
   3,24,254

-wayne


> --
> View this message in context: http://imagej.1557.x6.nabble.com/Add-ROIs-from-a-list-of-coordinates-in-a-CSV-file-tp5009300.html
> Sent from the ImageJ mailing list archive at Nabble.com.

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