Help with ImageJ macro code

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

Help with ImageJ macro code

crieken
Hi all, I hope this is an appropriate place for this question.  I'm writing a macro to put together a mask from three images with multiple channels.  I am making progress on the macro, but as I test it, I'm running into a problem.  When the 402nm image is opened, the windows "Z" and "W" are named properly.  When the 488nm image is opened, the windows "A", "C", and "D" are named fine, but the "Z" and "W" windows are renamed to "1".  This messes up the creation of the mask and will mess up the analysis that will come further down the line.  I have even tried saving each image individually, but the names still get reset.  This only occurs occasionally, though.  Does anyone have any ideas?  I can email the original images if it would help.  Thanks in advance!  BTW, this may not be the most elegant code, but go easy, I'm a beginner .
Chris

//Selects directory to save files to
dir = getDirectory("Select save directory");

//Prompt for 402nm image
var violet = "Open a 402nm image";  
requires("1.34m");
  title = "Untitled";
  width=512; height=512;
  Dialog.create("402nm");
  Dialog.addMessage(violet);
  Dialog.show();

//Run ICS opener
run("ICS/IDS... ");

//Closes 402 unassigned, 402 background, and renames channel 2 as "Z" and channel 1 as "W"
close();
close();
rename("Z");
run("Put Behind [tab]");
rename("W");

//Prompt for 488nm image
var blue = "Open a 488nm image";  
requires("1.34m");
  title = "Untitled";
  width=512; height=512;
  Dialog.create("488nm");
  Dialog.addMessage(blue);
  Dialog.show();

//Run ICS opener
run("ICS/IDS... ");

//Converts stack to images
run("Convert Stack to Images");

//Closes 488 unassigned, 488 background, E_488 and renames channel 3 as "D", channel 2 as "C", and channel 1 as "A"
close();
close();
close();
rename("D");
run("Put Behind [tab]");
rename("C");
run("Put Behind [tab]");
rename("A");

//Prompt for 561nm image
var green = "Open a 561nm image";  
requires("1.34m");
  title = "Untitled";
  width=512; height=512;
  Dialog.create("561nm");
  Dialog.addMessage(green);
  Dialog.show();

//Run ICS opener
run("ICS/IDS... ");

//Converts stack to images
run("Convert Stack to Images");

//Closes 561 unassigned, 561 background, and renames channel 3 as "gamma", channel 2 as "F", and channel 1 as "E"
close();
close();
rename("gamma");
run("Put Behind [tab]");
rename("F");
run("Put Behind [tab]");
rename("E");

//Create a mask
run("Duplicate...", "title=Mask");
run("Paste Control...");
setPasteMode("OR");
selectWindow("F");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("gamma");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("D");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("C");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("A");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("Z");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("W");
run("Copy");
selectWindow("Mask");
run("Paste");
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

crieken
To add more frustration, the images don't open the same way reproducibly.  I tried rewriting the code so that all 3 raw images are opened, then the macro closes the certain channels I don't want and renames the channels I do want.  The windows are still randomly reset to be named "1" and the channels do not come to the front the same way each time.  
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

Justin McGrath
In reply to this post by crieken
I do not know why your images get renamed, but I think the easiest way
to solve this is to use the getImageID() function, which returns a
unique ID for the active image, and then use the selectImage(id)
function to activate the image later.  It has a few benefits: it's
faster, the IDs are unique, and the IDs don't change throughout macro
execution.

I think you can just replace the rename() and selectWindow()
statements you have now, and it should work.  However, I believe
imageCalculator("or", img1, img2) does the same thing as all of those
select-copy-select-pastes, so you might use that in order to make the
code more succinct.

Justin



On 1/30/08, crieken <[hidden email]> wrote:

> Hi all, I hope this is an appropriate place for this question.  I'm writing
> a
> macro to put together a mask from three images with multiple channels.  I am
> making progress on the macro, but as I test it, I'm running into a problem.
> When the 402nm image is opened, the windows "Z" and "W" are named properly.
> When the 488nm image is opened, the windows "A", "C", and "D" are named
> fine, but the "Z" and "W" windows are renamed to "1".  This messes up the
> creation of the mask and will mess up the analysis that will come further
> down the line.  I have even tried saving each image individually, but the
> names still get reset.  This only occurs occasionally, though.  Does anyone
> have any ideas?  I can email the original images if it would help.  Thanks
> in advance!  BTW, this may not be the most elegant code, but go easy, I'm a
> beginner :confused:.
> Chris
>
> //Selects directory to save files to
> dir = getDirectory("Select save directory");
>
> //Prompt for 402nm image
> var violet = "Open a 402nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("402nm");
>   Dialog.addMessage(violet);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Closes 402 unassigned, 402 background, and renames channel 2 as "Z" and
> channel 1 as "W"
> close();
> close();
> rename("Z");
> run("Put Behind [tab]");
> rename("W");
>
> //Prompt for 488nm image
> var blue = "Open a 488nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("488nm");
>   Dialog.addMessage(blue);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 488 unassigned, 488 background, E_488 and renames channel 3 as "D",
> channel 2 as "C", and channel 1 as "A"
> close();
> close();
> close();
> rename("D");
> run("Put Behind [tab]");
> rename("C");
> run("Put Behind [tab]");
> rename("A");
>
> //Prompt for 561nm image
> var green = "Open a 561nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("561nm");
>   Dialog.addMessage(green);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 561 unassigned, 561 background, and renames channel 3 as "gamma",
> channel 2 as "F", and channel 1 as "E"
> close();
> close();
> rename("gamma");
> run("Put Behind [tab]");
> rename("F");
> run("Put Behind [tab]");
> rename("E");
>
> //Create a mask
> run("Duplicate...", "title=Mask");
> run("Paste Control...");
> setPasteMode("OR");
> selectWindow("F");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("gamma");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("D");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("C");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("A");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("Z");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("W");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
>
> --
> View this message in context:
> http://www.nabble.com/Help-with-ImageJ-macro-code-tp15195190p15195190.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Antwort: Re: Help with ImageJ macro code

Joachim Wesner
Hi there,

I had a similar experience that somehow, when using a mcro together with
plugins, the "front" window ist not always identical with the "active"
resp. "selected" window.
I did not look into that issue further, but also changed my code to use
unique image IDs similar to what Justin suggests and from that on it worked
as expected.

Mit freundlichen Grüßen / Best regards

Joachim Wesner
Projektleiter Optik Technologiesysteme

Leica Microsystems CMS GmbH | GmbH mit Sitz in Wetzlar | Amtsgericht
Wetzlar  HRB 2432
Geschäftsführer:  Dr. Stefan Traeger | Dr. Wolf-Otto Reuter | Dr. David Roy
Martyr | Colin Davis


                                                                           
             [hidden email]                                            
             Gesendet von:                                                
             ImageJ Interest                                            An
             Group                      [hidden email]                
             <[hidden email].                                       Kopie
             GOV>                                                          
                                                                     Thema
                                        Re: Help with ImageJ macro code    
             31.01.2008 04:43                                              
                                                                           
                                                                           
              Bitte antworten                                              
                    an                                                    
              ImageJ Interest                                              
                   Group                                                  
             <[hidden email].                                            
                   GOV>                                                    
                                                                           
                                                                           




I do not know why your images get renamed, but I think the easiest way
to solve this is to use the getImageID() function, which returns a
unique ID for the active image, and then use the selectImage(id)
function to activate the image later.  It has a few benefits: it's
faster, the IDs are unique, and the IDs don't change throughout macro
execution.

I think you can just replace the rename() and selectWindow()
statements you have now, and it should work.  However, I believe
imageCalculator("or", img1, img2) does the same thing as all of those
select-copy-select-pastes, so you might use that in order to make the
code more succinct.

Justin



On 1/30/08, crieken <[hidden email]> wrote:
> Hi all, I hope this is an appropriate place for this question.  I'm
writing
> a
> macro to put together a mask from three images with multiple channels.  I
am
> making progress on the macro, but as I test it, I'm running into a
problem.
> When the 402nm image is opened, the windows "Z" and "W" are named
properly.
> When the 488nm image is opened, the windows "A", "C", and "D" are named
> fine, but the "Z" and "W" windows are renamed to "1".  This messes up the
> creation of the mask and will mess up the analysis that will come further
> down the line.  I have even tried saving each image individually, but the
> names still get reset.  This only occurs occasionally, though.  Does
anyone
> have any ideas?  I can email the original images if it would help.
Thanks
> in advance!  BTW, this may not be the most elegant code, but go easy, I'm
a

> beginner :confused:.
> Chris
>
> //Selects directory to save files to
> dir = getDirectory("Select save directory");
>
> //Prompt for 402nm image
> var violet = "Open a 402nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("402nm");
>   Dialog.addMessage(violet);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Closes 402 unassigned, 402 background, and renames channel 2 as "Z" and
> channel 1 as "W"
> close();
> close();
> rename("Z");
> run("Put Behind [tab]");
> rename("W");
>
> //Prompt for 488nm image
> var blue = "Open a 488nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("488nm");
>   Dialog.addMessage(blue);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 488 unassigned, 488 background, E_488 and renames channel 3 as
"D",

