Function in imagej

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

Function in imagej

Lelli Thomas
Hello

I want to return several arguments in a function in imagej macro, but I
don't know how save it in a variable

I would like recuperate a and b

How can i write it?

For example:

a,b=calcul(1,2);
function calcul(a,b){
s=a+b;
d=a-b;
return a;
return b;
}
Reply | Threaded
Open this post in threaded view
|

Re: Function in imagej

Gluender
Dear Lelli Thomas,

I guess you like to return 's' and 'd', don't you ?


>Hello
>
>I want to return several arguments in a function in imagej macro,
>but I don't know how save it in a variable
>
>I would like recuperate a and b
>
>How can i write it?
>
>For example:
>
>a,b=calcul(1,2);
>function calcul(a,b){
>s=a+b;
>d=a-b;
>return a;
>return b;
>}


You may put your results into an array an return the array.

You may even pass the array to the function, set the result values
and by "java-magic" see the results returned after the function
finishes without even returning the array itself.

HTH


--


                   Herbie

          ------------------------

          <http://www.gluender.de>
Reply | Threaded
Open this post in threaded view
|

Re: Function in imagej

Michael Schmid
In reply to this post by Lelli Thomas
Hi,
No programming language that I am aware of allows something like what
you suggested - "return" stops executing a function.

You can use global variables, see the documentation at
  http://rsb.info.nih.gov/ij/developer/macro/macros.html

var return1;
var return2;

calcul(1,2);
myresult = return1 * return2;


function calcul(a,b) {
return1 = a + b;
return2 = a - b;
}

Michael
________________________________________________________

On Wed, 11 Apr 2007 12:10:42 +0200 Lelli Thomas wrote:

>Hello
>
>I want to return several arguments in a function in imagej macro, but I
>don't know how save it in a variable
>
>I would like recuperate a and b
>
>How can i write it?
>
>For example:
>
>a,b=calcul(1,2);
>function calcul(a,b){
>s=a+b;
>d=a-b;
>return a;
>return b;
>}
>
Reply | Threaded
Open this post in threaded view
|

Re: Function in imagej

Lelli Thomas
In reply to this post by Gluender
Yes, i want to return s an d
I can return an array but I just give you an example

In my reel macro, I need to return 2 arrays, and i can't create an array
of array


