Login  Register

Re: reading .roi files (outside ImageJ)

Posted by Kenneth Sloan-2 on Jan 29, 2019; 2:12pm
URL: http://imagej.273.s1.nabble.com/reading-roi-files-outside-ImageJ-tp5021725p5021729.html

Thanks, very much - this is EXACTLY what I need!

I will use it...and will study the details.


--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.





> On Jan 29, 2019, at 07:27, Christophe Leterrier <[hidden email]> wrote:
>
> Dear Kenneth,
>
> The macro below should do what you want - it opens all rois inside a folder and exports the x,y coordinates as a .csv file (on line per x,y point). I there is a problem with formatting you can find the macro here also: http://neurocytolab.org/up/ExportRoi.ijm <http://neurocytolab.org/up/ExportRoi.ijm>
>
> macro "ExportROI" {
> inputdir = getDirectory("Choose a directory containing .roi files");
> filelist = getFileList(inputdir);
>
> for (i = 0; i < filelist.length; i++) {
> currfile = filelist[i];
> l = lengthOf(currfile);
> shortname = substring(currfile, 0, l-4);
> ext = substring(currfile, l-4, l);
> if (ext == ".roi") {
> open(inputdir + currfile);
> getSelectionCoordinates(xpoints, ypoints);
> string = "";
> for (j = 0; j < xpoints.length; j++) {
> string = string + "" + xpoints[j] + "," + ypoints[j] + "\n";
> }
> outname = shortname + ".csv";
> File.saveString(string,inputdir + outname);
> close();
> }
> }
> }
>
>
> Christophe
>
>
>
> On Mon, 28 Jan 2019 at 23:06, Kenneth Sloan <[hidden email] <mailto:[hidden email]>> wrote:
> I'm collaborating on a project.  My collaborator has created many, many .roi files (each one containing a single PolygonRoi).
> I can drag&drop the .roi file on FIJI, and use File->Save As->XY Coordinates to get a .txt file that I can read in a non-ImageJ
> Java program.
>
> But, this will be tedious.  Is there a simple way to automate this?
>
> a) first choice: is there a description of the .roi file format?  Given sufficient documentation, I'm comfortable
> writing code to read the .roi file directly
> b) second choid: a SIMPLE macro that will read all of the .roi files in a directory and create .txt files containing the XY coordinates.
>
> I'm a skilled Java progammer - but very much a novice at ImageJ macros.  I expect that my major stumbling block would be
> writing a macro to read in all of the .roi files, one at a time.  I think I could save to .txt files just fine, once
> I have the .roi file read in.  [ I know this is trivial for many of you - have pity on me. ]
>
> For scale - I anticipate approximately 60 .roi files.  Not out of the question to simply do one at a time, by hand - but
> (if it's simple) I'd rather let a macro do the iteration.
>
> --
> Kenneth Sloan
> [hidden email] <mailto:[hidden email]>
> Vision is the art of seeing what is invisible to others.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html <http://imagej.nih.gov/ij/list.html>


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