> channel 2 as "C", and channel 1 as "A"
> close();
> close();
> close();
> rename("D");
> run("Put Behind [tab]");
> rename("C");
> run("Put Behind [tab]");
> rename("A");
>
> //Prompt for 561nm image
> var green = "Open a 561nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("561nm");
>   Dialog.addMessage(green);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 561 unassigned, 561 background, and renames channel 3 as
"gamma",

> channel 2 as "F", and channel 1 as "E"
> close();
> close();
> rename("gamma");
> run("Put Behind [tab]");
> rename("F");
> run("Put Behind [tab]");
> rename("E");
>
> //Create a mask
> run("Duplicate...", "title=Mask");
> run("Paste Control...");
> setPasteMode("OR");
> selectWindow("F");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("gamma");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("D");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("C");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("A");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("Z");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("W");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
>
> --
> View this message in context:
>
http://www.nabble.com/Help-with-ImageJ-macro-code-tp15195190p15195190.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>



______________________________________________________________________
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: Help with ImageJ macro code

crieken
In reply to this post by Justin McGrath
Great!  Thanks for the assistance Justin.  I'll let you know how it goes...
Chris
Justin McGrath wrote
I do not know why your images get renamed, but I think the easiest way
to solve this is to use the getImageID() function, which returns a
unique ID for the active image, and then use the selectImage(id)
function to activate the image later.  It has a few benefits: it's
faster, the IDs are unique, and the IDs don't change throughout macro
execution.

I think you can just replace the rename() and selectWindow()
statements you have now, and it should work.  However, I believe
imageCalculator("or", img1, img2) does the same thing as all of those
select-copy-select-pastes, so you might use that in order to make the
code more succinct.

Justin



On 1/30/08, crieken <chris.rieken@gmail.com> wrote:
> Hi all, I hope this is an appropriate place for this question.  I'm writing
> a
> macro to put together a mask from three images with multiple channels.  I am
> making progress on the macro, but as I test it, I'm running into a problem.
> When the 402nm image is opened, the windows "Z" and "W" are named properly.
> When the 488nm image is opened, the windows "A", "C", and "D" are named
> fine, but the "Z" and "W" windows are renamed to "1".  This messes up the
> creation of the mask and will mess up the analysis that will come further
> down the line.  I have even tried saving each image individually, but the
> names still get reset.  This only occurs occasionally, though.  Does anyone
> have any ideas?  I can email the original images if it would help.  Thanks
> in advance!  BTW, this may not be the most elegant code, but go easy, I'm a
> beginner :confused:.
> Chris
>
> //Selects directory to save files to
> dir = getDirectory("Select save directory");
>
> //Prompt for 402nm image
> var violet = "Open a 402nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("402nm");
>   Dialog.addMessage(violet);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Closes 402 unassigned, 402 background, and renames channel 2 as "Z" and
> channel 1 as "W"
> close();
> close();
> rename("Z");
> run("Put Behind [tab]");
> rename("W");
>
> //Prompt for 488nm image
> var blue = "Open a 488nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("488nm");
>   Dialog.addMessage(blue);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 488 unassigned, 488 background, E_488 and renames channel 3 as "D",
> channel 2 as "C", and channel 1 as "A"
> close();
> close();
> close();
> rename("D");
> run("Put Behind [tab]");
> rename("C");
> run("Put Behind [tab]");
> rename("A");
>
> //Prompt for 561nm image
> var green = "Open a 561nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("561nm");
>   Dialog.addMessage(green);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 561 unassigned, 561 background, and renames channel 3 as "gamma",
> channel 2 as "F", and channel 1 as "E"
> close();
> close();
> rename("gamma");
> run("Put Behind [tab]");
> rename("F");
> run("Put Behind [tab]");
> rename("E");
>
> //Create a mask
> run("Duplicate...", "title=Mask");
> run("Paste Control...");
> setPasteMode("OR");
> selectWindow("F");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("gamma");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("D");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("C");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("A");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("Z");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("W");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
>
> --
> View this message in context:
> http://www.nabble.com/Help-with-ImageJ-macro-code-tp15195190p15195190.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

crieken
In reply to this post by Justin McGrath
Hi Justin,
Unfortunately, it doesn't appear that each image is getting a unique ID... unless I'm not using the code correctly.  In the end I need to have the windows named "A, C, D, E, F, gamma, W, Z" in order to do particle analysis.  I keep getting errors, so I printed the image IDs and there is always a repeat, but it seems to vary.  Are the image IDs usually expressed like"-10", "-71", etc.?  Thanks for your advice.
Chris


//Selects directory to save files to
dir = getDirectory("Select save directory");

//Prompt for 402nm image
var violet = "Open a 402nm image";  
requires("1.34m");
  title = "Untitled";
  width=512; height=512;
  Dialog.create("402nm");
  Dialog.addMessage(violet);
  Dialog.show();

//Run ICS opener
run("ICS/IDS... ");

//Closes 402 unassigned, 402 background
close();
close();
Z = getImageID();
run("Put Behind [tab]");
W = getImageID();

//Prompt for 488nm image
var blue = "Open a 488nm image";  
requires("1.34m");
  title = "Untitled";
  width=512; height=512;
  Dialog.create("488nm");
  Dialog.addMessage(blue);
  Dialog.show();

//Run ICS opener
run("ICS/IDS... ");

//Converts stack to images
run("Convert Stack to Images");

//Closes 488 unassigned, 488 background, E_488
close();
close();
close();
D = getImageID();
run("Put Behind [tab]");
C = getImageID();
run("Put Behind [tab]");
A = getImageID();


//Prompt for 561nm image
var green = "Open a 561nm image";  
requires("1.34m");
  title = "Untitled";
  width=512; height=512;
  Dialog.create("561nm");
  Dialog.addMessage(green);
  Dialog.show();

//Run ICS opener
run("ICS/IDS... ");

//Converts stack to images
run("Convert Stack to Images");

//Closes 561 unassigned, 561 background
close();
close();
gamma = getImageID();
run("Put Behind [tab]");
F = getImageID();
run("Put Behind [tab]");
E = getImageID();

//Prints image IDs
print(A);
print(C);
print(D);
print(E);
print(F);
print(gamma);
print(W);
print(Z);


//Renames windows
selectWindow(A);
rename("A");
selectWindow(C);
rename("C");
selectWindow(D);
rename("D");
selectWindow(E);
rename("E");
selectWindow(F);
rename("F");
selectWindow(gamma);
rename("gamma");
selectWindow(W);
rename("W");
selectWindow(Z);
rename("Z");

Justin McGrath wrote
I do not know why your images get renamed, but I think the easiest way
to solve this is to use the getImageID() function, which returns a
unique ID for the active image, and then use the selectImage(id)
function to activate the image later.  It has a few benefits: it's
faster, the IDs are unique, and the IDs don't change throughout macro
execution.

I think you can just replace the rename() and selectWindow()
statements you have now, and it should work.  However, I believe
imageCalculator("or", img1, img2) does the same thing as all of those
select-copy-select-pastes, so you might use that in order to make the
code more succinct.

Justin



On 1/30/08, crieken <chris.rieken@gmail.com> wrote:
> Hi all, I hope this is an appropriate place for this question.  I'm writing
> a
> macro to put together a mask from three images with multiple channels.  I am
> making progress on the macro, but as I test it, I'm running into a problem.
> When the 402nm image is opened, the windows "Z" and "W" are named properly.
> When the 488nm image is opened, the windows "A", "C", and "D" are named
> fine, but the "Z" and "W" windows are renamed to "1".  This messes up the
> creation of the mask and will mess up the analysis that will come further
> down the line.  I have even tried saving each image individually, but the
> names still get reset.  This only occurs occasionally, though.  Does anyone
> have any ideas?  I can email the original images if it would help.  Thanks
> in advance!  BTW, this may not be the most elegant code, but go easy, I'm a
> beginner :confused:.
> Chris
>
> //Selects directory to save files to
> dir = getDirectory("Select save directory");
>
> //Prompt for 402nm image
> var violet = "Open a 402nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("402nm");
>   Dialog.addMessage(violet);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Closes 402 unassigned, 402 background, and renames channel 2 as "Z" and
> channel 1 as "W"
> close();
> close();
> rename("Z");
> run("Put Behind [tab]");
> rename("W");
>
> //Prompt for 488nm image
> var blue = "Open a 488nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("488nm");
>   Dialog.addMessage(blue);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 488 unassigned, 488 background, E_488 and renames channel 3 as "D",
> channel 2 as "C", and channel 1 as "A"
> close();
> close();
> close();
> rename("D");
> run("Put Behind [tab]");
> rename("C");
> run("Put Behind [tab]");
> rename("A");
>
> //Prompt for 561nm image
> var green = "Open a 561nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("561nm");
>   Dialog.addMessage(green);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 561 unassigned, 561 background, and renames channel 3 as "gamma",
> channel 2 as "F", and channel 1 as "E"
> close();
> close();
> rename("gamma");
> run("Put Behind [tab]");
> rename("F");
> run("Put Behind [tab]");
> rename("E");
>
> //Create a mask
> run("Duplicate...", "title=Mask");
> run("Paste Control...");
> setPasteMode("OR");
> selectWindow("F");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("gamma");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("D");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("C");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("A");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("Z");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
> selectWindow("W");
> run("Copy");
> selectWindow("Mask");
> run("Paste");
>
> --
> View this message in context:
> http://www.nabble.com/Help-with-ImageJ-macro-code-tp15195190p15195190.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

