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

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

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

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

If someone could at least point me in the right direction I would be forever grateful!

Best regards,
Joshua
Reply | Threaded
Open this post in threaded view
|

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

Pariksheet Nanda
Hi Joshua,

On Thu, Aug 21, 2014 at 11:49 PM, joshuamarcus
<[hidden email]> wrote:
>
> a .csv file of coordinates [...] lists frame, x
> coordinates, and y coordinates. I would like to write a macro that first
> imports the list of coordinates,

   // Import it into a results table.
   run("Results... ", "open=/path/to/coordinates.csv");


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

   for (i = 0; i < nResults; i++)
   {
      // You may need to change the "frame", etc strings to match your csv file.
      slice = getResult("frame", i);
      x = getResult("x", i);
      y = getResult("y", i);

      // Using square ROI of size 10x10 pixels centered around your coordinate.
      run("Specify...", "width=10 height=10 x=&x y=&y slice=&slice centered");

      // Add to the ROI manager.
      roiManager("Add");
   }


> Joshua

Pariksheet

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

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

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by joshuamarcus
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