image name as a variable

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

image name as a variable

kgeorge
Dear group,

I am calling file using a file open statement. I would like to merge the final result of this file after analysis as an overlay with an 8-bit version of the original.

Because the image name changes with the file that is called, how do I program the merge statement as opposed to the fixed file name that is given when using the macro recorder?

I have tried variable names:
temp=getImageID();
temp2=getImageID();

run("Merge Channels...", "c1=[temp2] c4=temp create keep");

or printing the outputs of these variables to the screen and coding them directly:

run("Merge Channels...", "c1=[-221] c4=-227 create keep");

I looked deeper into this and believe concatenation or something like may be required.

Lastly, what is the significance of the square brackets in the Merge Channels line? I have seen this in other statements.

Thanks in advance.
Ken

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

Re: image name as a variable

Lachlan Whitehead
Hi Ken,

When using the open command you can use the getInfo("image.filename") command to get the file name into a variable.
So something like:

temp = getInfo("image.filename");
/*...
do all your processing
...*/
temp2 = getTitle();  //Assuming your final result is the active window at this point

then you can run the Merge Channels:

run("Merge Channels...", "c1=["+temp2+"] c4=["+temp+"] create keep");

I believe (and I'm happy to be corrected if I've got this wrong) that the significance of the square brackets is to allow there to be whitespace in the filenames. When calling pretty much any operation in imagej the settings are passed using a long text string. Spaces within the string tell the operation to look for the next setting, square brackets prevent that until it has actually reached the end of the current setting.

Hope that makes sense,
-Lachie

----- Original Message -----
From: "Ken George" <[hidden email]>
To: [hidden email]
Sent: Wednesday, 6 November, 2013 3:21:06 PM
Subject: image name as a variable

Dear group,

I am calling file using a file open statement. I would like to merge the final result of this file after analysis as an overlay with an 8-bit version of the original.

Because the image name changes with the file that is called, how do I program the merge statement as opposed to the fixed file name that is given when using the macro recorder?

I have tried variable names:
temp=getImageID();
temp2=getImageID();

run("Merge Channels...", "c1=[temp2] c4=temp create keep");

or printing the outputs of these variables to the screen and coding them directly:

run("Merge Channels...", "c1=[-221] c4=-227 create keep");

I looked deeper into this and believe concatenation or something like may be required.

Lastly, what is the significance of the square brackets in the Merge Channels line? I have seen this in other statements.

Thanks in advance.
Ken

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

______________________________________________________________________
The information in this email is confidential and intended solely for the addressee.
You must not disclose, forward, print or use it without the permission of the sender.
______________________________________________________________________

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

Re: image name as a variable

kgeorge
In reply to this post by kgeorge
Thanks. Works as advertised.  :-)

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

Re: image name as a variable

pduw
In reply to this post by Lachlan Whitehead
I am a novice and just started using ImageJ macros. I wanted to solve the
same problem as OP, which is solved now. But I am wondering what does the
["+temp+"] does, what's the significance of the + here?

If I remove + merge does not happen

thank you



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: image name as a variable

Aryeh Weiss
On 26/07/2018 0:44, pduw wrote:
> I am a novice and just started using ImageJ macros. I wanted to solve the
> same problem as OP, which is solved now. But I am wondering what does the
> ["+temp+"] does, what's the significance of the + here?
The + concatenates strings. So, if
temp = "myFileName"
and you argument string is constructed as
"all kinds of arguments ["
then
"all kinds of arguments [" + temp
will return a new string
"all kinds of arguments [myFileName"

> If I remove + merge does not happen
>
> thank you
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

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

Re: image name as a variable

Philippe CARL
In reply to this post by pduw
Dear Pankaj,
What the operation the operator "+" you are referring below is doing is a called a "concatenation of strings".
With "Strings" being a "chain of characters".
For example if you write the following simple macro code
        two = 2.0;
        test = "this" + " " + "is" + " " + "a" + " " + "test" + " " + "for" + " " + two;
        print(test);
the result will give you:
        this is a test for 2
Please note that I have defined the variable "two" as a float which is thus automatically transformed into a String (the java operation for doing this would be to use String.valueOf(two)) and tranparently concatened to the rest of the string.
Hoping that my short explanations help you to move further, I wish you a nice day.
My best regards,
Philippe


Le Jeudi 26 Juillet 2018 06:44 CEST, pduw <[hidden email]> a écrit:

> I am a novice and just started using ImageJ macros. I wanted to solve the
> same problem as OP, which is solved now. But I am wondering what does the
> ["+temp+"] does, what's the significance of the + here?
>
> If I remove + merge does not happen
>
> thank you
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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