Help with Macro

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

Help with Macro

Margiotta, Joseph
I would like to write a macro that allows the user to set the tolerance for the wand tool by clicking on two points that represent the boundaries of light and dark and then take the difference between these values as the tolerance.

This difference value could then be used in a line of code for the macro I have already written and that is now specified as 2500 in the macro below that is set up to draw a perimeter around a light area in a stack of 25 images:


run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");

setTool("point");

s = selectionType();


if( s == -1 ) {

    exit("There was no selection.");

} else if( s != 10 ) {

    exit("The selection wasn't a point selection.");

} else {

    getSelectionCoordinates(xPoints,yPoints);

    x = xPoints[0];

    y = yPoints[0];

    showMessage("Got coordinates ("+x+","+y+")");

};wait(2000);

w = selectionType();


if( w == -1 ) {

    exit("There was no selection.");

} else if( w != 10 ) {

    exit("The selection wasn't a point selection.");

} else {

    getSelectionCoordinates(xPoints,yPoints);

    x1 = xPoints[0];

    y1 = yPoints[0];

    showMessage("Got coordinates ("+x1+","+y1+")");

}

for (i=1; i<=25; i++) {

j=1*i;

Stack.setSlice(j);

//setTool("wand");

doWand(x, y, 2500, "8-connected");

doWand(x1, y1, 2500, "8-connected");

run("Measure");wait(200);

}


My problem is that I am new to this programming language and I can’t figure out how I input a variable and have the macro use that value in a calculation.

Can anyone out there help?


-- Joseph F. Margiotta, PhD
Dept. of Neurosciences
University of Toledo College of Medicine
3000 Transverse Drive
Block HS 120A   Mail Stop 1007
Toledo, OH  43614
419-383-4119


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

Re: Help with Macro

ctrueden
Hi Joseph,

> My problem is that I am new to this programming language and I can’t
> figure out how I input a variable and have the macro use that value in
> a calculation.

The classical way is using the Dialog.* macro functions:
   http://imagej.net/developer/macro/functions.html#dialog

The "ImageJ2 way" is to declare your input and output parameters at the top
of your macro/script; e.g.:

    // @String name
    // @OUTPUT String greeting

    // An ImageJ macro with parameters.
    // It is the duty of the scripting framework to harvest
    // the 'name' parameter from the user, and then display
    // the 'greeting' output parameter, based on its type.

    greeting = "Hello " + name + "!";

For numeric parameters, you can use "double" for the type instead of
"String".

You an access the above macro as a starting point by pressing the "[" key
to launch the Script Editor, then choosing Templates > IJ1 Macro > Greeting.

You will need to be using ImageJ2 for this approach to work. The easiest
way to do that at the moment is to download the Fiji distribution of ImageJ
from: http://imagej.net/Downloads

Regards,
Curtis

On Wed, Jan 14, 2015 at 4:36 PM, Margiotta, Joseph <
[hidden email]> wrote:

> I would like to write a macro that allows the user to set the tolerance
> for the wand tool by clicking on two points that represent the boundaries
> of light and dark and then take the difference between these values as the
> tolerance.
>
> This difference value could then be used in a line of code for the macro I
> have already written and that is now specified as 2500 in the macro below
> that is set up to draw a perimeter around a light area in a stack of 25
> images:
>
>
> run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
>
> setTool("point");
>
> s = selectionType();
>
>
> if( s == -1 ) {
>
>     exit("There was no selection.");
>
> } else if( s != 10 ) {
>
>     exit("The selection wasn't a point selection.");
>
> } else {
>
>     getSelectionCoordinates(xPoints,yPoints);
>
>     x = xPoints[0];
>
>     y = yPoints[0];
>
>     showMessage("Got coordinates ("+x+","+y+")");
>
> };wait(2000);
>
> w = selectionType();
>
>
> if( w == -1 ) {
>
>     exit("There was no selection.");
>
> } else if( w != 10 ) {
>
>     exit("The selection wasn't a point selection.");
>
> } else {
>
>     getSelectionCoordinates(xPoints,yPoints);
>
>     x1 = xPoints[0];
>
>     y1 = yPoints[0];
>
>     showMessage("Got coordinates ("+x1+","+y1+")");
>
> }
>
> for (i=1; i<=25; i++) {
>
> j=1*i;
>
> Stack.setSlice(j);
>
> //setTool("wand");
>
> doWand(x, y, 2500, "8-connected");
>
> doWand(x1, y1, 2500, "8-connected");
>
> run("Measure");wait(200);
>
> }
>
>
> My problem is that I am new to this programming language and I can’t
> figure out how I input a variable and have the macro use that value in a
> calculation.
>
> Can anyone out there help?
>
>
> -- Joseph F. Margiotta, PhD
> Dept. of Neurosciences
> University of Toledo College of Medicine
> 3000 Transverse Drive
> Block HS 120A   Mail Stop 1007
> Toledo, OH  43614
> 419-383-4119
>
>
> --
> 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: Help with Macro

