array in macro functions

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

array in macro functions

Csaba DÁVID
Hi,i have coordinates of hundreds of irregularly shaped polygons that i want to draw on a single image. I do not have the polygons as ROIs, unfortunately. I want to usea list of coordinates from another software. I managed to import them in an array, but when i wanted to use makePolygon(coord); where coord is an array of all the coordinates of a polygon, i got the failure message: Numer or numeric function is required. When i wrote a list of coordinates one by one in the makePolygon function it worked well, but I do not have the time to write all the many thousand coordinates of many hundred polygons that way.
How can I use list of coordinates for making polygons?
Many thank in advance!Csaba

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

Re: array in macro functions

Krs5
Dear Csaba,

You need something like:

coord = newArray(20,48,59,13,101,40,75,77,38,70);
makePolygon(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5],coord[6],coord[7],coord[8],coord[9]);

I guess it depends a little how many sides your polygons will have how to implement this.

Best wishes

Kees


Dr Ir K.R. Straatman
Senior Experimental Officer
Advanced Imaging Facility
Centre for Core Biotechnology Services
University of Leicester
www.le.ac.uk/advanced-imaging-facility



-----Original Message-----
From: Csaba DÁVID [mailto:[hidden email]]
Sent: 15 February 2018 20:28
To: [hidden email]
Subject: array in macro functions

Hi,i have coordinates of hundreds of irregularly shaped polygons that i want to draw on a single image. I do not have the polygons as ROIs, unfortunately. I want to usea list of coordinates from another software. I managed to import them in an array, but when i wanted to use makePolygon(coord); where coord is an array of all the coordinates of a polygon, i got the failure message: Numer or numeric function is required. When i wrote a list of coordinates one by one in the makePolygon function it worked well, but I do not have the time to write all the many thousand coordinates of many hundred polygons that way.
How can I use list of coordinates for making polygons?
Many thank in advance!Csaba

--
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: array in macro functions

Csaba DÁVID
Dear Kees,this is exactly what I wanted to avoid, since each of the polygons have different number of points, so I cannot express them in a general format. Is there any tricky way? Maybe?Best regardsCsaba

    On Friday, February 16, 2018 9:55 AM, "Straatman, Kees (Dr.)" <[hidden email]> wrote:
 

 Dear Csaba,

You need something like:

coord = newArray(20,48,59,13,101,40,75,77,38,70);
makePolygon(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5],coord[6],coord[7],coord[8],coord[9]);

I guess it depends a little how many sides your polygons will have how to implement this.

Best wishes

Kees


Dr Ir K.R. Straatman
Senior Experimental Officer
Advanced Imaging Facility
Centre for Core Biotechnology Services
University of Leicester
www.le.ac.uk/advanced-imaging-facility



-----Original Message-----
From: Csaba DÁVID [mailto:[hidden email]]
Sent: 15 February 2018 20:28
To: [hidden email]
Subject: array in macro functions

Hi,i have coordinates of hundreds of irregularly shaped polygons that i want to draw on a single image. I do not have the polygons as ROIs, unfortunately. I want to usea list of coordinates from another software. I managed to import them in an array, but when i wanted to use makePolygon(coord); where coord is an array of all the coordinates of a polygon, i got the failure message: Numer or numeric function is required. When i wrote a list of coordinates one by one in the makePolygon function it worked well, but I do not have the time to write all the many thousand coordinates of many hundred polygons that way.
How can I use list of coordinates for making polygons?
Many thank in advance!Csaba

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

Re: array in macro functions

Jan Eglinger
Dear Csaba,

I recommend to switch to some of the more powerful scripting languages
[1], e.g. Groovy, Javascript, Beanshell or Jython.
They provide syntactic constructs (such as list comprehensions) that
facilitate this kind of task. In addition, you have full access to the
underlying Java API [2] to create your Roi objects.

Cheers
Jan

[1]: https://imagej.net/Scripting#Supported_languages
[2]: http://javadoc.scijava.org/ImageJ1/index.html?overview-summary.html

On 16.02.2018 10:09, Csaba DÁVID wrote:

