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

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

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

ERIC
Hi All,
As I had no answer to my former question , I try to rephrase it.
Can I be explained why the instruction of a macro are not executed one
after the others ?
My problem being that sometimes I have to add a wait(1000 or more) after
an instructionso that the result is obtained before the next instruction
is executed. If I do not add the wait() then the last instrcution is
executed before obtaining the result of the former.
How can I know the time needed in the wait(time) instruction ?

Can anyone clarified this point  ??? Thank you



--

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/

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

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

John Hayes
Hi Eric,

Can you illustrate the macro code that you are using where you are observing the problem?

In the meantime, it sounds like the plugin calls you are making from the macro are not blocking -- by that, I mean the execution of the macro continues after a given plugin is started. I _think_ this is because calls to "run" create a new instance of PlugIns/PlugInFilters and spawns a separate for each thread by default. I'm not sure what the most elegant solution for avoiding this currently is from macros, but this would explain why you would have to put a wait function after each call and the length of time varies from computer to computer.

You may want to also check out the "runMacro" function, which could potentially replace calls to "run" and I think it blocks.

HTH,

John

Le 10 févr. 2015 à 15:09, Eric Denarier a écrit :

> Hi All,
> As I had no answer to my former question , I try to rephrase it.
> Can I be explained why the instruction of a macro are not executed one after the others ?
> My problem being that sometimes I have to add a wait(1000 or more) after an instructionso that the result is obtained before the next instruction is executed. If I do not add the wait() then the last instrcution is executed before obtaining the result of the former.
> How can I know the time needed in the wait(time) instruction ?
>
> Can anyone clarified this point  ??? Thank you
>
>
>
> --
>
> 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/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

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

Gabriel Landini
In reply to this post by ERIC
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
Reply | Threaded
Open this post in threaded view
|

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

ERIC
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.





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 (250K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

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

Gabriel Landini
On Wednesday 11 Feb 2015 09:42:41 Eric Denarier 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.

Not sure what this macro should do, but I think that the difference in result
has to do with the program assuming that is processing the right image, while
it is not doing so.
If you specify what is the result of the LoG3 and select that as the current
image then I think it behaves as without the "wait":
 
a=getTitle();
run("Gaussian Blur...", "sigma=1 stack");
run("LoG 3D", "sigmax=3 sigmay=3 sigmaz=0 displaykernel=0 volume=0");
selectWindow("LoG of "+a);
run("8-bit");
run("Invert", "stack");
setOption("BlackBackground", true);
run("Convert to Mask", "method=Intermodes background=Dark black stack");
selectWindow("LoG of "+a);  // this line might no be necessary now
run("Duplicate...", "title=Avant duplicate range=nSlices");
run("Duplicate...", "title=Apres duplicate range=nSlices");
run("Delete Slice");
run("Divide...", "value=255 stack");


Perhaps IJ is not getting the current image correctly, or the LoG3 plugin is
not returning the image on time. Not sure, but I think the above resolves it.

Cheers
Gabriel

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

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

ERIC
It works : Specifing the name of the image that the LoG plugin produces
makes the wait()  unnecessary.

Thank you all for your suggestion.

a=getTitle();
run("Gaussian Blur...", "sigma=1 stack");
run("LoG 3D", "sigmax=3 sigmay=3 sigmaz=0 displaykernel=0 volume=0");
selectWindow("LoG of "+a);
run("8-bit");





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 11/02/2015 12:14, Gabriel Landini a écrit :

> On Wednesday 11 Feb 2015 09:42:41 Eric Denarier 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.
> Not sure what this macro should do, but I think that the difference in result
> has to do with the program assuming that is processing the right image, while
> it is not doing so.
> If you specify what is the result of the LoG3 and select that as the current
> image then I think it behaves as without the "wait":
>  
> a=getTitle();
> run("Gaussian Blur...", "sigma=1 stack");
> run("LoG 3D", "sigmax=3 sigmay=3 sigmaz=0 displaykernel=0 volume=0");
> selectWindow("LoG of "+a);
> run("8-bit");
> run("Invert", "stack");
> setOption("BlackBackground", true);
> run("Convert to Mask", "method=Intermodes background=Dark black stack");
> selectWindow("LoG of "+a);  // this line might no be necessary now
> run("Duplicate...", "title=Avant duplicate range=nSlices");
> run("Duplicate...", "title=Apres duplicate range=nSlices");
> run("Delete Slice");
> run("Divide...", "value=255 stack");
>
>
> Perhaps IJ is not getting the current image correctly, or the LoG3 plugin is
> not returning the image on time. Not sure, but I think the above resolves it.
>
> Cheers
> Gabriel
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

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

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by ERIC
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


> 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
Reply | Threaded
Open this post in threaded view
|

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

Aryeh Weiss
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