Michael Schmid
Hi Chris,

you are right that ImageIDs are negative numbers. They stay
valid until an image is closed. A new image that you open gets
a new ID that is the last ID used minus one.
(strictly speaking, "image" means the ImagePlus class of ImageJ)

See the selectImage(id) and getImageID entries on
   http://rsb.info.nih.gov/ij/developer/macro/functions.html

It might be that your problems are caused by
   run("Put Behind [tab]");
since some operations on Windows happen in a different thread
that may be slower than the thread executing the macro.

Therefore, to access the images created I would simply try:
   Z = getImageID();
   W = getImageID()+1; //the image created before Z


Michael
________________________________________________________________

On 1 Feb 2008, at 01:42, crieken wrote:

> Hi Justin,
> Unfortunately, it doesn't appear that each image is getting a  
> unique ID...
> unless I'm not using the code correctly.  In the end I need to have  
> the
> windows named "A, C, D, E, F, gamma, W, Z" in order to do particle  
> analysis.
> I keep getting errors, so I printed the image IDs and there is  
> always a
> repeat, but it seems to vary.  Are the image IDs usually expressed
> like"-10", "-71", etc.?  Thanks for your advice.
> Chris
>
>
> //Selects directory to save files to
> dir = getDirectory("Select save directory");
>
> //Prompt for 402nm image
> var violet = "Open a 402nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("402nm");
>   Dialog.addMessage(violet);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Closes 402 unassigned, 402 background
> close();
> close();
> Z = getImageID();
> run("Put Behind [tab]");
> W = getImageID();
>
> //Prompt for 488nm image
> var blue = "Open a 488nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("488nm");
>   Dialog.addMessage(blue);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 488 unassigned, 488 background, E_488
> close();
> close();
> close();
> D = getImageID();
> run("Put Behind [tab]");
> C = getImageID();
> run("Put Behind [tab]");
> A = getImageID();
>
>
> //Prompt for 561nm image
> var green = "Open a 561nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("561nm");
>   Dialog.addMessage(green);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 561 unassigned, 561 background
> close();
> close();
> gamma = getImageID();
> run("Put Behind [tab]");
> F = getImageID();
> run("Put Behind [tab]");
> E = getImageID();
>
> //Prints image IDs
> print(A);
> print(C);
> print(D);
> print(E);
> print(F);
> print(gamma);
> print(W);
> print(Z);
>
>
> //Renames windows
> selectWindow(A);
> rename("A");
> selectWindow(C);
> rename("C");
> selectWindow(D);
> rename("D");
> selectWindow(E);
> rename("E");
> selectWindow(F);
> rename("F");
> selectWindow(gamma);
> rename("gamma");
> selectWindow(W);
> rename("W");
> selectWindow(Z);
> rename("Z");
>
>
> Justin McGrath wrote:
>>
>> I do not know why your images get renamed, but I think the easiest  
>> way
>> to solve this is to use the getImageID() function, which returns a
>> unique ID for the active image, and then use the selectImage(id)
>> function to activate the image later.  It has a few benefits: it's
>> faster, the IDs are unique, and the IDs don't change throughout macro
>> execution.
>>
>> I think you can just replace the rename() and selectWindow()
>> statements you have now, and it should work.  However, I believe
>> imageCalculator("or", img1, img2) does the same thing as all of those
>> select-copy-select-pastes, so you might use that in order to make the
>> code more succinct.
>>
>> Justin
>>
>>
>>
>> On 1/30/08, crieken <[hidden email]> wrote:
>>> Hi all, I hope this is an appropriate place for this question.  I'm
>>> writing
>>> a
>>> macro to put together a mask from three images with multiple  
>>> channels.  I
>>> am
>>> making progress on the macro, but as I test it, I'm running into a
>>> problem.
>>> When the 402nm image is opened, the windows "Z" and "W" are named
>>> properly.
>>> When the 488nm image is opened, the windows "A", "C", and "D" are  
>>> named
>>> fine, but the "Z" and "W" windows are renamed to "1".  This  
>>> messes up the
>>> creation of the mask and will mess up the analysis that will come  
>>> further
>>> down the line.  I have even tried saving each image individually,  
>>> but the
>>> names still get reset.  This only occurs occasionally, though.  Does
>>> anyone
>>> have any ideas?  I can email the original images if it would help.
>>> Thanks
>>> in advance!  BTW, this may not be the most elegant code, but go  
>>> easy, I'm
>>> a
>>> beginner :confused:.
>>> Chris
>>>
>>> //Selects directory to save files to
>>> dir = getDirectory("Select save directory");
>>>
>>> //Prompt for 402nm image
>>> var violet = "Open a 402nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("402nm");
>>>   Dialog.addMessage(violet);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Closes 402 unassigned, 402 background, and renames channel 2 as  
>>> "Z" and
>>> channel 1 as "W"
>>> close();
>>> close();
>>> rename("Z");
>>> run("Put Behind [tab]");
>>> rename("W");
>>>
>>> //Prompt for 488nm image
>>> var blue = "Open a 488nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("488nm");
>>>   Dialog.addMessage(blue);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 488 unassigned, 488 background, E_488 and renames  
>>> channel 3 as
>>> "D",
>>> channel 2 as "C", and channel 1 as "A"
>>> close();
>>> close();
>>> close();
>>> rename("D");
>>> run("Put Behind [tab]");
>>> rename("C");
>>> run("Put Behind [tab]");
>>> rename("A");
>>>
>>> //Prompt for 561nm image
>>> var green = "Open a 561nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("561nm");
>>>   Dialog.addMessage(green);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 561 unassigned, 561 background, and renames channel 3 as
>>> "gamma",
>>> channel 2 as "F", and channel 1 as "E"
>>> close();
>>> close();
>>> rename("gamma");
>>> run("Put Behind [tab]");
>>> rename("F");
>>> run("Put Behind [tab]");
>>> rename("E");
>>>
>>> //Create a mask
>>> run("Duplicate...", "title=Mask");
>>> run("Paste Control...");
>>> setPasteMode("OR");
>>> selectWindow("F");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("gamma");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("D");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("C");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("A");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("Z");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("W");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Help-with-ImageJ-macro-code- 
>>> tp15195190p15195190.html
>>> Sent from the ImageJ mailing list archive at Nabble.com.
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Help-with- 
> ImageJ-macro-code-tp15195190p15218299.html
> Sent from the ImageJ mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

crieken
Hi Michael,
Thanks for the advice.  I have rewritten the code as you have suggested, but I'm still getting errors.  The good news is, I think I know why, but the bad is that I have no idea how to solve it.  When I run the macro and open my images, I notice that the active image window (the one on top) will not remain consistent from run to run.  I therefore believe that ImageJ is closing some of the channels I want to retain (A, C, D, etc...) and keeping some of the junk channels I want to discard, thus causing errors in the back end because the imageID that I direct ImageJ to no longer exists.  I will try rewriting the code so that no channels are closed, but how can I be sure that I'm getting the correct imageID when I don't know how to control which window is active?  I could try to identify the windows based on their original window names using a string search (ie 402nm ch:1), but then I run back into the problem that these window names are being reset to "1".  Aaargh!  Sorry to be such a bother, but does anyone have a good fix for this?  Many thanks!
Chris


Michael Schmid-3 wrote
Hi Chris,

you are right that ImageIDs are negative numbers. They stay
valid until an image is closed. A new image that you open gets
a new ID that is the last ID used minus one.
(strictly speaking, "image" means the ImagePlus class of ImageJ)

See the selectImage(id) and getImageID entries on
   http://rsb.info.nih.gov/ij/developer/macro/functions.html

It might be that your problems are caused by
   run("Put Behind [tab]");
since some operations on Windows happen in a different thread
that may be slower than the thread executing the macro.

Therefore, to access the images created I would simply try:
   Z = getImageID();
   W = getImageID()+1; //the image created before Z


Michael
________________________________________________________________

On 1 Feb 2008, at 01:42, crieken wrote:

