Login  Register

Re: Help with ImageJ macro code

Posted by crieken on Feb 01, 2008; 5:39pm
URL: http://imagej.273.s1.nabble.com/Help-with-ImageJ-macro-code-tp3697312p3697319.html

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");
>>>