Margiotta, Joseph
Thanks curtis.  Using the Dialog function works fine for me!

-- Joseph F. Margiotta, PhD
Dept. of Neurosciences
University of Toledo College of Medicine
3000 Transverse Drive
Block HS 120A   Mail Stop 1007
Toledo, OH  43614
419-383-4119






On 1/14/15, 6:09 PM, "Curtis Rueden" <[hidden email]> wrote:

>Hi Joseph,
>
>> My problem is that I am new to this programming language and I can¹t
>> figure out how I input a variable and have the macro use that value in
>> a calculation.
>
>The classical way is using the Dialog.* macro functions:
>   http://imagej.net/developer/macro/functions.html#dialog
>
>The "ImageJ2 way" is to declare your input and output parameters at the
>top
>of your macro/script; e.g.:
>
>    // @String name
>    // @OUTPUT String greeting
>
>    // An ImageJ macro with parameters.
>    // It is the duty of the scripting framework to harvest
>    // the 'name' parameter from the user, and then display
>    // the 'greeting' output parameter, based on its type.
>
>    greeting = "Hello " + name + "!";
>
>For numeric parameters, you can use "double" for the type instead of
>"String".
>
>You an access the above macro as a starting point by pressing the "[" key
>to launch the Script Editor, then choosing Templates > IJ1 Macro >
>Greeting.
>
>You will need to be using ImageJ2 for this approach to work. The easiest
>way to do that at the moment is to download the Fiji distribution of
>ImageJ
>from: http://imagej.net/Downloads
>
>Regards,
>Curtis
>
>On Wed, Jan 14, 2015 at 4:36 PM, Margiotta, Joseph <
>[hidden email]> wrote:
>
>> I would like to write a macro that allows the user to set the tolerance
>> for the wand tool by clicking on two points that represent the
>>boundaries
>> of light and dark and then take the difference between these values as
>>the
>> tolerance.
>>
>> This difference value could then be used in a line of code for the
>>macro I
>> have already written and that is now specified as 2500 in the macro
>>below
>> that is set up to draw a perimeter around a light area in a stack of 25
>> images:
>>
>>
>> run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
>>
>> setTool("point");
>>
>> s = selectionType();
>>
>>
>> if( s == -1 ) {
>>
>>     exit("There was no selection.");
>>
>> } else if( s != 10 ) {
>>
>>     exit("The selection wasn't a point selection.");
>>
>> } else {
>>
>>     getSelectionCoordinates(xPoints,yPoints);
>>
>>     x = xPoints[0];
>>
>>     y = yPoints[0];
>>
>>     showMessage("Got coordinates ("+x+","+y+")");
>>
>> };wait(2000);
>>
>> w = selectionType();
>>
>>
>> if( w == -1 ) {
>>
>>     exit("There was no selection.");
>>
>> } else if( w != 10 ) {
>>
>>     exit("The selection wasn't a point selection.");
>>
>> } else {
>>
>>     getSelectionCoordinates(xPoints,yPoints);
>>
>>     x1 = xPoints[0];
>>
>>     y1 = yPoints[0];
>>
>>     showMessage("Got coordinates ("+x1+","+y1+")");
>>
>> }
>>
>> for (i=1; i<=25; i++) {
>>
>> j=1*i;
>>
>> Stack.setSlice(j);
>>
>> //setTool("wand");
>>
>> doWand(x, y, 2500, "8-connected");
>>
>> doWand(x1, y1, 2500, "8-connected");
>>
>> run("Measure");wait(200);
>>
>> }
>>
>>
>> My problem is that I am new to this programming language and I can¹t
>> figure out how I input a variable and have the macro use that value in a
>> calculation.
>>
>> Can anyone out there help?
>>
>>
>> -- Joseph F. Margiotta, PhD
>> Dept. of Neurosciences
>> University of Toledo College of Medicine
>> 3000 Transverse Drive
>> Block HS 120A   Mail Stop 1007
>> Toledo, OH  43614
>> 419-383-4119
>>
>>
>> --
>> 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