> Hi Justin,
> Unfortunately, it doesn't appear that each image is getting a  
> unique ID...
> unless I'm not using the code correctly.  In the end I need to have  
> the
> windows named "A, C, D, E, F, gamma, W, Z" in order to do particle  
> analysis.
> I keep getting errors, so I printed the image IDs and there is  
> always a
> repeat, but it seems to vary.  Are the image IDs usually expressed
> like"-10", "-71", etc.?  Thanks for your advice.
> Chris
>
>
> //Selects directory to save files to
> dir = getDirectory("Select save directory");
>
> //Prompt for 402nm image
> var violet = "Open a 402nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("402nm");
>   Dialog.addMessage(violet);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Closes 402 unassigned, 402 background
> close();
> close();
> Z = getImageID();
> run("Put Behind [tab]");
> W = getImageID();
>
> //Prompt for 488nm image
> var blue = "Open a 488nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("488nm");
>   Dialog.addMessage(blue);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 488 unassigned, 488 background, E_488
> close();
> close();
> close();
> D = getImageID();
> run("Put Behind [tab]");
> C = getImageID();
> run("Put Behind [tab]");
> A = getImageID();
>
>
> //Prompt for 561nm image
> var green = "Open a 561nm image";
> requires("1.34m");
>   title = "Untitled";
>   width=512; height=512;
>   Dialog.create("561nm");
>   Dialog.addMessage(green);
>   Dialog.show();
>
> //Run ICS opener
> run("ICS/IDS... ");
>
> //Converts stack to images
> run("Convert Stack to Images");
>
> //Closes 561 unassigned, 561 background
> close();
> close();
> gamma = getImageID();
> run("Put Behind [tab]");
> F = getImageID();
> run("Put Behind [tab]");
> E = getImageID();
>
> //Prints image IDs
> print(A);
> print(C);
> print(D);
> print(E);
> print(F);
> print(gamma);
> print(W);
> print(Z);
>
>
> //Renames windows
> selectWindow(A);
> rename("A");
> selectWindow(C);
> rename("C");
> selectWindow(D);
> rename("D");
> selectWindow(E);
> rename("E");
> selectWindow(F);
> rename("F");
> selectWindow(gamma);
> rename("gamma");
> selectWindow(W);
> rename("W");
> selectWindow(Z);
> rename("Z");
>
>
> Justin McGrath wrote:
>>
>> I do not know why your images get renamed, but I think the easiest  
>> way
>> to solve this is to use the getImageID() function, which returns a
>> unique ID for the active image, and then use the selectImage(id)
>> function to activate the image later.  It has a few benefits: it's
>> faster, the IDs are unique, and the IDs don't change throughout macro
>> execution.
>>
>> I think you can just replace the rename() and selectWindow()
>> statements you have now, and it should work.  However, I believe
>> imageCalculator("or", img1, img2) does the same thing as all of those
>> select-copy-select-pastes, so you might use that in order to make the
>> code more succinct.
>>
>> Justin
>>
>>
>>
>> On 1/30/08, crieken <chris.rieken@gmail.com> wrote:
>>> Hi all, I hope this is an appropriate place for this question.  I'm
>>> writing
>>> a
>>> macro to put together a mask from three images with multiple  
>>> channels.  I
>>> am
>>> making progress on the macro, but as I test it, I'm running into a
>>> problem.
>>> When the 402nm image is opened, the windows "Z" and "W" are named
>>> properly.
>>> When the 488nm image is opened, the windows "A", "C", and "D" are  
>>> named
>>> fine, but the "Z" and "W" windows are renamed to "1".  This  
>>> messes up the
>>> creation of the mask and will mess up the analysis that will come  
>>> further
>>> down the line.  I have even tried saving each image individually,  
>>> but the
>>> names still get reset.  This only occurs occasionally, though.  Does
>>> anyone
>>> have any ideas?  I can email the original images if it would help.
>>> Thanks
>>> in advance!  BTW, this may not be the most elegant code, but go  
>>> easy, I'm
>>> a
>>> beginner :confused:.
>>> Chris
>>>
>>> //Selects directory to save files to
>>> dir = getDirectory("Select save directory");
>>>
>>> //Prompt for 402nm image
>>> var violet = "Open a 402nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("402nm");
>>>   Dialog.addMessage(violet);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Closes 402 unassigned, 402 background, and renames channel 2 as  
>>> "Z" and
>>> channel 1 as "W"
>>> close();
>>> close();
>>> rename("Z");
>>> run("Put Behind [tab]");
>>> rename("W");
>>>
>>> //Prompt for 488nm image
>>> var blue = "Open a 488nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("488nm");
>>>   Dialog.addMessage(blue);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 488 unassigned, 488 background, E_488 and renames  
>>> channel 3 as
>>> "D",
>>> channel 2 as "C", and channel 1 as "A"
>>> close();
>>> close();
>>> close();
>>> rename("D");
>>> run("Put Behind [tab]");
>>> rename("C");
>>> run("Put Behind [tab]");
>>> rename("A");
>>>
>>> //Prompt for 561nm image
>>> var green = "Open a 561nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("561nm");
>>>   Dialog.addMessage(green);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 561 unassigned, 561 background, and renames channel 3 as
>>> "gamma",
>>> channel 2 as "F", and channel 1 as "E"
>>> close();
>>> close();
>>> rename("gamma");
>>> run("Put Behind [tab]");
>>> rename("F");
>>> run("Put Behind [tab]");
>>> rename("E");
>>>
>>> //Create a mask
>>> run("Duplicate...", "title=Mask");
>>> run("Paste Control...");
>>> setPasteMode("OR");
>>> selectWindow("F");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("gamma");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("D");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("C");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("A");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("Z");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>> selectWindow("W");
>>> run("Copy");
>>> selectWindow("Mask");
>>> run("Paste");
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Help-with-ImageJ-macro-code- 
>>> tp15195190p15195190.html
>>> Sent from the ImageJ mailing list archive at Nabble.com.
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Help-with- 
> ImageJ-macro-code-tp15195190p15218299.html
> Sent from the ImageJ mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

Michael Schmid
Hi Chris,

maybe also this is a multithreading problem with the
foreground image not being set fast enough?

There was a bug in ImageJ versions before 1.39f that has caused
such problems - maybe you have an old version?

Otherwise, adding a short delay before close() could help, e.g.
wait(200);
It's not an elegant solution, only a workaround...


Michael
________________________________________________________________

On 1 Feb 2008, at 13:16, crieken wrote:

> Hi Michael,
> Thanks for the advice.  I have rewritten the code as you have  
> suggested, but
> I'm still getting errors.  The good news is, I think I know why,  
> but the bad
> is that I have no idea how to solve it.  When I run the macro and  
> open my
> images, I notice that the active image window (the one on top) will  
> not
> remain consistent from run to run.  I therefore believe that ImageJ is
> closing some of the channels I want to retain (A, C, D, etc...) and  
> keeping
> some of the junk channels I want to discard, thus causing errors in  
> the back
> end because the imageID that I direct ImageJ to no longer exists.  
> I will
> try rewriting the code so that no channels are closed, but how can  
> I be sure
> that I'm getting the correct imageID when I don't know how to  
> control which
> window is active?  I could try to identify the windows based on their
> original window names using a string search (ie 402nm ch:1), but  
> then I run
> back into the problem that these window names are being reset to "1".
> Aaargh!  Sorry to be such a bother, but does anyone have a good fix  
> for
> this?  Many thanks!
> Chris
>
>
>
> Michael Schmid-3 wrote:
>>
>> Hi Chris,
>>
>> you are right that ImageIDs are negative numbers. They stay
>> valid until an image is closed. A new image that you open gets
>> a new ID that is the last ID used minus one.
>> (strictly speaking, "image" means the ImagePlus class of ImageJ)
>>
>> See the selectImage(id) and getImageID entries on
>>    http://rsb.info.nih.gov/ij/developer/macro/functions.html
>>
>> It might be that your problems are caused by
>>    run("Put Behind [tab]");
>> since some operations on Windows happen in a different thread
>> that may be slower than the thread executing the macro.
>>
>> Therefore, to access the images created I would simply try:
>>    Z = getImageID();
>>    W = getImageID()+1; //the image created before Z
>>
>>
>> Michael
>> ________________________________________________________________
>>
>> On 1 Feb 2008, at 01:42, crieken wrote:
>>
>>> Hi Justin,
>>> Unfortunately, it doesn't appear that each image is getting a
>>> unique ID...
>>> unless I'm not using the code correctly.  In the end I need to have
>>> the
>>> windows named "A, C, D, E, F, gamma, W, Z" in order to do particle
>>> analysis.
>>> I keep getting errors, so I printed the image IDs and there is
>>> always a
>>> repeat, but it seems to vary.  Are the image IDs usually expressed
>>> like"-10", "-71", etc.?  Thanks for your advice.
>>> Chris
>>>
>>>
>>> //Selects directory to save files to
>>> dir = getDirectory("Select save directory");
>>>
>>> //Prompt for 402nm image
>>> var violet = "Open a 402nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("402nm");
>>>   Dialog.addMessage(violet);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Closes 402 unassigned, 402 background
>>> close();
>>> close();
>>> Z = getImageID();
>>> run("Put Behind [tab]");
>>> W = getImageID();
>>>
>>> //Prompt for 488nm image
>>> var blue = "Open a 488nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("488nm");
>>>   Dialog.addMessage(blue);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 488 unassigned, 488 background, E_488
>>> close();
>>> close();
>>> close();
>>> D = getImageID();
>>> run("Put Behind [tab]");
>>> C = getImageID();
>>> run("Put Behind [tab]");
>>> A = getImageID();
>>>
>>>
>>> //Prompt for 561nm image
>>> var green = "Open a 561nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("561nm");
>>>   Dialog.addMessage(green);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 561 unassigned, 561 background
>>> close();
>>> close();
>>> gamma = getImageID();
>>> run("Put Behind [tab]");
>>> F = getImageID();
>>> run("Put Behind [tab]");
>>> E = getImageID();
>>>
>>> //Prints image IDs
>>> print(A);
>>> print(C);
>>> print(D);
>>> print(E);
>>> print(F);
>>> print(gamma);
>>> print(W);
>>> print(Z);
>>>
>>>
>>> //Renames windows
>>> selectWindow(A);
>>> rename("A");
>>> selectWindow(C);
>>> rename("C");
>>> selectWindow(D);
>>> rename("D");
>>> selectWindow(E);
>>> rename("E");
>>> selectWindow(F);
>>> rename("F");
>>> selectWindow(gamma);
>>> rename("gamma");
>>> selectWindow(W);
>>> rename("W");
>>> selectWindow(Z);
>>> rename("Z");
>>>
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