> Dear Kees,this is exactly what I wanted to avoid, since each of the polygons have different number of points, so I cannot express them in a general format. Is there any tricky way? Maybe?Best regardsCsaba
>
>      On Friday, February 16, 2018 9:55 AM, "Straatman, Kees (Dr.)" <[hidden email]> wrote:
>  
>
>   Dear Csaba,
>
> You need something like:
>
> coord = newArray(20,48,59,13,101,40,75,77,38,70);
> makePolygon(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5],coord[6],coord[7],coord[8],coord[9]);
>
> I guess it depends a little how many sides your polygons will have how to implement this.
>
> Best wishes
>
> Kees
>
>
> Dr Ir K.R. Straatman
> Senior Experimental Officer
> Advanced Imaging Facility
> Centre for Core Biotechnology Services
> University of Leicester
> www.le.ac.uk/advanced-imaging-facility
>
>
>
> -----Original Message-----
> From: Csaba DÁVID [mailto:[hidden email]]
> Sent: 15 February 2018 20:28
> To: [hidden email]
> Subject: array in macro functions
>
> Hi,i have coordinates of hundreds of irregularly shaped polygons that i want to draw on a single image. I do not have the polygons as ROIs, unfortunately. I want to usea list of coordinates from another software. I managed to import them in an array, but when i wanted to use makePolygon(coord); where coord is an array of all the coordinates of a polygon, i got the failure message: Numer or numeric function is required. When i wrote a list of coordinates one by one in the makePolygon function it worked well, but I do not have the time to write all the many thousand coordinates of many hundred polygons that way.
> How can I use list of coordinates for making polygons?
> Many thank in advance!Csaba
>
> --
> 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
Reply | Threaded
Open this post in threaded view
|

Re: array in macro functions

Csaba DÁVID
Dear Jan,thank you for your advice. I was afraid that I have to learn another language. But it is probably not possible to learn Java in a week :(
ThanksCsaba
 

    On Friday, February 16, 2018 10:25 AM, Jan Eglinger <[hidden email]> wrote:
 

 Dear Csaba,

I recommend to switch to some of the more powerful scripting languages
[1], e.g. Groovy, Javascript, Beanshell or Jython.
They provide syntactic constructs (such as list comprehensions) that
facilitate this kind of task. In addition, you have full access to the
underlying Java API [2] to create your Roi objects.

Cheers
Jan

[1]: https://imagej.net/Scripting#Supported_languages
[2]: http://javadoc.scijava.org/ImageJ1/index.html?overview-summary.html

On 16.02.2018 10:09, Csaba DÁVID wrote:

> Dear Kees,this is exactly what I wanted to avoid, since each of the polygons have different number of points, so I cannot express them in a general format. Is there any tricky way? Maybe?Best regardsCsaba
>
>      On Friday, February 16, 2018 9:55 AM, "Straatman, Kees (Dr.)" <[hidden email]> wrote:

>
>  Dear Csaba,
>
> You need something like:
>
> coord = newArray(20,48,59,13,101,40,75,77,38,70);
> makePolygon(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5],coord[6],coord[7],coord[8],coord[9]);
>
> I guess it depends a little how many sides your polygons will have how to implement this.
>
> Best wishes
>
> Kees
>
>
> Dr Ir K.R. Straatman
> Senior Experimental Officer
> Advanced Imaging Facility
> Centre for Core Biotechnology Services
> University of Leicester
> www.le.ac.uk/advanced-imaging-facility
>
>
>
> -----Original Message-----
> From: Csaba DÁVID [mailto:[hidden email]]
> Sent: 15 February 2018 20:28
> To: [hidden email]
> Subject: array in macro functions
>
> Hi,i have coordinates of hundreds of irregularly shaped polygons that i want to draw on a single image. I do not have the polygons as ROIs, unfortunately. I want to usea list of coordinates from another software. I managed to import them in an array, but when i wanted to use makePolygon(coord); where coord is an array of all the coordinates of a polygon, i got the failure message: Numer or numeric function is required. When i wrote a list of coordinates one by one in the makePolygon function it worked well, but I do not have the time to write all the many thousand coordinates of many hundred polygons that way.
> How can I use list of coordinates for making polygons?
> Many thank in advance!Csaba
>
> --
> 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


   

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

