Login  Register

Re: Is it normal to use a wait() instruction after a command

Posted by Aryeh Weiss on Feb 11, 2015; 5:29pm
URL: http://imagej.273.s1.nabble.com/Is-it-normal-to-use-a-wait-instruction-after-a-command-tp5011551p5011570.html

On 2/11/15 5:32 PM, Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Feb 11, 2015, at 3:42 AM, Eric Denarier <[hidden email]> wrote:
>> Hi John and Gabriel,
>> Thank you for your answers. Here is an example of the macro that behaves differently if wait(1000) is removed.
>> It runs on the original image instead of running on the LoG of the Image.
>> Enclosed a stack to run the macro.
> Hi Eric,
>
> The LoG 3D plugin (http://bigwww.epfl.ch/sage/soft/LoG3D/) is not designed to be called from a macro. Unlike normal plugins, it returns immediately and processes the image in a separate thread. You can work around this problem by calling selectWindow(“LoG 3D of “+title), which will wait for the output image to be displayed. Unfortunately, selectWindow() has a 2 second timeout, so this will not work if LoG 3D takes more than 2 seconds to process the image. The following test macro
>
>    run("T1 Head Renderings (736K)");
>    title = getTitle;
>    t0 = getTime;
>    run("LoG 3D", "sigmax=3 sigmay=3 sigmaz=0 displaykernel=0 volume=0");
>    print("LoG 3D returned: " + (getTime-t0));
>    selectWindow("LoG of " + title);
>    print("LoG 3D window opened: " + (getTime-t0));
>
> displays
>
>     LoG 3D returned: 4
>     LoG 3D window opened: 667
>
> in the Log window, which shows that Log 3D returned after only 4 ms, but it took 667 ms to process the stack in a separate thread.
>
> -wayne
>
You can  use something like:
while (!isOpen(your-expected-window-name)) {
// code to let you know the macro is still alive while you wait

}

to wait for your window. I did this with the EDF (extended depth of
focus) plugin, which also returns immediately.

--aryeh

>> run("Gaussian Blur...", "sigma=1 stack");
>> run("LoG 3D", "sigmax=3 sigmay=3 sigmaz=0 displaykernel=0 volume=0");
>> wait (1000);
>> run("8-bit");
>> run("Invert", "stack");
>> setOption("BlackBackground", true);
>> run("Convert to Mask", "method=Intermodes background=Dark black stack");
>> selectWindow("LoG of essai_0.tif");
>> run("Duplicate...", "title=Avant duplicate range=nSlices");
>> run("Duplicate...", "title=Apres duplicate range=nSlices");
>> run("Delete Slice");
>> run("Divide...", "value=255 stack");
>>
>> Eric Denarier
>> Grenoble Institut des Neurosciences
>> Inserm U836
>> Chemin Fortuné Ferrini
>> 38700 La Tronche
>> France
>>
>>
>> Tél :33 (0)4 56 52 05 38
>> Fax :33 (0)4 56 52 06 57
>>
>> http://neurosciences.ujf-grenoble.fr/
>>
>> Le 10/02/2015 21:58, Gabriel Landini a écrit :
>>> On Tuesday 10 Feb 2015 21:09:28 Eric Denarier wrote:
>>>> As I had no answer to my former question , I try to rephrase it.
>>> No, it is not normal, but the description is too vague for anybody to be able
>>> to explain what is going on. Perhaps if you post a short example where this
>>> happens, we can try to reproduce the problem in various platforms.
>>>
>>> Cheers
>>> Gabriel
>>>
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>> <essai_0.tif>
> --
> 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