Justin McGrath
In reply to this post by crieken
Maybe use setSlice() instead of splitting the stack into different windows.
You can't close unwanted channels, and you'll need more code, but as long as
your channels are always in the same order in the stack, then it should work
correctly.

Justin

On Feb 1, 2008 6:16 AM, crieken <[hidden email]> wrote:

> Hi Michael,
> Thanks for the advice.  I have rewritten the code as you have suggested,
> but
> I'm still getting errors.  The good news is, I think I know why, but the
> bad
> is that I have no idea how to solve it.  When I run the macro and open my
> images, I notice that the active image window (the one on top) will not
> remain consistent from run to run.  I therefore believe that ImageJ is
> closing some of the channels I want to retain (A, C, D, etc...) and
> keeping
> some of the junk channels I want to discard, thus causing errors in the
> back
> end because the imageID that I direct ImageJ to no longer exists.  I will
> try rewriting the code so that no channels are closed, but how can I be
> sure
> that I'm getting the correct imageID when I don't know how to control
> which
> window is active?  I could try to identify the windows based on their
> original window names using a string search (ie 402nm ch:1), but then I
> run
> back into the problem that these window names are being reset to "1".
> Aaargh!  Sorry to be such a bother, but does anyone have a good fix for
> this?  Many thanks!
> Chris
>
>
>
> Michael Schmid-3 wrote:
> >
> > Hi Chris,
> >
> > you are right that ImageIDs are negative numbers. They stay
> > valid until an image is closed. A new image that you open gets
> > a new ID that is the last ID used minus one.
> > (strictly speaking, "image" means the ImagePlus class of ImageJ)
> >
> > See the selectImage(id) and getImageID entries on
> >    http://rsb.info.nih.gov/ij/developer/macro/functions.html
> >
> > It might be that your problems are caused by
> >    run("Put Behind [tab]");
> > since some operations on Windows happen in a different thread
> > that may be slower than the thread executing the macro.
> >
> > Therefore, to access the images created I would simply try:
> >    Z = getImageID();
> >    W = getImageID()+1; //the image created before Z
> >
> >
> > Michael
> > ________________________________________________________________
> >
> > On 1 Feb 2008, at 01:42, crieken wrote:
> >
> >> Hi Justin,
> >> Unfortunately, it doesn't appear that each image is getting a
> >> unique ID...
> >> unless I'm not using the code correctly.  In the end I need to have
> >> the
> >> windows named "A, C, D, E, F, gamma, W, Z" in order to do particle
> >> analysis.
> >> I keep getting errors, so I printed the image IDs and there is
> >> always a
> >> repeat, but it seems to vary.  Are the image IDs usually expressed
> >> like"-10", "-71", etc.?  Thanks for your advice.
> >> Chris
> >>
> >>
> >> //Selects directory to save files to
> >> dir = getDirectory("Select save directory");
> >>
> >> //Prompt for 402nm image
> >> var violet = "Open a 402nm image";
> >> requires("1.34m");
> >>   title = "Untitled";
> >>   width=512; height=512;
> >>   Dialog.create("402nm");
> >>   Dialog.addMessage(violet);
> >>   Dialog.show();
> >>
> >> //Run ICS opener
> >> run("ICS/IDS... ");
> >>
> >> //Closes 402 unassigned, 402 background
> >> close();
> >> close();
> >> Z = getImageID();
> >> run("Put Behind [tab]");
> >> W = getImageID();
> >>
> >> //Prompt for 488nm image
> >> var blue = "Open a 488nm image";
> >> requires("1.34m");
> >>   title = "Untitled";
> >>   width=512; height=512;
> >>   Dialog.create("488nm");
> >>   Dialog.addMessage(blue);
> >>   Dialog.show();
> >>
> >> //Run ICS opener
> >> run("ICS/IDS... ");
> >>
> >> //Converts stack to images
> >> run("Convert Stack to Images");
> >>
> >> //Closes 488 unassigned, 488 background, E_488
> >> close();
> >> close();
> >> close();
> >> D = getImageID();
> >> run("Put Behind [tab]");
> >> C = getImageID();
> >> run("Put Behind [tab]");
> >> A = getImageID();
> >>
> >>
> >> //Prompt for 561nm image
> >> var green = "Open a 561nm image";
> >> requires("1.34m");
> >>   title = "Untitled";
> >>   width=512; height=512;
> >>   Dialog.create("561nm");
> >>   Dialog.addMessage(green);
> >>   Dialog.show();
> >>
> >> //Run ICS opener
> >> run("ICS/IDS... ");
> >>
> >> //Converts stack to images
> >> run("Convert Stack to Images");
> >>
> >> //Closes 561 unassigned, 561 background
> >> close();
> >> close();
> >> gamma = getImageID();
> >> run("Put Behind [tab]");
> >> F = getImageID();
> >> run("Put Behind [tab]");
> >> E = getImageID();
> >>
> >> //Prints image IDs
> >> print(A);
> >> print(C);
> >> print(D);
> >> print(E);
> >> print(F);
> >> print(gamma);
> >> print(W);
> >> print(Z);
> >>
> >>
> >> //Renames windows
> >> selectWindow(A);
> >> rename("A");
> >> selectWindow(C);
> >> rename("C");
> >> selectWindow(D);
> >> rename("D");
> >> selectWindow(E);
> >> rename("E");
> >> selectWindow(F);
> >> rename("F");
> >> selectWindow(gamma);
> >> rename("gamma");
> >> selectWindow(W);
> >> rename("W");
> >> selectWindow(Z);
> >> rename("Z");
> >>
> >>
> >> Justin McGrath wrote:
> >>>
> >>> I do not know why your images get renamed, but I think the easiest
> >>> way
> >>> to solve this is to use the getImageID() function, which returns a
> >>> unique ID for the active image, and then use the selectImage(id)
> >>> function to activate the image later.  It has a few benefits: it's
> >>> faster, the IDs are unique, and the IDs don't change throughout macro
> >>> execution.
> >>>
> >>> I think you can just replace the rename() and selectWindow()
> >>> statements you have now, and it should work.  However, I believe
> >>> imageCalculator("or", img1, img2) does the same thing as all of those
> >>> select-copy-select-pastes, so you might use that in order to make the
> >>> code more succinct.
> >>>
> >>> Justin
> >>>
> >>>
> >>>
> >>> On 1/30/08, crieken <[hidden email]> wrote:
> >>>> Hi all, I hope this is an appropriate place for this question.  I'm
> >>>> writing
> >>>> a
> >>>> macro to put together a mask from three images with multiple
> >>>> channels.  I
> >>>> am
> >>>> making progress on the macro, but as I test it, I'm running into a
> >>>> problem.
> >>>> When the 402nm image is opened, the windows "Z" and "W" are named
> >>>> properly.
> >>>> When the 488nm image is opened, the windows "A", "C", and "D" are
> >>>> named
> >>>> fine, but the "Z" and "W" windows are renamed to "1".  This
> >>>> messes up the
> >>>> creation of the mask and will mess up the analysis that will come
> >>>> further
> >>>> down the line.  I have even tried saving each image individually,
> >>>> but the
> >>>> names still get reset.  This only occurs occasionally, though.  Does
> >>>> anyone
> >>>> have any ideas?  I can email the original images if it would help.
> >>>> Thanks
> >>>> in advance!  BTW, this may not be the most elegant code, but go
> >>>> easy, I'm
> >>>> a
> >>>> beginner :confused:.
> >>>> Chris
> >>>>
> >>>> //Selects directory to save files to
> >>>> dir = getDirectory("Select save directory");
> >>>>
> >>>> //Prompt for 402nm image
> >>>> var violet = "Open a 402nm image";
> >>>> requires("1.34m");
> >>>>   title = "Untitled";
> >>>>   width=512; height=512;
> >>>>   Dialog.create("402nm");
> >>>>   Dialog.addMessage(violet);
> >>>>   Dialog.show();
> >>>>
> >>>> //Run ICS opener
> >>>> run("ICS/IDS... ");
> >>>>
> >>>> //Closes 402 unassigned, 402 background, and renames channel 2 as
> >>>> "Z" and
> >>>> channel 1 as "W"
> >>>> close();
> >>>> close();
> >>>> rename("Z");
> >>>> run("Put Behind [tab]");
> >>>> rename("W");
> >>>>
> >>>> //Prompt for 488nm image
> >>>> var blue = "Open a 488nm image";
> >>>> requires("1.34m");
> >>>>   title = "Untitled";
> >>>>   width=512; height=512;
> >>>>   Dialog.create("488nm");
> >>>>   Dialog.addMessage(blue);
> >>>>   Dialog.show();
> >>>>
> >>>> //Run ICS opener
> >>>> run("ICS/IDS... ");
> >>>>
> >>>> //Converts stack to images
> >>>> run("Convert Stack to Images");
> >>>>
> >>>> //Closes 488 unassigned, 488 background, E_488 and renames
> >>>> channel 3 as
> >>>> "D",
> >>>> channel 2 as "C", and channel 1 as "A"
> >>>> close();
> >>>> close();
> >>>> close();
> >>>> rename("D");
> >>>> run("Put Behind [tab]");
> >>>> rename("C");
> >>>> run("Put Behind [tab]");
> >>>> rename("A");
> >>>>
> >>>> //Prompt for 561nm image
> >>>> var green = "Open a 561nm image";
> >>>> requires("1.34m");
> >>>>   title = "Untitled";
> >>>>   width=512; height=512;
> >>>>   Dialog.create("561nm");
> >>>>   Dialog.addMessage(green);
> >>>>   Dialog.show();
> >>>>
> >>>> //Run ICS opener
> >>>> run("ICS/IDS... ");
> >>>>
> >>>> //Converts stack to images
> >>>> run("Convert Stack to Images");
> >>>>
> >>>> //Closes 561 unassigned, 561 background, and renames channel 3 as
> >>>> "gamma",
> >>>> channel 2 as "F", and channel 1 as "E"
> >>>> close();
> >>>> close();
> >>>> rename("gamma");
> >>>> run("Put Behind [tab]");
> >>>> rename("F");
> >>>> run("Put Behind [tab]");
> >>>> rename("E");
> >>>>
> >>>> //Create a mask
> >>>> run("Duplicate...", "title=Mask");
> >>>> run("Paste Control...");
> >>>> setPasteMode("OR");
> >>>> selectWindow("F");
> >>>> run("Copy");
> >>>> selectWindow("Mask");
> >>>> run("Paste");
> >>>> selectWindow("gamma");
> >>>> run("Copy");
> >>>> selectWindow("Mask");
> >>>> run("Paste");
> >>>> selectWindow("D");
> >>>> run("Copy");
> >>>> selectWindow("Mask");
> >>>> run("Paste");
> >>>> selectWindow("C");
> >>>> run("Copy");
> >>>> selectWindow("Mask");
> >>>> run("Paste");
> >>>> selectWindow("A");
> >>>> run("Copy");
> >>>> selectWindow("Mask");
> >>>> run("Paste");
> >>>> selectWindow("Z");
> >>>> run("Copy");
> >>>> selectWindow("Mask");
> >>>> run("Paste");
> >>>> selectWindow("W");
> >>>> run("Copy");
> >>>> selectWindow("Mask");
> >>>> run("Paste");
> >>>>
> >>>> --
> >>>> View this message in context:
> >>>> http://www.nabble.com/Help-with-ImageJ-macro-code-
> >>>> tp15195190p15195190.html
> >>>> Sent from the ImageJ mailing list archive at Nabble.com.
> >>>>
> >>>
> >>>
> >>
> >> --
> >> View this message in context: http://www.nabble.com/Help-with-
> >> ImageJ-macro-code-tp15195190p15218299.html
> >> Sent from the ImageJ mailing list archive at Nabble.com.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Help-with-ImageJ-macro-code-tp15195190p15225608.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

