reading .roi files (outside ImageJ)

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

reading .roi files (outside ImageJ)

Kenneth Sloan-2
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]
Vision is the art of seeing what is invisible to others.

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

Re: reading .roi files (outside ImageJ)

Niko Ehrenfeuchter
Hi Kenneth,

if Python is an option for you, here's some code to read ImageJ ROIs, both single file as well as multi ROI zip files:

https://github.com/hadim/read-roi

Cheers
Niko

Am 28.01.2019 11:06 nachm. schrieb Kenneth Sloan <[hidden email]>:
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]
Vision is the art of seeing what is invisible to others.

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

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

Re: reading .roi files (outside ImageJ)

Kenneth Sloan-2
That's a possibility - but even better was the link that led me to the ImageJ code with documentation
on the format.

For now, I'm using Fiji to convert from .roi to .txt.  When that becomes tedious, I'll use the documentation to write my own reader in Java.  This is a one-time deal, and my ROIs are very restricted, so it now looks easy.

Thanks very much for providing a useful link!
--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.





> On Jan 28, 2019, at 16:27, Nikolaus Ehrenfeuchter <[hidden email]> wrote:
>
> Hi Kenneth,
>
> if Python is an option for you, here's some code to read ImageJ ROIs, both single file as well as multi ROI zip files:
>
> https://github.com/hadim/read-roi
>
> Cheers
> Niko

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

Re: reading .roi files (outside ImageJ)

lechristophe
In reply to this post by Kenneth Sloan-2
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

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]> 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]
> Vision is the art of seeing what is invisible to others.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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

Re: reading .roi files (outside ImageJ)

Kenneth Sloan-2
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
Reply | Threaded
Open this post in threaded view
|

Re: reading .roi files (outside ImageJ)

bmacgreg
In reply to this post by lechristophe
Hi,

Belated thanks here too! Tweaked it a little to get all the pixels rather
than the outlines (Roi.getContainedPoints(xpoints, ypoints)) and it does
just what I want.

Barbara



--
Sent from: http://imagej.1557.x6.nabble.com/

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