Programatic(Java) zooming issue(s)

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

Programatic(Java) zooming issue(s)

Fred Damen
Greetings,

Resizing image windows thru the GUI seems to always work as expected.
Resizing the windows from within a Java plugin seem to work undesirably
about 40% of the time.  The undesirable effects tend to be consistent,
e.g., the second,third, and fifth windows exhibit the same effect each
time the plugin is run.  I suspect that the issue is some sort of a race
condition between ImageJ and Java/System GUI proper, as the symptoms vary
somewhat with load and computer.

The symptoms include:
Window has slightly wrong size and image appears to be the correct
magnification.
Window has correct size and the image is original size.

Both these statements produce these results:
IJ.run("In [+]", "");
IJ.run("Set... ", "zoom=200");

I have found that after show(ing) all the windows if I ...
      Dimension ws = imps[0].getWindow().getSize();
      for(ImagePlus imp : imps)
         imp.getWindow().setSize(ws.width,ws.height);
      for(ImagePlus imp : imps)
         imp.getWindow().getCanvas().fitToWindow();
This seems to adjust the window and image sizes appropriately most of the
time.

Is there a recommended way to zoom a window programmatically that works
consistently and correctly like it does from Image>Zoom>... ?

Thanks in advance,

Fred

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

Re: Programatic(Java) zooming issue(s)

Herbie
Dear Fred,

since long I successfully use

if ( imp.getRoi() != null )
   new Zoom().run( "to" );

and have never ever encountered any of the described effects.

Regards

Herbie

::::::::::::::::::::::::::::::::::::::::
Am 01.04.21 um 04:09 schrieb Fred Damen:

> Greetings,
>
> Resizing image windows thru the GUI seems to always work as expected.
> Resizing the windows from within a Java plugin seem to work undesirably
> about 40% of the time.  The undesirable effects tend to be consistent,
> e.g., the second,third, and fifth windows exhibit the same effect each
> time the plugin is run.  I suspect that the issue is some sort of a race
> condition between ImageJ and Java/System GUI proper, as the symptoms vary
> somewhat with load and computer.
>
> The symptoms include:
> Window has slightly wrong size and image appears to be the correct
> magnification.
> Window has correct size and the image is original size.
>
> Both these statements produce these results:
> IJ.run("In [+]", "");
> IJ.run("Set... ", "zoom=200");
>
> I have found that after show(ing) all the windows if I ...
>        Dimension ws = imps[0].getWindow().getSize();
>        for(ImagePlus imp : imps)
>           imp.getWindow().setSize(ws.width,ws.height);
>        for(ImagePlus imp : imps)
>           imp.getWindow().getCanvas().fitToWindow();
> This seems to adjust the window and image sizes appropriately most of the
> time.
>
> Is there a recommended way to zoom a window programmatically that works
> consistently and correctly like it does from Image>Zoom>... ?
>
> Thanks in advance,
>
> Fred
>
> --
> 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: Programatic(Java) zooming issue(s)

Michael Schmid
In reply to this post by Fred Damen
Hi Fred,

at least with JavaScript, there is no such problem on my Linux machine
(which is usually susceptible to race conditions). It makes no
difference whether a CPU-demanding operation runs in the background or not.
Here is my JavaScript test:

imp = IJ.openImage("https://imagej.net/images/t1-rendering.zip");
imp = imp.crop("1-9");
imp.show();
IJ.run("Stack to Images", "");
//Thread.sleep(1000); //works with and without this
for (i=1; i<10;i++) {
   IJ.selectWindow("DUP_t1-rendering-000"+i);
   IJ.run("In [+]", "");
   // IJ.run("Set... ", "zoom=200"); //alternatively
}

One can even see that the display of the images is asynchronous: Some
images get zoomed while they are in the background.


ImageJ 1.53i28; Java 1.8.0_112 [64-bit]; Linux 4.4.0-206-generic; 53MB
of 10000MB (<1%)

Michael
________________________________________________________________
On 01.04.21 04:09, Fred Damen wrote:

> Greetings,
>
> Resizing image windows thru the GUI seems to always work as expected.
> Resizing the windows from within a Java plugin seem to work undesirably
> about 40% of the time.  The undesirable effects tend to be consistent,
> e.g., the second,third, and fifth windows exhibit the same effect each
> time the plugin is run.  I suspect that the issue is some sort of a race
> condition between ImageJ and Java/System GUI proper, as the symptoms vary
> somewhat with load and computer.
>
> The symptoms include:
> Window has slightly wrong size and image appears to be the correct
> magnification.
> Window has correct size and the image is original size.
>
> Both these statements produce these results:
> IJ.run("In [+]", "");
> IJ.run("Set... ", "zoom=200");
>
> I have found that after show(ing) all the windows if I ...
>        Dimension ws = imps[0].getWindow().getSize();
>        for(ImagePlus imp : imps)
>           imp.getWindow().setSize(ws.width,ws.height);
>        for(ImagePlus imp : imps)
>           imp.getWindow().getCanvas().fitToWindow();
> This seems to adjust the window and image sizes appropriately most of the
> time.
>
> Is there a recommended way to zoom a window programmatically that works
> consistently and correctly like it does from Image>Zoom>... ?
>
> Thanks in advance,
>
> Fred
>
> --
> 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: Programatic(Java) zooming issue(s)