crieken
In reply to this post by Michael Schmid
Aha!  I'm using 1.38x - I'll check for a newer version and let you know how it goes.  Thanks!
Chris

Michael Schmid-3 wrote
Hi Chris,

maybe also this is a multithreading problem with the
foreground image not being set fast enough?

There was a bug in ImageJ versions before 1.39f that has caused
such problems - maybe you have an old version?

Otherwise, adding a short delay before close() could help, e.g.
wait(200);
It's not an elegant solution, only a workaround...


Michael
________________________________________________________________

On 1 Feb 2008, at 13:16, crieken wrote:

> Hi Michael,
> Thanks for the advice.  I have rewritten the code as you have  
> suggested, but
> I'm still getting errors.  The good news is, I think I know why,  
> but the bad
> is that I have no idea how to solve it.  When I run the macro and  
> open my
> images, I notice that the active image window (the one on top) will  
> not
> remain consistent from run to run.  I therefore believe that ImageJ is
> closing some of the channels I want to retain (A, C, D, etc...) and  
> keeping
> some of the junk channels I want to discard, thus causing errors in  
> the back
> end because the imageID that I direct ImageJ to no longer exists.  
> I will
> try rewriting the code so that no channels are closed, but how can  
> I be sure
> that I'm getting the correct imageID when I don't know how to  
> control which
> window is active?  I could try to identify the windows based on their
> original window names using a string search (ie 402nm ch:1), but  
> then I run
> back into the problem that these window names are being reset to "1".
> Aaargh!  Sorry to be such a bother, but does anyone have a good fix  
> for
> this?  Many thanks!
> Chris
>
>
>
> Michael Schmid-3 wrote:
>>
>> Hi Chris,
>>
>> you are right that ImageIDs are negative numbers. They stay
>> valid until an image is closed. A new image that you open gets
>> a new ID that is the last ID used minus one.
>> (strictly speaking, "image" means the ImagePlus class of ImageJ)
>>
>> See the selectImage(id) and getImageID entries on
>>    http://rsb.info.nih.gov/ij/developer/macro/functions.html
>>
>> It might be that your problems are caused by
>>    run("Put Behind [tab]");
>> since some operations on Windows happen in a different thread
>> that may be slower than the thread executing the macro.
>>
>> Therefore, to access the images created I would simply try:
>>    Z = getImageID();
>>    W = getImageID()+1; //the image created before Z
>>
>>
>> Michael
>> ________________________________________________________________
>>
>> On 1 Feb 2008, at 01:42, crieken wrote:
>>
>>> Hi Justin,
>>> Unfortunately, it doesn't appear that each image is getting a
>>> unique ID...
>>> unless I'm not using the code correctly.  In the end I need to have
>>> the
>>> windows named "A, C, D, E, F, gamma, W, Z" in order to do particle
>>> analysis.
>>> I keep getting errors, so I printed the image IDs and there is
>>> always a
>>> repeat, but it seems to vary.  Are the image IDs usually expressed
>>> like"-10", "-71", etc.?  Thanks for your advice.
>>> Chris
>>>
>>>
>>> //Selects directory to save files to
>>> dir = getDirectory("Select save directory");
>>>
>>> //Prompt for 402nm image
>>> var violet = "Open a 402nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("402nm");
>>>   Dialog.addMessage(violet);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Closes 402 unassigned, 402 background
>>> close();
>>> close();
>>> Z = getImageID();
>>> run("Put Behind [tab]");
>>> W = getImageID();
>>>
>>> //Prompt for 488nm image
>>> var blue = "Open a 488nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("488nm");
>>>   Dialog.addMessage(blue);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 488 unassigned, 488 background, E_488
>>> close();
>>> close();
>>> close();
>>> D = getImageID();
>>> run("Put Behind [tab]");
>>> C = getImageID();
>>> run("Put Behind [tab]");
>>> A = getImageID();
>>>
>>>
>>> //Prompt for 561nm image
>>> var green = "Open a 561nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("561nm");
>>>   Dialog.addMessage(green);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 561 unassigned, 561 background
>>> close();
>>> close();
>>> gamma = getImageID();
>>> run("Put Behind [tab]");
>>> F = getImageID();
>>> run("Put Behind [tab]");
>>> E = getImageID();
>>>
>>> //Prints image IDs
>>> print(A);
>>> print(C);
>>> print(D);
>>> print(E);
>>> print(F);
>>> print(gamma);
>>> print(W);
>>> print(Z);
>>>
>>>
>>> //Renames windows
>>> selectWindow(A);
>>> rename("A");
>>> selectWindow(C);
>>> rename("C");
>>> selectWindow(D);
>>> rename("D");
>>> selectWindow(E);
>>> rename("E");
>>> selectWindow(F);
>>> rename("F");
>>> selectWindow(gamma);
>>> rename("gamma");
>>> selectWindow(W);
>>> rename("W");
>>> selectWindow(Z);
>>> rename("Z");
>>>
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

crieken
1.39q is confused and telling me that I've run out of memory (63MB) when I have it set to 1500MB.  Hmmm, maybe I'll try a version that's a bit older...

crieken wrote
Aha!  I'm using 1.38x - I'll check for a newer version and let you know how it goes.  Thanks!
Chris

Michael Schmid-3 wrote
Hi Chris,

maybe also this is a multithreading problem with the
foreground image not being set fast enough?

There was a bug in ImageJ versions before 1.39f that has caused
such problems - maybe you have an old version?

Otherwise, adding a short delay before close() could help, e.g.
wait(200);
It's not an elegant solution, only a workaround...


Michael
________________________________________________________________

On 1 Feb 2008, at 13:16, crieken wrote:

