Re: print Roi?

Posted by Stein Rørvik on
URL: http://imagej.273.s1.nabble.com/print-Roi-tp5024487p5024499.html

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&amp;data=04%7C01%7Cstein.rorvik%40sintef.
>> no%7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b3
>> 2af%7C1%7C0%7C637503878617041326%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4w
>> LjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sda
>> ta=4SWvYMBBCcGFYje7buK4gpjce7DlYgZLr8DEQGfsxdY%3D&amp;reserved=0
>>
>
> --
> ImageJ mailing list:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no
> %7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C0%7C637503878617041326%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw
> MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=4S
> WvYMBBCcGFYje7buK4gpjce7DlYgZLr8DEQGfsxdY%3D&amp;reserved=0

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C4627ec1073f24f45c66408d8de666167%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637503878617046305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=991OKTEw7fcxXRVsTcc%2BKoNSZFTtGt%2B8fiympsDh1fU%3D&amp;reserved=0

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