function triMoyenne(a){
nb_cellule=0;
for (i=0; i<a.length; i++) nb_cellule++;
nb_cellule=nb_cellule/nb_color;
print("nbr_cellule="+nb_cellule);
D1=newArray(nb_cellule);
D2=newArray(nb_cellule);
D3=newArray(nb_cellule);
//remplissage de D1, D2, D3
for (j=0; j<nb_cellule; j++){
    D1[j]=a[j*nb_color];
    D2[j]=a[j*nb_color+1];
    D3[j]=a[j*nb_color+2];

}

return D1;  // and D2 and D3

Gluender a écrit :

> Dear Lelli Thomas,
>
> I guess you like to return 's' and 'd', don't you ?
>
>
>> Hello
>>
>> I want to return several arguments in a function in imagej macro, but
>> I don't know how save it in a variable
>>
>> I would like recuperate a and b
>>
>> How can i write it?
>>
>> For example:
>>
>> a,b=calcul(1,2);
>> function calcul(a,b){
>> s=a+b;
>> d=a-b;
>> return a;
>> return b;
>> }
>
>
> You may put your results into an array an return the array.
>
> You may even pass the array to the function, set the result values and
> by "java-magic" see the results returned after the function finishes
> without even returning the array itself.
>
> HTH
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Function in imagej

Gluender
Dear Lelli Thomas,

well you are to declare the arrays in the main part of your macro.
Then, pass them (empty) to your function like: triMoyenne( a, D1, D2,
D3 ). Don't return anything and the arrays will be filled with what
you have entered to them in the function.

>Yes, i want to return s an d
>I can return an array but I just give you an example
>
>In my reel macro, I need to return 2 arrays, and i can't create an
>array of array
>
>function triMoyenne(a){
>nb_cellule=0;
>for (i=0; i<a.length; i++) nb_cellule++;
>nb_cellule=nb_cellule/nb_color;
>print("nbr_cellule="+nb_cellule);
>D1=newArray(nb_cellule);
>D2=newArray(nb_cellule);
>D3=newArray(nb_cellule);
>//remplissage de D1, D2, D3
>for (j=0; j<nb_cellule; j++){
>    D1[j]=a[j*nb_color];
>    D2[j]=a[j*nb_color+1];
>    D3[j]=a[j*nb_color+2];
>
>}
>
>return D1;  // and D2 and D3
>
>Gluender a écrit :
>>Dear Lelli Thomas,
>>
>>I guess you like to return 's' and 'd', don't you ?
>>
>>>Hello
>>>
>>>I want to return several arguments in a function in imagej macro,
>>>but I don't know how save it in a variable
>>>
>>>I would like recuperate a and b
>>>
>>>How can i write it?
>>>
>>>For example:
>>>
>>>a,b=calcul(1,2);
>>>function calcul(a,b){
>>>s=a+b;
>>>d=a-b;
>>>return a;
>>>return b;
>>>}
>>
>>
>>You may put your results into an array an return the array.
>>
>>You may even pass the array to the function, set the result values
>>and by "java-magic" see the results returned after the function
>>finishes without even returning the array itself.
>>
>>HTH

Best


--


                   Herbie

          ------------------------

          <http://www.gluender.de>
Reply | Threaded
Open this post in threaded view
|

Re: Function in imagej

Justin McGrath
In reply to this post by Lelli Thomas
I was under the impression that one could make an array of arrays in
Java.  If not, you could make a simple class that contained two
arrays.  Passing arrays (which get sent as pointers) will change the
values in the arrays, but I like return values more.  They seem more
intuitive.

Justin

On 4/11/07, Gluender <[hidden email]> wrote:

> Dear Lelli Thomas,
>
> well you are to declare the arrays in the main part of your macro.
> Then, pass them (empty) to your function like: triMoyenne( a, D1, D2,
> D3 ). Don't return anything and the arrays will be filled with what
> you have entered to them in the function.
>
> >Yes, i want to return s an d
> >I can return an array but I just give you an example
> >
> >In my reel macro, I need to return 2 arrays, and i can't create an
> >array of array
> >
> >function triMoyenne(a){
> >nb_cellule=0;
> >for (i=0; i<a.length; i++) nb_cellule++;
> >nb_cellule=nb_cellule/nb_color;
> >print("nbr_cellule="+nb_cellule);
> >D1=newArray(nb_cellule);
> >D2=newArray(nb_cellule);
> >D3=newArray(nb_cellule);
> >//remplissage de D1, D2, D3
> >for (j=0; j<nb_cellule; j++){
> >    D1[j]=a[j*nb_color];
> >    D2[j]=a[j*nb_color+1];
> >    D3[j]=a[j*nb_color+2];
> >
> >}
> >
> >return D1;  // and D2 and D3
> >
> >Gluender a écrit :
> >>Dear Lelli Thomas,
> >>
> >>I guess you like to return 's' and 'd', don't you ?
> >>
> >>>Hello
> >>>
> >>>I want to return several arguments in a function in imagej macro,
> >>>but I don't know how save it in a variable
> >>>
> >>>I would like recuperate a and b
> >>>
> >>>How can i write it?
> >>>
> >>>For example:
> >>>
> >>>a,b=calcul(1,2);
> >>>function calcul(a,b){
> >>>s=a+b;
> >>>d=a-b;
> >>>return a;
> >>>return b;
> >>>}
> >>
> >>
> >>You may put your results into an array an return the array.
> >>
> >>You may even pass the array to the function, set the result values
> >>and by "java-magic" see the results returned after the function
> >>finishes without even returning the array itself.
> >>
> >>HTH
>
> Best
>
>
> --
>
>
>                    Herbie
>
>           ------------------------
>
>           <http://www.gluender.de>
>
Reply | Threaded
Open this post in threaded view
|

Antwort: Re: Function in imagej

Joachim Wesner
ImageJ Interest Group <[hidden email]> schrieb am 11.04.2007 15:24:13:

> I was under the impression that one could make an array of arrays in
> Java.  If not, you could make a simple class that contained two
> arrays.  Passing arrays (which get sent as pointers) will change the
> values in the arrays, but I like return values more.  They seem more
> intuitive.
>
> Justin
>

Yep, but the thread was about ImageJs macro language which is somewhat
similar
but not really full Java at all. Macro only has simple 1-dim arrays.

JW



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: Function in imagej

Ben G
In reply to this post by Gluender
Gluender,

I have been fighting with functions that suddenly quit working.  I guess I don't understand functions.  The IJ documentation says almost nothing.

Here is my problem.  I want to find the boundary values of an ROI using a function, then use those boundary values in my calculation without having to scan the whole image.  Each piece works fine, but they will not work together.  The function finds the values fine, but I cannot see them in the rest of the program.  All the variables are declared globally.

Below is a simple example.  I declare two global variables, a an b, then use a function to change their values.  Then I print the results.  As you can see, the variables are not changed outside the function.

I would appreciate some help.

var a,b;

FCT();
print ("a="+a+", b="+b);

function FCT(){
a=5;
b=10;
}

//----------------------------------------------------
//result is a=0, b=0
Reply | Threaded
Open this post in threaded view
|

Re: Function in imagej

Justin McGrath
If run directly from the text file editor in ImageJ (Using Macro->Run
Macro), your code should run fine.  However, for a reason I don't
remember, if you install the macro, you need to define a macro within
the file in order for global variables to work correctly.  The
following should work:

var a,b;

macro "Print" {
    FCT();
    print ("a="+a+", b="+b);
}

function FCT() {
    a=5;
    b=10;
}

You can have multiple macro definitions in the file.  Each will be
listed in the Macro menu. Global variables need to be declared outside
of any function or macro definiton.  You can also add hotkeys after
the macro name e.g.

macro "Print" [F4] {code};

Justin

On Fri, Oct 17, 2008 at 2:15 PM, Ben G <[hidden email]> wrote:

> Gluender,
>
> I have been fighting with functions that suddenly quit working.  I guess I
> don't understand functions.  The IJ documentation says almost nothing.
>
> Here is my problem.  I want to find the boundary values of an ROI using a
> function, then use those boundary values in my calculation without having to
> scan the whole image.  Each piece works fine, but they will not work
> together.  The function finds the values fine, but I cannot see them in the
> rest of the program.  All the variables are declared globally.
>
> Below is a simple example.  I declare two global variables, a an b, then use
> a function to change their values.  Then I print the results.  As you can
> see, the variables are not changed outside the function.
>
> I would appreciate some help.
>
> var a,b;
>
> FCT();
> print ("a="+a+", b="+b);
>
> function FCT(){
> a=5;
> b=10;
> }
>
> //----------------------------------------------------
> //result is a=0, b=0
> --
> View this message in context: http://n2.nabble.com/Function-in-imagej-tp633159p1346445.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Function in imagej

Wayne Rasband
In reply to this post by Lelli Thomas
This bug, which was introduced in 1.41k, is fixed in the v1.41o daily  
build. Macro functions should be able to change the values of global  
variables.

-wayne


> I have been fighting with functions that suddenly quit working.  I  
> guess I
> don't understand functions.  The IJ documentation says almost nothing.
>
> Here is my problem.  I want to find the boundary values of an ROI  
> using a
> function, then use those boundary values in my calculation without  
> having to
> scan the whole image.  Each piece works fine, but they will not work
> together.  The function finds the values fine, but I cannot see  
> them in the
> rest of the program.  All the variables are declared globally.
>
> Below is a simple example.  I declare two global variables, a an b,  
> then use
> a function to change their values.  Then I print the results.  As  
> you can
> see, the variables are not changed outside the function.
>
> I would appreciate some help.
>
> var a,b;
>
> FCT();
> print ("a="+a+", b="+b);
>
> function FCT(){
> a=5;
> b=10;
> }
>
> //----------------------------------------------------
> //result is a=0, b=0