> Hi Michael,
> Thanks for the advice.  I have rewritten the code as you have  
> suggested, but
> I'm still getting errors.  The good news is, I think I know why,  
> but the bad
> is that I have no idea how to solve it.  When I run the macro and  
> open my
> images, I notice that the active image window (the one on top) will  
> not
> remain consistent from run to run.  I therefore believe that ImageJ is
> closing some of the channels I want to retain (A, C, D, etc...) and  
> keeping
> some of the junk channels I want to discard, thus causing errors in  
> the back
> end because the imageID that I direct ImageJ to no longer exists.  
> I will
> try rewriting the code so that no channels are closed, but how can  
> I be sure
> that I'm getting the correct imageID when I don't know how to  
> control which
> window is active?  I could try to identify the windows based on their
> original window names using a string search (ie 402nm ch:1), but  
> then I run
> back into the problem that these window names are being reset to "1".
> Aaargh!  Sorry to be such a bother, but does anyone have a good fix  
> for
> this?  Many thanks!
> Chris
>
>
>
> Michael Schmid-3 wrote:
>>
>> Hi Chris,
>>
>> you are right that ImageIDs are negative numbers. They stay
>> valid until an image is closed. A new image that you open gets
>> a new ID that is the last ID used minus one.
>> (strictly speaking, "image" means the ImagePlus class of ImageJ)
>>
>> See the selectImage(id) and getImageID entries on
>>    http://rsb.info.nih.gov/ij/developer/macro/functions.html
>>
>> It might be that your problems are caused by
>>    run("Put Behind [tab]");
>> since some operations on Windows happen in a different thread
>> that may be slower than the thread executing the macro.
>>
>> Therefore, to access the images created I would simply try:
>>    Z = getImageID();
>>    W = getImageID()+1; //the image created before Z
>>
>>
>> Michael
>> ________________________________________________________________
>>
>> On 1 Feb 2008, at 01:42, crieken wrote:
>>
>>> Hi Justin,
>>> Unfortunately, it doesn't appear that each image is getting a
>>> unique ID...
>>> unless I'm not using the code correctly.  In the end I need to have
>>> the
>>> windows named "A, C, D, E, F, gamma, W, Z" in order to do particle
>>> analysis.
>>> I keep getting errors, so I printed the image IDs and there is
>>> always a
>>> repeat, but it seems to vary.  Are the image IDs usually expressed
>>> like"-10", "-71", etc.?  Thanks for your advice.
>>> Chris
>>>
>>>
>>> //Selects directory to save files to
>>> dir = getDirectory("Select save directory");
>>>
>>> //Prompt for 402nm image
>>> var violet = "Open a 402nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("402nm");
>>>   Dialog.addMessage(violet);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Closes 402 unassigned, 402 background
>>> close();
>>> close();
>>> Z = getImageID();
>>> run("Put Behind [tab]");
>>> W = getImageID();
>>>
>>> //Prompt for 488nm image
>>> var blue = "Open a 488nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("488nm");
>>>   Dialog.addMessage(blue);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 488 unassigned, 488 background, E_488
>>> close();
>>> close();
>>> close();
>>> D = getImageID();
>>> run("Put Behind [tab]");
>>> C = getImageID();
>>> run("Put Behind [tab]");
>>> A = getImageID();
>>>
>>>
>>> //Prompt for 561nm image
>>> var green = "Open a 561nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("561nm");
>>>   Dialog.addMessage(green);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 561 unassigned, 561 background
>>> close();
>>> close();
>>> gamma = getImageID();
>>> run("Put Behind [tab]");
>>> F = getImageID();
>>> run("Put Behind [tab]");
>>> E = getImageID();
>>>
>>> //Prints image IDs
>>> print(A);
>>> print(C);
>>> print(D);
>>> print(E);
>>> print(F);
>>> print(gamma);
>>> print(W);
>>> print(Z);
>>>
>>>
>>> //Renames windows
>>> selectWindow(A);
>>> rename("A");
>>> selectWindow(C);
>>> rename("C");
>>> selectWindow(D);
>>> rename("D");
>>> selectWindow(E);
>>> rename("E");
>>> selectWindow(F);
>>> rename("F");
>>> selectWindow(gamma);
>>> rename("gamma");
>>> selectWindow(W);
>>> rename("W");
>>> selectWindow(Z);
>>> rename("Z");
>>>
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

crieken
Now the whole thing is messed up and when I try to open ImageJ.exe, I get an error message that says, "Could not create the java virtual machine".  I can run the ij.jar, but then I get the 63MB error.  
Chris

crieken wrote
1.39q is confused and telling me that I've run out of memory (63MB) when I have it set to 1500MB.  Hmmm, maybe I'll try a version that's a bit older...

crieken wrote
Aha!  I'm using 1.38x - I'll check for a newer version and let you know how it goes.  Thanks!
Chris

Michael Schmid-3 wrote
Hi Chris,

maybe also this is a multithreading problem with the
foreground image not being set fast enough?

There was a bug in ImageJ versions before 1.39f that has caused
such problems - maybe you have an old version?

Otherwise, adding a short delay before close() could help, e.g.
wait(200);
It's not an elegant solution, only a workaround...


Michael
________________________________________________________________

On 1 Feb 2008, at 13:16, crieken wrote:

> Hi Michael,
> Thanks for the advice.  I have rewritten the code as you have  
> suggested, but
> I'm still getting errors.  The good news is, I think I know why,  
> but the bad
> is that I have no idea how to solve it.  When I run the macro and  
> open my
> images, I notice that the active image window (the one on top) will  
> not
> remain consistent from run to run.  I therefore believe that ImageJ is
> closing some of the channels I want to retain (A, C, D, etc...) and  
> keeping
> some of the junk channels I want to discard, thus causing errors in  
> the back
> end because the imageID that I direct ImageJ to no longer exists.  
> I will
> try rewriting the code so that no channels are closed, but how can  
> I be sure
> that I'm getting the correct imageID when I don't know how to  
> control which
> window is active?  I could try to identify the windows based on their
> original window names using a string search (ie 402nm ch:1), but  
> then I run
> back into the problem that these window names are being reset to "1".
> Aaargh!  Sorry to be such a bother, but does anyone have a good fix  
> for
> this?  Many thanks!
> Chris
>
>
>
> Michael Schmid-3 wrote:
>>
>> Hi Chris,
>>
>> you are right that ImageIDs are negative numbers. They stay
>> valid until an image is closed. A new image that you open gets
>> a new ID that is the last ID used minus one.
>> (strictly speaking, "image" means the ImagePlus class of ImageJ)
>>
>> See the selectImage(id) and getImageID entries on
>>    http://rsb.info.nih.gov/ij/developer/macro/functions.html
>>
>> It might be that your problems are caused by
>>    run("Put Behind [tab]");
>> since some operations on Windows happen in a different thread
>> that may be slower than the thread executing the macro.
>>
>> Therefore, to access the images created I would simply try:
>>    Z = getImageID();
>>    W = getImageID()+1; //the image created before Z
>>
>>
>> Michael
>> ________________________________________________________________
>>
>> On 1 Feb 2008, at 01:42, crieken wrote:
>>
>>> Hi Justin,
>>> Unfortunately, it doesn't appear that each image is getting a
>>> unique ID...
>>> unless I'm not using the code correctly.  In the end I need to have
>>> the
>>> windows named "A, C, D, E, F, gamma, W, Z" in order to do particle
>>> analysis.
>>> I keep getting errors, so I printed the image IDs and there is
>>> always a
>>> repeat, but it seems to vary.  Are the image IDs usually expressed
>>> like"-10", "-71", etc.?  Thanks for your advice.
>>> Chris
>>>
>>>
>>> //Selects directory to save files to
>>> dir = getDirectory("Select save directory");
>>>
>>> //Prompt for 402nm image
>>> var violet = "Open a 402nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("402nm");
>>>   Dialog.addMessage(violet);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Closes 402 unassigned, 402 background
>>> close();
>>> close();
>>> Z = getImageID();
>>> run("Put Behind [tab]");
>>> W = getImageID();
>>>
>>> //Prompt for 488nm image
>>> var blue = "Open a 488nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("488nm");
>>>   Dialog.addMessage(blue);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 488 unassigned, 488 background, E_488
>>> close();
>>> close();
>>> close();
>>> D = getImageID();
>>> run("Put Behind [tab]");
>>> C = getImageID();
>>> run("Put Behind [tab]");
>>> A = getImageID();
>>>
>>>
>>> //Prompt for 561nm image
>>> var green = "Open a 561nm image";
>>> requires("1.34m");
>>>   title = "Untitled";
>>>   width=512; height=512;
>>>   Dialog.create("561nm");
>>>   Dialog.addMessage(green);
>>>   Dialog.show();
>>>
>>> //Run ICS opener
>>> run("ICS/IDS... ");
>>>
>>> //Converts stack to images
>>> run("Convert Stack to Images");
>>>
>>> //Closes 561 unassigned, 561 background
>>> close();
>>> close();
>>> gamma = getImageID();
>>> run("Put Behind [tab]");
>>> F = getImageID();
>>> run("Put Behind [tab]");
>>> E = getImageID();
>>>
>>> //Prints image IDs
>>> print(A);
>>> print(C);
>>> print(D);
>>> print(E);
>>> print(F);
>>> print(gamma);
>>> print(W);
>>> print(Z);
>>>
>>>
>>> //Renames windows
>>> selectWindow(A);
>>> rename("A");
>>> selectWindow(C);
>>> rename("C");
>>> selectWindow(D);
>>> rename("D");
>>> selectWindow(E);
>>> rename("E");
>>> selectWindow(F);
>>> rename("F");
>>> selectWindow(gamma);
>>> rename("gamma");
>>> selectWindow(W);
>>> rename("W");
>>> selectWindow(Z);
>>> rename("Z");
>>>
Reply | Threaded
Open this post in threaded view
|

Re: Help with ImageJ macro code

Wayne Rasband
On Windows, try deleting the configuration file (ImageJ.cfg) and  
restarting ImageJ. The ImageJ launcher (ImageJ.exe) will detect that  
ImageJ.cfg is missing and generate a replacement. If the ImageJ/jre  
directory is missing, it will detect the latest installed Java and  
setup ImageJ.cfg to use that instead. It will set the memory limit to  
2/3 of installed memory or 640MB, whichever is lower. You will only be  
able to use 63MB of you launch ImageJ by double clicking on ij.jar.

