I have many (polygon) ROIs stored as .roi files.
How can I print the coordinates of the vertices of the ROI? -- 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 |
Greeting Kenneth,
Analyze>Tools>ROI Manager::More>>open... ::Properties::List Coordinates then OK Note: On a Oval ROI the listed coordinates are an interpolated version of the displayed vertices. FloatPolygon fp = Roi.getFloatPolygon(); If you want to read the actual .roi file and list the contents, there are MATLAB scripts out there that do this, i.e., easy to read. ::More>>::List This answers one of my previous bonus questions, i.e., GUI display of bounding box in voxel/pixel coordinates. Fred Produces the definition of the On Tue, March 2, 2021 4:04 pm, Kenneth Sloan wrote: > I have many (polygon) ROIs stored as .roi files. > > How can I print the coordinates of the vertices of the ROI? > > -- > 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 |
Thank you for the reply.
Answering my own question - I eventually found a demonstration macro, from which I extracted this: ================ Roi.getCoordinates(x,y); print("ROI coordinates"); for (i=0;i<x.length; i++) print(i,x[i],y[i]); ================ I would have preferred a stand-alone (preferably Java) program to read the .roi file and print the coordinates, but for my current purposes it was acceptable to drag&drop the .roi files onto a running FIJI and then run the above macro. I only had 10 files to process, so doing this manually was acceptable. Actually, I was trying to montage several data files, where the raw data consisted of: a) a .csv file giving coordinates for points to be plotted b) an .roi file giving the location and boundary of the sampled area Where the points in a) were expressed in local coordinate systems, relative to the top, left corner of the Roi. Alas, I had no control over the data collection. I would have preferred to write a stand-along Java program to read a collection of these raw data file pairs, but could not find information on the file format for an .roi file. Is there documentation on the format of an .roi file? -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. > On Mar 2, 2021, at 22:52, Fred Damen <[hidden email]> wrote: > > Greeting Kenneth, > > Analyze>Tools>ROI Manager::More>>open... > ::Properties::List Coordinates then OK > Note: On a Oval ROI the listed coordinates are an interpolated version of > the displayed vertices. > FloatPolygon fp = Roi.getFloatPolygon(); > If you want to read the actual .roi file and list the contents, there are > MATLAB scripts out there that do this, i.e., easy to read. > > ::More>>::List > This answers one of my previous bonus questions, i.e., GUI display of > bounding box in voxel/pixel coordinates. > > Fred > > Produces the definition of the > On Tue, March 2, 2021 4:04 pm, Kenneth Sloan wrote: >> I have many (polygon) ROIs stored as .roi files. >> >> How can I print the coordinates of the vertices of the ROI? >> >> -- >> 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 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Kenneth,
the format of a .roi file is rather complex. I suspect that the RoiDecoder [1] and RoiEncoder sources are the only documentation of the .roi file format. You should better examine the RoiDecoder, which also reads .roi files created by previous versions of ImageJ, while the RoiEncoder only tells you the format of .roi files written by the current version of ImageJ. You can modify the ImageJ RoiDecoder class [1] to read a .roi file, but it will a bit of work to get a stand-alone version. The RoiDecoder class obviously refers to the Roi class (and its subclasses) in many places, and with all the dependencies you would essentially need all of ImageJ. So you will need quite a few modifications. By the way, if this helps, you can also zip a collection of .roi files and drag&drop it onto ImageJ, you will then get them in the Roi Manager. Then do with the Rois in the RoiManager whatever you like. [1] https://github.com/imagej/imagej1/blob/master/ij/io/RoiDecoder.java Michael ________________________________________________________________ On 03.03.21 18:02, Kenneth Sloan wrote: > Thank you for the reply. > > Answering my own question - I eventually found a demonstration macro, from which I extracted this: > > ================ > Roi.getCoordinates(x,y); > print("ROI coordinates"); > for (i=0;i<x.length; i++) > print(i,x[i],y[i]); > ================ > > I would have preferred a stand-alone (preferably Java) program to read the .roi file and print the coordinates, but for my current purposes it was acceptable to drag&drop the .roi files onto a running FIJI and then run the above macro. I only had 10 files to process, so doing this manually was acceptable. > > Actually, I was trying to montage several data files, where the raw data consisted of: > > a) a .csv file giving coordinates for points to be plotted > b) an .roi file giving the location and boundary of the sampled area > > Where the points in a) were expressed in local coordinate systems, relative to the top, left corner of the Roi. > > Alas, I had no control over the data collection. > > I would have preferred to write a stand-along Java program to read a collection of these raw data file pairs, but could not find information on the file format for an .roi file. > > Is there documentation on the format of an .roi file? > > -- > Kenneth Sloan > [hidden email] > Vision is the art of seeing what is invisible to others. > > > > > >> On Mar 2, 2021, at 22:52, Fred Damen <[hidden email]> wrote: >> >> Greeting Kenneth, >> >> Analyze>Tools>ROI Manager::More>>open... >> ::Properties::List Coordinates then OK >> Note: On a Oval ROI the listed coordinates are an interpolated version of >> the displayed vertices. >> FloatPolygon fp = Roi.getFloatPolygon(); >> If you want to read the actual .roi file and list the contents, there are >> MATLAB scripts out there that do this, i.e., easy to read. >> >> ::More>>::List >> This answers one of my previous bonus questions, i.e., GUI display of >> bounding box in voxel/pixel coordinates. >> >> Fred >> >> Produces the definition of the >> On Tue, March 2, 2021 4:04 pm, Kenneth Sloan wrote: >>> I have many (polygon) ROIs stored as .roi files. >>> >>> How can I print the coordinates of the vertices of the ROI? >>> >>> -- >>> 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 > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks for the information.
I'll add this to my queue, but it's a very long queue, and my current crisis has passed. All of *my* data collection plugins write out .roi information in .csv files. Alas, I didn't have any control over the data collection in this project. I now have it down to a couple of mouse-clicks and a cut-and-paste to turn the .roi files into clear-text polygons. That will have to do, for now. -- 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 |
Hello Kenneth,
I just save my data as a text image. It can then be loaded into Excel, or any other spreadsheet just as it is. Just saying. Bob Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10 From: Kenneth Sloan<mailto:[hidden email]> Sent: Wednesday, March 3, 2021 4:29 PM To: [hidden email]<mailto:[hidden email]> Subject: Re: print Roi? Thanks for the information. I'll add this to my queue, but it's a very long queue, and my current crisis has passed. All of *my* data collection plugins write out .roi information in .csv files. Alas, I didn't have any control over the data collection in this project. I now have it down to a couple of mouse-clicks and a cut-and-paste to turn the .roi files into clear-text polygons. That will have to do, for now. -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. -- ImageJ mailing list: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7C%7C2b30c70e63a94a1eebe608d8de8b71c4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637504037774141197%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=IX%2B4n%2BWps%2FIK%2Bc9Vh2E4Ij4TMn7q37Wp%2Bw88naUuHuA%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Kenneth Sloan-2
What about implementing this as a hybrid script?
If you are on Windows, the below code should do. Save the text between the two long lines as MyMacro.cmd, put it in the ImageJ folder, and drop your ROI file onto it. The trick is that ImageJ treats the script file as a macro, and Windows treats it as a command ("batch") file. All you need is to point it to a minimal Java runtime and the ij.jar file, or have these in the same folder as the script. ----------------------------------------------------------------------------------------------------------------------- rem = "Hybrid script with Windows commands and ImageJ macro in the same file"; /* ::To use, place this file wherever desired and drop whatever desired onto it ::The ImageJ macro below will be executed using the dropped filenames, filepaths or parameters as input arguments ::ImageJ will consider the Windows part as a comment ::Windows will skip the ImageJ parts ::----- start of Windows command script ----- @echo off cls ::set MacroFile to this file set MacroFile=%~f0 set MacroFile=%MacroFile:\=/% ::set Parameters to dropped file set Parameters=%~1 set Parameters=%Parameters:\=/% ::create a Java command line set Command=jre\bin\java -jar -Xmx1024m ij.jar -eval "runMacro('%MacroFile%', '%Parameters%');" -batch ::execute it %Command% ::wait for user response before closing pause goto :EOF ::----- end of Windows command script ----- */ //----- start of ImageJ macro script ----- strArgument=getArgument(); print("Arguments:\t" + strArgument); open(strArgument); Roi.getCoordinates(x,y); print('ROI coordinates'); for (i=0;i<x.length; i++) print(i,x[i],y[i]);" //----- end of ImageJ macro script ----- ----------------------------------------------------------------------------------------------------------------------- -----Original Message----- Sent: 3. mars 2021 18:02 Subject: Re: print Roi? Thank you for the reply. Answering my own question - I eventually found a demonstration macro, from which I extracted this: ================ Roi.getCoordinates(x,y); print("ROI coordinates"); for (i=0;i<x.length; i++) print(i,x[i],y[i]); ================ I would have preferred a stand-alone (preferably Java) program to read the .roi file and print the coordinates, but for my current purposes it was acceptable to drag&drop the .roi files onto a running FIJI and then run the above macro. I only had 10 files to process, so doing this manually was acceptable. Actually, I was trying to montage several data files, where the raw data consisted of: a) a .csv file giving coordinates for points to be plotted b) an .roi file giving the location and boundary of the sampled area Where the points in a) were expressed in local coordinate systems, relative to the top, left corner of the Roi. Alas, I had no control over the data collection. I would have preferred to write a stand-along Java program to read a collection of these raw data file pairs, but could not find information on the file format for an .roi file. Is there documentation on the format of an .roi file? -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. > On Mar 2, 2021, at 22:52, Fred Damen <[hidden email]> wrote: > > Greeting Kenneth, > > Analyze>Tools>ROI Manager::More>>open... > ::Properties::List Coordinates then OK > Note: On a Oval ROI the listed coordinates are an interpolated version > of the displayed vertices. > FloatPolygon fp = Roi.getFloatPolygon(); If you want to read the > actual .roi file and list the contents, there are MATLAB scripts out > there that do this, i.e., easy to read. > > ::More>>::List > This answers one of my previous bonus questions, i.e., GUI display of > bounding box in voxel/pixel coordinates. > > Fred > > Produces the definition of the > On Tue, March 2, 2021 4:04 pm, Kenneth Sloan wrote: >> I have many (polygon) ROIs stored as .roi files. >> >> How can I print the coordinates of the vertices of the ROI? >> >> -- >> Kenneth Sloan >> [hidden email] >> Vision is the art of seeing what is invisible to others. >> >> -- >> ImageJ mailing list: >> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimag >> ej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef. >> no%7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b3 >> 2af%7C1%7C0%7C637503878617041326%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4w >> LjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sda >> ta=4SWvYMBBCcGFYje7buK4gpjce7DlYgZLr8DEQGfsxdY%3D&reserved=0 >> > > -- > ImageJ mailing list: > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage > j.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no > %7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b32af > %7C1%7C0%7C637503878617041326%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw > MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=4S > WvYMBBCcGFYje7buK4gpjce7DlYgZLr8DEQGfsxdY%3D&reserved=0 -- ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no%7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637503878617046305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=991OKTEw7fcxXRVsTcc%2BKoNSZFTtGt%2B8fiympsDh1fU%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
I wrote a Java plugin to convert a (polygon) ROI to a 2-column x,y .csv file.
My situation is slightly complicated by the fact that I try to make these things work in Locales where ',' is not acceptable as a field separator (like, say, GERMAN). I also prefer Java, where I'm more comfortable. Also...(applicable only to the latest suggestion) I live on Macs, so Windows scripts are twice removed from my comfort zone. It's still a little clunky, and a bit long to post - but I'd be happy to share. I might even put it up on my ImageJ Update site. If it arises, I might be tempted to generalize this to more than simple PolygonRoi - but only if I actually need it! Today, I'm busy writing the code that needed the ROIs in Java-readable format in the first place. And...adding a bullet to my pre-data-collection consultation checklist: do not save essential data in proprietary, undocumented file formats! -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. > On Mar 4, 2021, at 15:08, Stein Rørvik <[hidden email]> wrote: > > What about implementing this as a hybrid script? > > If you are on Windows, the below code should do. > Save the text between the two long lines as MyMacro.cmd, put it in the ImageJ folder, and drop your ROI file onto it. > > The trick is that ImageJ treats the script file as a macro, and Windows treats it as a command ("batch") file. > All you need is to point it to a minimal Java runtime and the ij.jar file, or have these in the same folder as the script. > > ----------------------------------------------------------------------------------------------------------------------- > rem = "Hybrid script with Windows commands and ImageJ macro in the same file"; /* > ::To use, place this file wherever desired and drop whatever desired onto it > ::The ImageJ macro below will be executed using the dropped filenames, filepaths or parameters as input arguments > ::ImageJ will consider the Windows part as a comment > ::Windows will skip the ImageJ parts > > ::----- start of Windows command script ----- > @echo off > cls > > ::set MacroFile to this file > set MacroFile=%~f0 > set MacroFile=%MacroFile:\=/% > ::set Parameters to dropped file > set Parameters=%~1 > set Parameters=%Parameters:\=/% > ::create a Java command line > set Command=jre\bin\java -jar -Xmx1024m ij.jar -eval "runMacro('%MacroFile%', '%Parameters%');" -batch > ::execute it > %Command% > ::wait for user response before closing > pause > goto :EOF > ::----- end of Windows command script ----- > */ > > //----- start of ImageJ macro script ----- > > strArgument=getArgument(); > print("Arguments:\t" + strArgument); > open(strArgument); > Roi.getCoordinates(x,y); > print('ROI coordinates'); > for (i=0;i<x.length; i++) > print(i,x[i],y[i]);" > > //----- end of ImageJ macro script ----- > ----------------------------------------------------------------------------------------------------------------------- > > -----Original Message----- > Sent: 3. mars 2021 18:02 > Subject: Re: print Roi? > > Thank you for the reply. > > Answering my own question - I eventually found a demonstration macro, from which I extracted this: > > ================ > Roi.getCoordinates(x,y); > print("ROI coordinates"); > for (i=0;i<x.length; i++) > print(i,x[i],y[i]); > ================ > > I would have preferred a stand-alone (preferably Java) program to read the .roi file and print the coordinates, but for my current purposes it was acceptable to drag&drop the .roi files onto a running FIJI and then run the above macro. I only had 10 files to process, so doing this manually was acceptable. > > Actually, I was trying to montage several data files, where the raw data consisted of: > > a) a .csv file giving coordinates for points to be plotted > b) an .roi file giving the location and boundary of the sampled area > > Where the points in a) were expressed in local coordinate systems, relative to the top, left corner of the Roi. > > Alas, I had no control over the data collection. > > I would have preferred to write a stand-along Java program to read a collection of these raw data file pairs, but could not find information on the file format for an .roi file. > > Is there documentation on the format of an .roi file? > > -- > Kenneth Sloan > [hidden email] > Vision is the art of seeing what is invisible to others. > > > > > >> On Mar 2, 2021, at 22:52, Fred Damen <[hidden email]> wrote: >> >> Greeting Kenneth, >> >> Analyze>Tools>ROI Manager::More>>open... >> ::Properties::List Coordinates then OK >> Note: On a Oval ROI the listed coordinates are an interpolated version >> of the displayed vertices. >> FloatPolygon fp = Roi.getFloatPolygon(); If you want to read the >> actual .roi file and list the contents, there are MATLAB scripts out >> there that do this, i.e., easy to read. >> >> ::More>>::List >> This answers one of my previous bonus questions, i.e., GUI display of >> bounding box in voxel/pixel coordinates. >> >> Fred >> >> Produces the definition of the >> On Tue, March 2, 2021 4:04 pm, Kenneth Sloan wrote: >>> I have many (polygon) ROIs stored as .roi files. >>> >>> How can I print the coordinates of the vertices of the ROI? >>> >>> -- >>> Kenneth Sloan >>> [hidden email] >>> Vision is the art of seeing what is invisible to others. >>> >>> -- >>> ImageJ mailing list: >>> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimag <https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimag> >>> ej.nih.gov <http://ej.nih.gov/>%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef. >>> no%7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b3 >>> 2af%7C1%7C0%7C637503878617041326%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4w >>> LjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sda >>> ta=4SWvYMBBCcGFYje7buK4gpjce7DlYgZLr8DEQGfsxdY%3D&reserved=0 >>> >> >> -- >> ImageJ mailing list: >> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage <https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage> >> j.nih.gov <http://j.nih.gov/>%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no <http://40sintef.no/> >> %7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b32af >> %7C1%7C0%7C637503878617041326%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw >> MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=4S >> WvYMBBCcGFYje7buK4gpjce7DlYgZLr8DEQGfsxdY%3D&reserved=0 > > -- > ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no%7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637503878617046305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=991OKTEw7fcxXRVsTcc%2BKoNSZFTtGt%2B8fiympsDh1fU%3D&reserved=0 <https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no%7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637503878617046305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=991OKTEw7fcxXRVsTcc%2BKoNSZFTtGt%2B8fiympsDh1fU%3D&reserved=0> > > -- > 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 |
Kenneth, I am glad to hear you already found a solution.
A few additional thoughts: Regarding separator, I always use tabulator between cells. Then programs like Excel do not try to interpret the comma as a decimal separator, like in Norway where I live. Regarding documentation of the ROI format, the source code of ImageJ https://imagej.nih.gov/ij/developer/source/ij/io/RoiDecoder.java.html describes the binary format in this comment at the top of the file. But I agree it would have made things simpler if it was an ASCII based format. I guess this is an inheritance from NIH image, to make it compatible with ROIs from this. I also guess the example code at http://wsr.imagej.net/macros/js/DecodeRoiFile.js could be adapted into something that does not require ImageJ. /** This class decodes an ImageJ .roi file. <p> Format of the original 64 byte ImageJ/NIH Image .roi file header. Two byte numbers are big-endian signed shorts. The JavaScript example at http://wsr.imagej.net/macros/js/DecodeRoiFile.js demonstrates how to use this information to decode a .roi file. <pre> 0-3 "Iout" 4-5 version (>=217) 6-7 roi type (encoded as one byte) 8-9 top 10-11 left 12-13 bottom 14-15 right 16-17 NCoordinates 18-33 x1,y1,x2,y2 (straight line) | x,y,width,height (double rect) | size (npoints) 34-35 stroke width (v1.43i or later) 36-39 ShapeRoi size (type must be 1 if this value>0) 40-43 stroke color (v1.43i or later) 44-47 fill color (v1.43i or later) 48-49 subtype (v1.43k or later) 50-51 options (v1.43k or later) 52-52 arrow style or aspect ratio (v1.43p or later) 53-53 arrow head size (v1.43p or later) 54-55 rounded rect arc size (v1.43p or later) 56-59 position 60-63 header2 offset 64- x-coordinates (short), followed by y-coordinates <pre> @see <a href="http://wsr.imagej.net/macros/js/DecodeRoiFile.js">DecodeRoiFile.js</a> */ In case this helps. Stein -----Original Message----- Sent: 5. mars 2021 01:12 Subject: Re: print Roi? I wrote a Java plugin to convert a (polygon) ROI to a 2-column x,y .csv file. My situation is slightly complicated by the fact that I try to make these things work in Locales where ',' is not acceptable as a field separator (like, say, GERMAN). I also prefer Java, where I'm more comfortable. Also...(applicable only to the latest suggestion) I live on Macs, so Windows scripts are twice removed from my comfort zone. It's still a little clunky, and a bit long to post - but I'd be happy to share. I might even put it up on my ImageJ Update site. If it arises, I might be tempted to generalize this to more than simple PolygonRoi - but only if I actually need it! Today, I'm busy writing the code that needed the ROIs in Java-readable format in the first place. And...adding a bullet to my pre-data-collection consultation checklist: do not save essential data in proprietary, undocumented file formats! -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. > On Mar 4, 2021, at 15:08, Stein Rørvik <[hidden email]> wrote: > > What about implementing this as a hybrid script? > > If you are on Windows, the below code should do. > Save the text between the two long lines as MyMacro.cmd, put it in the ImageJ folder, and drop your ROI file onto it. > > The trick is that ImageJ treats the script file as a macro, and Windows treats it as a command ("batch") file. > All you need is to point it to a minimal Java runtime and the ij.jar file, or have these in the same folder as the script. > > ---------------------------------------------------------------------- > ------------------------------------------------- > rem = "Hybrid script with Windows commands and ImageJ macro in the > same file"; /* ::To use, place this file wherever desired and drop > whatever desired onto it ::The ImageJ macro below will be executed > using the dropped filenames, filepaths or parameters as input > arguments ::ImageJ will consider the Windows part as a comment > ::Windows will skip the ImageJ parts > > ::----- start of Windows command script ----- @echo off cls > > ::set MacroFile to this file > set MacroFile=%~f0 > set MacroFile=%MacroFile:\=/% > ::set Parameters to dropped file > set Parameters=%~1 > set Parameters=%Parameters:\=/% > ::create a Java command line > set Command=jre\bin\java -jar -Xmx1024m ij.jar -eval > "runMacro('%MacroFile%', '%Parameters%');" -batch ::execute it > %Command% ::wait for user response before closing pause goto :EOF > ::----- end of Windows command script ----- */ > > //----- start of ImageJ macro script ----- > > strArgument=getArgument(); > print("Arguments:\t" + strArgument); > open(strArgument); > Roi.getCoordinates(x,y); > print('ROI coordinates'); > for (i=0;i<x.length; i++) > print(i,x[i],y[i]);" > > //----- end of ImageJ macro script ----- > ---------------------------------------------------------------------- > ------------------------------------------------- > > -----Original Message----- > Sent: 3. mars 2021 18:02 > Subject: Re: print Roi? > > Thank you for the reply. > > Answering my own question - I eventually found a demonstration macro, from which I extracted this: > > ================ > Roi.getCoordinates(x,y); > print("ROI coordinates"); > for (i=0;i<x.length; i++) > print(i,x[i],y[i]); > ================ > > I would have preferred a stand-alone (preferably Java) program to read the .roi file and print the coordinates, but for my current purposes it was acceptable to drag&drop the .roi files onto a running FIJI and then run the above macro. I only had 10 files to process, so doing this manually was acceptable. > > Actually, I was trying to montage several data files, where the raw data consisted of: > > a) a .csv file giving coordinates for points to be plotted > b) an .roi file giving the location and boundary of the sampled area > > Where the points in a) were expressed in local coordinate systems, relative to the top, left corner of the Roi. > > Alas, I had no control over the data collection. > > I would have preferred to write a stand-along Java program to read a collection of these raw data file pairs, but could not find information on the file format for an .roi file. > > Is there documentation on the format of an .roi file? > > -- > Kenneth Sloan > [hidden email] > Vision is the art of seeing what is invisible to others. > > > > > >> On Mar 2, 2021, at 22:52, Fred Damen <[hidden email]> wrote: >> >> Greeting Kenneth, >> >> Analyze>Tools>ROI Manager::More>>open... >> ::Properties::List Coordinates then OK >> Note: On a Oval ROI the listed coordinates are an interpolated >> version of the displayed vertices. >> FloatPolygon fp = Roi.getFloatPolygon(); If you want to read the >> actual .roi file and list the contents, there are MATLAB scripts out >> there that do this, i.e., easy to read. >> >> ::More>>::List >> This answers one of my previous bonus questions, i.e., GUI display of >> bounding box in voxel/pixel coordinates. >> >> Fred >> >> Produces the definition of the >> On Tue, March 2, 2021 4:04 pm, Kenneth Sloan wrote: >>> I have many (polygon) ROIs stored as .roi files. >>> >>> How can I print the coordinates of the vertices of the ROI? >>> >>> -- >>> Kenneth Sloan >>> [hidden email] >>> Vision is the art of seeing what is invisible to others. >>> >>> -- >>> ImageJ mailing list: >>> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fima >>> g >>> <https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fim >>> ag> ej.nih.gov >>> <https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fej.nih.gov%2F&data=04%7C01%7Cstein.rorvik%40sintef.no%7C44c51e4ac6bc405e57e408d8df96cebf%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637505186106229027%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=PPnokGOut%2FarwL9hKuIIFtQNPfflUFmM1wVuLBIo9fY%3D&reserved=0>%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef. >>> no%7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b >>> 3 >>> 2af%7C1%7C0%7C637503878617041326%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4 >>> w >>> LjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sd >>> a >>> ta=4SWvYMBBCcGFYje7buK4gpjce7DlYgZLr8DEQGfsxdY%3D&reserved=0 >>> >> >> -- >> ImageJ mailing list: >> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimag >> e >> <https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fima >> ge> j.nih.gov >> <https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fj.n >> ih.gov%2F&data=04%7C01%7Cstein.rorvik%40sintef.no%7C44c51e4ac6bc4 >> 05e57e408d8df96cebf%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C6375 >> 05186106229027%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2 >> luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=7jcfTUGOsmdbbzr >> xF51sWVkmBfJMRdjWZs3nOBoyKvY%3D&reserved=0>%2Fij%2Flist.html& >> data=04%7C01%7Cstein.rorvik%40sintef.no >> <https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2F40s >> intef.no%2F&data=04%7C01%7Cstein.rorvik%40sintef.no%7C44c51e4ac6b >> c405e57e408d8df96cebf%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C63 >> 7505186106229027%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoi >> V2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=GfvFgNlxJ%2Bh >> 2raHj0rHesVsuhr22WHbKszFRIK9YloY%3D&reserved=0> >> %7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b32a >> f >> %7C1%7C0%7C637503878617041326%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjA >> w >> MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=4 >> S >> WvYMBBCcGFYje7buK4gpjce7DlYgZLr8DEQGfsxdY%3D&reserved=0 > > -- > ImageJ mailing list: > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage > j.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no > %7C44c51e4ac6bc405e57e408d8df96cebf%7Ce1f00f39604145b0b309e0210d8b32af > %7C1%7C0%7C637505186106229027%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw > MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=fP > LSbdnWGqRi%2BiLKoVDdRIm14eFbst1JOLLFj%2FLulrk%3D&reserved=0 > <https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimag > ej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.n > o%7C44c51e4ac6bc405e57e408d8df96cebf%7Ce1f00f39604145b0b309e0210d8b32a > f%7C1%7C0%7C637505186106234005%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjA > wMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=0 > 1m8pMi8Q%2BDVdsf5%2BcAhh5X0pzKtuNcBvUlDoDcszsY%3D&reserved=0> > > -- > ImageJ mailing list: > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage > j.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no > %7C44c51e4ac6bc405e57e408d8df96cebf%7Ce1f00f39604145b0b309e0210d8b32af > %7C1%7C0%7C637505186106234005%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw > MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=01 > m8pMi8Q%2BDVdsf5%2BcAhh5X0pzKtuNcBvUlDoDcszsY%3D&reserved=0 > <https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimag > ej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.n > o%7C44c51e4ac6bc405e57e408d8df96cebf%7Ce1f00f39604145b0b309e0210d8b32a > f%7C1%7C0%7C637505186106234005%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjA > wMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=0 > 1m8pMi8Q%2BDVdsf5%2BcAhh5X0pzKtuNcBvUlDoDcszsY%3D&reserved=0> -- ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no%7C44c51e4ac6bc405e57e408d8df96cebf%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637505186106234005%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=01m8pMi8Q%2BDVdsf5%2BcAhh5X0pzKtuNcBvUlDoDcszsY%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Yes - that does help - thank you.
In the current case, the problem was exacerbated by the fact that the original data collection protocol saved all of this simply to document the polygon boundary. They created ROIs to outline cells, and then cleared the outside of the ROI and cropped a rectangular piece of the image to create separate images (actually volumes) for each cell. They then proceeded to annotate THOSE images, marking the locations and types of inclusions The original Images were calibrated - but the scale and global Origin was lost in translation. The inclusions were marked in pixel coordinates in the separate image tiles, and the ROIs were described in pixel coordinates in the original image. ROIs were stored in .roi files and the inclusion coordinates were stored in .csv files. And then...they wanted figures showing all the inclusions (stylized and color coded) along with all the ROIs. The required bookkeeping was straightforward, if a bit tedious - with the added speed bump of reading the .roi files to both draw the polygons but also extract the x, y offsets for the many local coordinate systems. Lessons learned: maintain Calibration when carving large images into tiles, and write data in calibrated coordinates rather than pixels. Don’t save an ROI when a list of x,y pairs will do. Don’t use binary formats. if possible. The ease of saving everything in pixels was too attractive for them to avoid. In any case, I now have a plugin tool to convert the polygon information in a .roi file to easily readable x,y pairs, and they kept excellent records so the Calibration could be recreated. I’ll probably write a stand alone Java version...realSoonNow. I’m having flashbacks to the days when I maintained C code for readers and writers for all known image formats (plus, of course, my own). The resulting figures are awesome! Well - the first one is. I have a full day of manual bookkeeping ahead of me today to produce the other 20 figures. One last question, which may reveal my age - are .roi files little-endian or big-endian? -- -Kenneth Sloan -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Stein Rørvik
After solving my initial problem by manually pushing .roi files through ImageJ and writing a simple macro to output x,y coordinates - I cleared the motivating project from my queue.
So…I took up the task of adapting ij.io <http://ij.io/>.RoiDecoder.java to produce a version which works as a stand-alone Java Class, with no external dependencies. This was relatively simple to do, if a bit time-consuming. The result is still quite crude, but it is at the stage where it *would have* served to solve my initial problem - which was to extract x,y coordinates from POLYGON and RECTANGLE .roi files. Many thanks to those who helped me understand where to start. If anyone has similar needs, I’m happy to share my code. [contact me off-list and I’ll send the code. It should fit as an attachment in e-mail]. The implementation attempts to handle every possibility (according to my limited understanding). The test program only fully handles POLYGON and RECTANGLE .roi files - and has lots of stubs which apologize for not being implemented, yet. Even for RECTANGLE ROIs, I don’t understand how a “ShapeArray” works. POLYGON ROIs appear to be fully implemented and tested. Question: is there a test suite of .roi files which exhibits the full range of options? Failing that, and left to my own devices, I am likely to stop working on this - using it for problems that come up for me and extending/testing as new .roi files cross my path. Question 2 (very low level): ij.io <http://ij.io/>.RoiDecoder defines a method: getShort(), which appears to allow negative values only down to -5000 - values lower than that are treated as UNSIGNED Shorts. This looks unhealthy to me (especially since there is a perfectly fine method : getUnsignedShort(). I suspect this may have been written very early on, and has been propagated forward (without breaking anything…yet). I’m tempted to rewrite this to be a proper getShort() method - but first I’ll ask: is there actually a case where ij.io <http://ij.io/>.RoiDecoder would break if this change were made? -- 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 |
Free forum by Nabble | Edit this page |