Re: array in macro functions

Herbie
In reply to this post by Jan Eglinger
Good day,

did you consider:

"*makeSelection(type, xcoord, ycoord)*
Creates a selection from a list of XY coordinates. The first argument
should be "polygon", "freehand", "polyline", "freeline", "angle" or
"point", or the numeric value returned by selectionType. The xcoord and
ycoord arguments are numeric arrays that contain the X and Y
coordinates. See the MakeSelectionDemo macro for examples."

Regards

Herbie

::::::::::::::::::::::::::::::::::::::::::
Am 16.02.18 um 10:23 schrieb Jan Eglinger:

> Dear Csaba,
>
> I recommend to switch to some of the more powerful scripting languages
> [1], e.g. Groovy, Javascript, Beanshell or Jython.
> They provide syntactic constructs (such as list comprehensions) that
> facilitate this kind of task. In addition, you have full access to the
> underlying Java API [2] to create your Roi objects.
>
> Cheers
> Jan
>
> [1]: https://imagej.net/Scripting#Supported_languages
> [2]: http://javadoc.scijava.org/ImageJ1/index.html?overview-summary.html
>
> On 16.02.2018 10:09, Csaba DÁVID wrote:
>> Dear Kees,this is exactly what I wanted to avoid, since each of the
>> polygons have different number of points, so I cannot express them in
>> a general format. Is there any tricky way? Maybe?Best regardsCsaba
>>
>>      On Friday, February 16, 2018 9:55 AM, "Straatman, Kees (Dr.)"
>> <[hidden email]> wrote:
>>
>>   Dear Csaba,
>>
>> You need something like:
>>
>> coord = newArray(20,48,59,13,101,40,75,77,38,70);
>> makePolygon(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5],coord[6],coord[7],coord[8],coord[9]);
>>
>>
>> I guess it depends a little how many sides your polygons will have how
>> to implement this.
>>
>> Best wishes
>>
>> Kees
>>
>>
>> Dr Ir K.R. Straatman
>> Senior Experimental Officer
>> Advanced Imaging Facility
>> Centre for Core Biotechnology Services
>> University of Leicester
>> www.le.ac.uk/advanced-imaging-facility
>>
>>
>>
>> -----Original Message-----
>> From: Csaba DÁVID [mailto:[hidden email]]
>> Sent: 15 February 2018 20:28
>> To: [hidden email]
>> Subject: array in macro functions
>>
>> Hi,i have coordinates of hundreds of irregularly shaped polygons that
>> i want to draw on a single image. I do not have the polygons as ROIs,
>> unfortunately. I want to usea list of coordinates from another
>> software. I managed to import them in an array, but when i wanted to
>> use makePolygon(coord); where coord is an array of all the coordinates
>> of a polygon, i got the failure message: Numer or numeric function is
>> required. When i wrote a list of coordinates one by one in the
>> makePolygon function it worked well, but I do not have the time to
>> write all the many thousand coordinates of many hundred polygons that
>> way.
>> How can I use list of coordinates for making polygons?
>> Many thank in advance!Csaba
>>
>> --
>> 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
>

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

Re: array in macro functions

Gabriel Landini
In reply to this post by Csaba DÁVID
On Friday, 16 February 2018 09:31:50 GMT Csaba DÁVID wrote:
> Dear Jan,thank you for your advice. I was afraid that I have to learn
> another language. But it is probably not possible to learn Java in a week
> :( ThanksCsaba

You do not have to learn another language if you can do this as a macro:

You need to have stored the list of coordinates in some file or a text, so you
have one ROI per line.
Read the file somehow (there are macros showing how to do that in the
examples).
Then, make a loop:
Read one line of the text file (ROI) at a time,
Parse the number of coordinates in that line (there is a split function in the
macro language), and count them, e.g. 15.
Create the x and y arrays with that number of items  coorx=newArray(15), etc.
Assign the coordinates to the array (you can use another loop)
Call the makeSelection function as Herbie suggested
Plot the ROI
End of loop.

In the macro language you can generate an array again with a different number
of items at each iteration of the loop. You cannot do that in Java without
resorting to some tricks or using a List.

Hope it helps.

Gabriel

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