Batch Mode/Active Image Ambiguity

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

Batch Mode/Active Image Ambiguity

David Webster
When running the included script with batch mode not set, I get
"4: active image is  test2" from  the final print statement. This jibes
with my intuition about what the active image should be at
this point. But, if I use "setBatchMode(true)", I get
"4: active image is  test1". Why does using the batch mode cause
a shift in the active image? Is this correct? This caused me some
problems until I discovered what was going on and started using
selectImage() rather than depending on the default active image.

macro batchtest3 {

newImage("test1", "32-bit", 101, 101, 1);
//setBatchMode(true);
print("1: active image is ",getTitle());
img2="test2"; run("Duplicate...","title="+img2);
print("2: active image is ",getTitle());  
img3="test3"; run("Duplicate...","title="+img3);
print("3: active image is ",getTitle());  
selectImage(img3); close();
print("4: active image is ",getTitle());  
 
} //End macro main

David Webster


Reply | Threaded
Open this post in threaded view
|

Antwort: Batch Mode/Active Image Ambiguity

Joachim Wesner
Hi David,

I have seen this too that relying on the "active image" will not be totally
portable
when switching batch mode on and off and thought that it´s a "feature" of
ImageJ
one has to live with and worked around it with selectImage or doing things
differently
when batchmode is on or not.(I have some scripts where batch mode is a user
option).

Maybe it should/could be fixed?

Joachim


____________________________________________

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

ImageJ Interest Group <[hidden email]> schrieb am 11.03.2009 21:27:17:

> When running the included script with batch mode not set, I get
> "4: active image is  test2" from  the final print statement. This jibes
> with my intuition about what the active image should be at
> this point. But, if I use "setBatchMode(true)", I get
> "4: active image is  test1". Why does using the batch mode cause
> a shift in the active image? Is this correct? This caused me some
> problems until I discovered what was going on and started using
> selectImage() rather than depending on the default active image.
>
> macro batchtest3 {
>
> newImage("test1", "32-bit", 101, 101, 1);
> //setBatchMode(true);
> print("1: active image is ",getTitle());
> img2="test2"; run("Duplicate...","title="+img2);
> print("2: active image is ",getTitle());
> img3="test3"; run("Duplicate...","title="+img3);
> print("3: active image is ",getTitle());
> selectImage(img3); close();
> print("4: active image is ",getTitle());
>
> } //End macro main
>
> David Webster
>
>


______________________________________________________________________
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: Batch Mode/Active Image Ambiguity

Gabriel Landini
> When running the included script with batch mode not set, I get
> "4: active image is  test2" from  the final print statement. This jibes
> with my intuition about what the active image should be at
> this point. But, if I use "setBatchMode(true)", I get
> "4: active image is  test1". Why does using the batch mode cause
> a shift in the active image? Is this correct? This caused me some
> problems until I discovered what was going on and started using
> selectImage() rather than depending on the default active image.

You haven't selected any image inside the batchmode, so it is not using any
and returns the original.

If not using batchmode, I think that IJ must be assigning the active (by
default) to test2 (perhaps by order in the list of windows?).

see:
http://rsb.info.nih.gov/ij/developer/macro/functions.html#S
setBatchMode(arg)
If arg is true, the interpreter enters batch mode and images are not
displayed, allowing the macro to run up to 20 times faster. If arg is false,
exits batch mode and displays the active image in a window. ImageJ exits batch
mode when the macro terminates if there is no setBatchMode(false) call. Note
that a macro should not call setBatchMode(true) more than once.

Apply a SelectImage( string or id); and that will be displayed at the end of
batchmode.
You have to be explicit about which images you are processing using
SelectImage(), otherwise some commands create new results windows that might
get autoselected instead.

Cheers,
G.
Reply | Threaded
Open this post in threaded view
|

Re: Batch Mode/Active Image Ambiguity

Wayne Rasband
In reply to this post by David Webster
On Mar 11, 2009, at 4:27 PM, David William Webster wrote:

> When running the included script with batch mode not set, I get
> "4: active image is  test2" from  the final print statement. This jibes
> with my intuition about what the active image should be at
> this point. But, if I use "setBatchMode(true)", I get
> "4: active image is  test1". Why does using the batch mode cause
> a shift in the active image? Is this correct? This caused me some
> problems until I discovered what was going on and started using
> selectImage() rather than depending on the default active image.

Switch to batch mode before opening any images and the macro will work
as expected. In batch mode there are separate lists for images that are
displayed and images that are not displayed and the list of displayed
images has priority.

    setBatchMode(true);
    newImage("test1", "32-bit", 101, 101, 1);
    print("1: active image is ", getTitle());
    run("Duplicate...","title=test2");
    print("2: active image is ", getTitle());
    run("Duplicate...","title=test3");
    print("3: active image is ", getTitle());
    close();
    print("4: active image is ", getTitle());

-wayne


> macro batchtest3 {
>
> newImage("test1", "32-bit", 101, 101, 1);
> //setBatchMode(true);
> print("1: active image is ",getTitle());
> img2="test2"; run("Duplicate...","title="+img2);
> print("2: active image is ",getTitle());
> img3="test3"; run("Duplicate...","title="+img3);
> print("3: active image is ",getTitle());
> selectImage(img3); close();
> print("4: active image is ",getTitle());
>
> } //End macro main
>
> David Webster
>
>
>