JAMES,
              gregory (SANDWELL AND WEST BIRMINGHAM HOSPITALS NHS TRUST)
In reply to this post by Herbie
Hello ImageJ-ers.

I was pleased to read Fred's post about the zooming issue. I too encounter this problem quite regularly in the macro language. I was going to ask the community for help, but Fred beat me to it. (Thanks Fred).

As Fred says... The behaviour is seemingly random. Furthermore, it happens often with some of my macro scripts and never happens with other scripts. I can't see an obvious reason for the difference but it's *possible​* that having a line of code before the 'zoom' command helps. For example, the following code sometimes produces the zooming error...

selectWindow(title);
run("Set... ", "zoom=400");

I do not observe the zooming error in the following code...

selectWindow(title);
Matrix = getHeight();
run("Set... ", "zoom=400");

I would like to understand the problem better. It's also possible that I'm talking rubbish and I'm completely wrong about the 'fix'. I wonder if certain combinations of code are more likely to produce the error?

I'm keen to hear from more users to see if they are encountering similar issues and how they have fixed them... Or is it just me and Fred encountering the problem?

Greg.

__________________________________________
Gregory James
Clinical Scientist (Nuclear Medicine)
Department of Physics and Nuclear Medicine
City Hospital
Dudley Road
Birmingham
B18 7QH

0121 507 4043

________________________________
From: Herbie <[hidden email]>
Sent: 01 April 2021 08:53
To: [hidden email] <[hidden email]>
Subject: Re: Programatic(Java) zooming issue(s)

Dear Fred,

since long I successfully use

if ( imp.getRoi() != null )
   new Zoom().run( "to" );

and have never ever encountered any of the described effects.

Regards

Herbie

::::::::::::::::::::::::::::::::::::::::
Am 01.04.21 um 04:09 schrieb Fred Damen:

> Greetings,
>
> Resizing image windows thru the GUI seems to always work as expected.
> Resizing the windows from within a Java plugin seem to work undesirably
> about 40% of the time.  The undesirable effects tend to be consistent,
> e.g., the second,third, and fifth windows exhibit the same effect each
> time the plugin is run.  I suspect that the issue is some sort of a race
> condition between ImageJ and Java/System GUI proper, as the symptoms vary
> somewhat with load and computer.
>
> The symptoms include:
> Window has slightly wrong size and image appears to be the correct
> magnification.
> Window has correct size and the image is original size.
>
> Both these statements produce these results:
> IJ.run("In [+]", "");
> IJ.run("Set... ", "zoom=200");
>
> I have found that after show(ing) all the windows if I ...
>        Dimension ws = imps[0].getWindow().getSize();
>        for(ImagePlus imp : imps)
>           imp.getWindow().setSize(ws.width,ws.height);
>        for(ImagePlus imp : imps)
>           imp.getWindow().getCanvas().fitToWindow();
> This seems to adjust the window and image sizes appropriately most of the
> time.
>
> Is there a recommended way to zoom a window programmatically that works
> consistently and correctly like it does from Image>Zoom>... ?
>
> Thanks in advance,
>
> Fred
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html



This message originated from outside of NHSmail. Please do not click links or open attachments unless you recognise the sender and know the content is safe.


********************************************************************************************************************

This message may contain confidential information. If you are not the intended recipient please inform the
sender that you have received the message in error before deleting it.
Please do not disclose, copy or distribute information in this e-mail or take any action in relation to its contents. To do so is strictly prohibited and may be unlawful. Thank you for your co-operation.

NHSmail is the secure email and directory service available for all NHS staff in England and Scotland. NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and other accredited email services.

For more information and to find out how you can switch, https://portal.nhs.net/help/joiningnhsmail


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

Re: Programatic(Java) zooming issue(s)

Fred Damen
In reply to this post by Herbie
Greetings,

Thanks to the Zoom plugin suggestion and some free time to dig, it seems I
may be on to something, or may be just a WAG...