-wayne

On Feb 1, 2008, at 1:13 PM, crieken wrote:

> Now the whole thing is messed up and when I try to open ImageJ.exe, I  
> get an
> error message that says, "Could not create the java virtual machine".  
> I can
> run the ij.jar, but then I get the 63MB error.
> Chris
>
>
> crieken wrote:
>>
>> 1.39q is confused and telling me that I've run out of memory (63MB)  
>> when I
>> have it set to 1500MB.  Hmmm, maybe I'll try a version that's a bit
>> older...
>>
>>
>> crieken wrote:
>>>
>>> Aha!  I'm using 1.38x - I'll check for a newer version and let you  
>>> know
>>> how it goes.  Thanks!
>>> Chris
>>>
>>>
>>> Michael Schmid-3 wrote:
>>>>
>>>> Hi Chris,
>>>>
>>>> maybe also this is a multithreading problem with the
>>>> foreground image not being set fast enough?
>>>>
>>>> There was a bug in ImageJ versions before 1.39f that has caused
>>>> such problems - maybe you have an old version?
>>>>
>>>> Otherwise, adding a short delay before close() could help, e.g.
>>>> wait(200);
>>>> It's not an elegant solution, only a workaround...
>>>>
>>>>
>>>> Michael
>>>> ________________________________________________________________
>>>>
>>>> On 1 Feb 2008, at 13:16, crieken wrote:
>>>>
>>>>> Hi Michael,
>>>>> Thanks for the advice.  I have rewritten the code as you have
>>>>> suggested, but
>>>>> I'm still getting errors.  The good news is, I think I know why,
>>>>> but the bad
>>>>> is that I have no idea how to solve it.  When I run the macro and
>>>>> open my
>>>>> images, I notice that the active image window (the one on top) will
>>>>> not
>>>>> remain consistent from run to run.  I therefore believe that  
>>>>> ImageJ is
>>>>> closing some of the channels I want to retain (A, C, D, etc...) and
>>>>> keeping
>>>>> some of the junk channels I want to discard, thus causing errors in
>>>>> the back
>>>>> end because the imageID that I direct ImageJ to no longer exists.
>>>>> I will
>>>>> try rewriting the code so that no channels are closed, but how can
>>>>> I be sure
>>>>> that I'm getting the correct imageID when I don't know how to
>>>>> control which
>>>>> window is active?  I could try to identify the windows based on  
>>>>> their
>>>>> original window names using a string search (ie 402nm ch:1), but
>>>>> then I run
>>>>> back into the problem that these window names are being reset to  
>>>>> "1".
>>>>> Aaargh!  Sorry to be such a bother, but does anyone have a good fix
>>>>> for
>>>>> this?  Many thanks!
>>>>> Chris
>>>>>
>>>>>
>>>>>
>>>>> Michael Schmid-3 wrote:
>>>>>>
>>>>>> Hi Chris,
>>>>>>
>>>>>> you are right that ImageIDs are negative numbers. They stay
>>>>>> valid until an image is closed. A new image that you open gets
>>>>>> a new ID that is the last ID used minus one.
>>>>>> (strictly speaking, "image" means the ImagePlus class of ImageJ)
>>>>>>
>>>>>> See the selectImage(id) and getImageID entries on
>>>>>>    http://rsb.info.nih.gov/ij/developer/macro/functions.html
>>>>>>
>>>>>> It might be that your problems are caused by
>>>>>>    run("Put Behind [tab]");
>>>>>> since some operations on Windows happen in a different thread
>>>>>> that may be slower than the thread executing the macro.
>>>>>>
>>>>>> Therefore, to access the images created I would simply try:
>>>>>>    Z = getImageID();
>>>>>>    W = getImageID()+1; //the image created before Z
>>>>>>
>>>>>>
>>>>>> Michael
>>>>>> ________________________________________________________________
>>>>>>
>>>>>> On 1 Feb 2008, at 01:42, crieken wrote:
>>>>>>
>>>>>>> Hi Justin,
>>>>>>> Unfortunately, it doesn't appear that each image is getting a
>>>>>>> unique ID...
>>>>>>> unless I'm not using the code correctly.  In the end I need to  
>>>>>>> have
>>>>>>> the
>>>>>>> windows named "A, C, D, E, F, gamma, W, Z" in order to do  
>>>>>>> particle
>>>>>>> analysis.
>>>>>>> I keep getting errors, so I printed the image IDs and there is
>>>>>>> always a
>>>>>>> repeat, but it seems to vary.  Are the image IDs usually  
>>>>>>> expressed
>>>>>>> like"-10", "-71", etc.?  Thanks for your advice.
>>>>>>> Chris
>>>>>>>
>>>>>>>
>>>>>>> //Selects directory to save files to
>>>>>>> dir = getDirectory("Select save directory");
>>>>>>>
>>>>>>> //Prompt for 402nm image
>>>>>>> var violet = "Open a 402nm image";
>>>>>>> requires("1.34m");
>>>>>>>   title = "Untitled";
>>>>>>>   width=512; height=512;
>>>>>>>   Dialog.create("402nm");
>>>>>>>   Dialog.addMessage(violet);
>>>>>>>   Dialog.show();
>>>>>>>
>>>>>>> //Run ICS opener
>>>>>>> run("ICS/IDS... ");
>>>>>>>
>>>>>>> //Closes 402 unassigned, 402 background
>>>>>>> close();
>>>>>>> close();
>>>>>>> Z = getImageID();
>>>>>>> run("Put Behind [tab]");
>>>>>>> W = getImageID();
>>>>>>>
>>>>>>> //Prompt for 488nm image
>>>>>>> var blue = "Open a 488nm image";
>>>>>>> requires("1.34m");
>>>>>>>   title = "Untitled";
>>>>>>>   width=512; height=512;
>>>>>>>   Dialog.create("488nm");
>>>>>>>   Dialog.addMessage(blue);
>>>>>>>   Dialog.show();
>>>>>>>
>>>>>>> //Run ICS opener
>>>>>>> run("ICS/IDS... ");
>>>>>>>
>>>>>>> //Converts stack to images
>>>>>>> run("Convert Stack to Images");
>>>>>>>
>>>>>>> //Closes 488 unassigned, 488 background, E_488
>>>>>>> close();
>>>>>>> close();
>>>>>>> close();
>>>>>>> D = getImageID();
>>>>>>> run("Put Behind [tab]");
>>>>>>> C = getImageID();
>>>>>>> run("Put Behind [tab]");
>>>>>>> A = getImageID();
>>>>>>>
>>>>>>>
>>>>>>> //Prompt for 561nm image
>>>>>>> var green = "Open a 561nm image";
>>>>>>> requires("1.34m");
>>>>>>>   title = "Untitled";
>>>>>>>   width=512; height=512;
>>>>>>>   Dialog.create("561nm");
>>>>>>>   Dialog.addMessage(green);
>>>>>>>   Dialog.show();
>>>>>>>
>>>>>>> //Run ICS opener
>>>>>>> run("ICS/IDS... ");
>>>>>>>
>>>>>>> //Converts stack to images
>>>>>>> run("Convert Stack to Images");
>>>>>>>
>>>>>>> //Closes 561 unassigned, 561 background
>>>>>>> close();
>>>>>>> close();
>>>>>>> gamma = getImageID();
>>>>>>> run("Put Behind [tab]");
>>>>>>> F = getImageID();
>>>>>>> run("Put Behind [tab]");
>>>>>>> E = getImageID();
>>>>>>>
>>>>>>> //Prints image IDs
>>>>>>> print(A);
>>>>>>> print(C);
>>>>>>> print(D);
>>>>>>> print(E);
>>>>>>> print(F);
>>>>>>> print(gamma);
>>>>>>> print(W);
>>>>>>> print(Z);
>>>>>>>
>>>>>>>
>>>>>>> //Renames windows
>>>>>>> selectWindow(A);
>>>>>>> rename("A");
>>>>>>> selectWindow(C);
>>>>>>> rename("C");
>>>>>>> selectWindow(D);
>>>>>>> rename("D");
>>>>>>> selectWindow(E);
>>>>>>> rename("E");
>>>>>>> selectWindow(F);
>>>>>>> rename("F");
>>>>>>> selectWindow(gamma);
>>>>>>> rename("gamma");
>>>>>>> selectWindow(W);
>>>>>>> rename("W");
>>>>>>> selectWindow(Z);
>>>>>>> rename("Z");
>>>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
> --  
> View this message in context:  
> http://www.nabble.com/Help-with-ImageJ-macro-code- 
> tp15195190p15231843.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Plot profile for multiple ROIs

Pedro J CamelloDr Pedro J Camello
In reply to this post by crieken
Hi all,

I need to obtain plot profiles from several lines in a number of images.
If I create all the lines for an image with the ROI Multimeasure or the
ROI manager, would be possible to get automatically all the corresponding
plot profiles?

Thanks in advance


--
Dr Pedro J Camello
Dpt Physiology
Faculty of Veterinary Sciences
University of Extremadura
10071 Caceres
Spain
Ph: 927257100 Extension 1321
Fax:927257110