It seems as though the Java GUI proper classes do no fully initialize
their internals until the widget has reached a certain point in its being
brought to life, i.e., activated?.  (I base this on a newly created but
not yet displayed Dialog not knowing its default Font...) The ImagePlus
show method waits upwards of 2 seconds, if a macro is running, for the
ImageWindow's windowActivated callback to be called. I suspect that this
is due to the ImageCanvas's internals may not be completely valid until
setActivated is called...  nb, Java plugin(s) get no time buffer. The load
on my computer partially results from my inability to work on one thing at
a time, thus I have many many browser, etc windows open, resulting in a
noticeable delay in GUI interactions in general. Thus a more than 2 second
delay in a window opening would not be surprising.  Whenever the
ImageWindow finally opens, it seems that ImagePlus will properly set its
activated variable to true, but alas this fact is not revealed outside of
ImagePlus and impeads my testing this hypothesis.  Therefore when Zoom
queries the canvas size, etc, in an pre-activated window the eventual
results of the zoom are ...

If there is any validity to my guess, might I suggest:
a) Expose the activated state, i.e., isActivated ImagePlus method.
b) Zoom deals with a possibly not yet valid ImageCanavas.
c) ImagePlus show method with a magnification parameter
d) The notifyListeners(OPENED) call in ImagePlus show method moved to the
setActivated method.

Enjoy,

Fred


On Thu, April 1, 2021 2:53 am, Herbie wrote:

> Dear Fred,
>
> since long I successfully use
>
> if ( imp.getRoi() != null )
>    new Zoom().run( "to" );
>
> and have never ever encountered any of the described effects.
>
> Regards
>
> Herbie
>
> ::::::::::::::::::::::::::::::::::::::::
> Am 01.04.21 um 0:09 schrieb Fred Damen:
>> Greetings,
>>
>> Resizing image windows thru the GUI seems to always work as expected.
>> Resizing the windows from within a Java plugin seem to work undesirably
>> about 40% of the time.  The undesirable effects tend to be consistent,
>> e.g., the second,third, and fifth windows exhibit the same effect each
>> time the plugin is run.  I suspect that the issue is some sort of a race
>> condition between ImageJ and Java/System GUI proper, as the symptoms
>> vary
>> somewhat with load and computer.
>>
>> The symptoms include:
>> Window has slightly wrong size and image appears to be the correct
>> magnification.
>> Window has correct size and the image is original size.
>>
>> Both these statements produce these results:
>> IJ.run("In [+]", "");
>> IJ.run("Set... ", "zoom=200");
>>
>> I have found that after show(ing) all the windows if I ...
>>        Dimension ws = imps[0].getWindow().getSize();
>>        for(ImagePlus imp : imps)
>>           imp.getWindow().setSize(ws.width,ws.height);
>>        for(ImagePlus imp : imps)
>>           imp.getWindow().getCanvas().fitToWindow();
>> This seems to adjust the window and image sizes appropriately most of
>> the
>> time.
>>
>> Is there a recommended way to zoom a window programmatically that works
>> consistently and correctly like it does from Image>Zoom>... ?
>>
>> Thanks in advance,
>>
>> Fred
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> 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: Programatic(Java) zooming issue(s)

Wayne Rasband-2
In reply to this post by Fred Damen
> On Mar 31, 2021, at 10:09 PM, Fred Damen <[hidden email]> wrote:
>
> Greetings,
>
> Resizing image windows thru the GUI seems to always work as expected.
> Resizing the windows from within a Java plugin seem to work undesirably
> about 40% of the time.

Zooming image windows programmatically should work more reliably with the latest daily build (1.53j7). Most methods in the Zoom class now wait until the image window is activated.

Here is some JavaScript code that works as expected with the daily build and fails with earlier versions.

  IJ.run("Close All", "");
  img = IJ.openImage("https://imagej.net/images/blobs.gif");
  for (i=0; i<6; i++) {
     img2 = img.duplicate();
     img2.show();
     Zoom.set(img2, 2.5);
  }

-wayne


>  The undesirable effects tend to be consistent,
> e.g., the second,third, and fifth windows exhibit the same effect each
> time the plugin is run.  I suspect that the issue is some sort of a race
> condition between ImageJ and Java/System GUI proper, as the symptoms vary
> somewhat with load and computer.
>
> The symptoms include:
> Window has slightly wrong size and image appears to be the correct
> magnification.
> Window has correct size and the image is original size.
>
> Both these statements produce these results:
> IJ.run("In [+]", "");
> IJ.run("Set... ", "zoom=200");
>
> I have found that after show(ing) all the windows if I ...
>      Dimension ws = imps[0].getWindow().getSize();
>      for(ImagePlus imp : imps)
>         imp.getWindow().setSize(ws.width,ws.height);
>      for(ImagePlus imp : imps)
>         imp.getWindow().getCanvas().fitToWindow();
> This seems to adjust the window and image sizes appropriately most of the
> time.
>
> Is there a recommended way to zoom a window programmatically that works
> consistently and correctly like it does from Image>Zoom>... ?
>
> Thanks in advance,
>
> Fred

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html