current window when using IJ.run() - Java

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

current window when using IJ.run() - Java

Kenneth Sloan-2
A question about running commands which depend on the current window.  Java plugin.

I have a Java plugin which generates several ImagePlus objects, and shows them.

The last one is an 8-bit image to which I want to apply a LUT.

I (naîvely?) assumed that the last ImagePlus.show() call would make that window the current one, so I tried:


                ...
                ip1.show();
                ip2.show();
                ip3.show();
                IJ.run("royal");

ip1 is an RGB image.
ip2 is a 32-bit float image.
ip3 is an 8-bit byte image.

My expectation was that the LUT would be applied to the 3rd image (the 8-bit byte image).  Instead, it was applied to
the 2nd image (the 32-bit float image).

I suspected some sort of race condition, so I tried this:
                ...
                ip1.show();
                ip2.show();
                ip3.show();
                WindowManager.setWindow(ip3.getWindow());
                IJ.run("royal");

No joy!  The LUT is *still* applied to ip2, the 32-bit float image.

What am I doing wrong?

For the time being, I'm leaving out the attempt to apply the LUT and simply telling the customer to use Image->Lookup Tables->royal
to get the color coding.  That has certain advantages, BUT...I'd really like to know how to do this automatically.

Do I need to explicitly load the LUT?  If so, what's the path to the pool of already installed LUTs? (needs to work across multiple platforms).

I dimly recall doing this year ago, but have forgotten the details.  At the time, I was constructing a custom LUT.  This time, I just want to use
one of the already installed LUT's.

--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.






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

Re: current window when using IJ.run() - Java

Gabriel Landini
Hi Kenneth,

I have used this:
                impT = IJ.createImage("RCC", "8-bit Black", nX, nY, 1);
                IJ.run(impT, "glasbey", "");

Hope it helps.

Gabriel


On Thursday, 25 October 2018 17:21:18 BST you wrote:

> A question about running commands which depend on the current window.  Java
> plugin.
>
> I have a Java plugin which generates several ImagePlus objects, and shows
> them.
>
> The last one is an 8-bit image to which I want to apply a LUT.
>
> I (naîvely?) assumed that the last ImagePlus.show() call would make that
> window the current one, so I tried:
>
>
>                 ...
>                 ip1.show();
>                 ip2.show();
>                 ip3.show();
>                 IJ.run("royal");
>
> ip1 is an RGB image.
> ip2 is a 32-bit float image.
> ip3 is an 8-bit byte image.
>
> My expectation was that the LUT would be applied to the 3rd image (the 8-bit
> byte image).  Instead, it was applied to the 2nd image (the 32-bit float
> image).
>
> I suspected some sort of race condition, so I tried this:
>                 ...
>                 ip1.show();
>                 ip2.show();
>                 ip3.show();
>                 WindowManager.setWindow(ip3.getWindow());
>                 IJ.run("royal");
>
> No joy!  The LUT is *still* applied to ip2, the 32-bit float image.
>
> What am I doing wrong?
>
> For the time being, I'm leaving out the attempt to apply the LUT and simply
> telling the customer to use Image->Lookup Tables->royal to get the color
> coding.  That has certain advantages, BUT...I'd really like to know how to
> do this automatically.
>
> Do I need to explicitly load the LUT?  If so, what's the path to the pool of
> already installed LUTs? (needs to work across multiple platforms).
>
> I dimly recall doing this year ago, but have forgotten the details.  At the
> time, I was constructing a custom LUT.  This time, I just want to use one
> of the already installed LUT's.
>
> --
> Kenneth Sloan
> [hidden email]
> Vision is the art of seeing what is invisible to others.
>
>
>
>
>
>
> --
> 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: current window when using IJ.run() - Java

Michael Schmid
In reply to this post by Kenneth Sloan-2
Hi Kenneth,

ImagePlus.show() is only for displaying the image for the first time. If
the image is already visible, it does nothing.
If the window was not visible before, I think that it becomes the
foreground image only after some delay (when it really becomes the
foreground window on the screen; this is asynchronous).

You need either

   ImageWindow win = imp.getWindow; // (imp is the ImagePlus)
   WindowManager.setCurrentWindow(ImageWindow win);

or one of the IJ.selectWindow methods (e.d. based on image id).

If you don't care whether the window appears as frontmost window on the
screen, simply use
   IJ.run(imp, "royal");


Michael
________________________________________________________________
On 25.10.18 18:21, Kenneth Sloan wrote:

> A question about running commands which depend on the current window.  Java plugin.
>
> I have a Java plugin which generates several ImagePlus objects, and shows them.
>
> The last one is an 8-bit image to which I want to apply a LUT.
>
> I (naîvely?) assumed that the last ImagePlus.show() call would make that window the current one, so I tried:
>
>
>                  ...
>                  ip1.show();
>                  ip2.show();
>                  ip3.show();
>                  IJ.run("royal");
>
> ip1 is an RGB image.
> ip2 is a 32-bit float image.
> ip3 is an 8-bit byte image.
>
> My expectation was that the LUT would be applied to the 3rd image (the 8-bit byte image).  Instead, it was applied to
> the 2nd image (the 32-bit float image).
>
> I suspected some sort of race condition, so I tried this:
>                  ...
>                  ip1.show();
>                  ip2.show();
>                  ip3.show();
>                  WindowManager.setWindow(ip3.getWindow());
>                  IJ.run("royal");
>
> No joy!  The LUT is *still* applied to ip2, the 32-bit float image.
>
> What am I doing wrong?
>
> For the time being, I'm leaving out the attempt to apply the LUT and simply telling the customer to use Image->Lookup Tables->royal
> to get the color coding.  That has certain advantages, BUT...I'd really like to know how to do this automatically.
>
> Do I need to explicitly load the LUT?  If so, what's the path to the pool of already installed LUTs? (needs to work across multiple platforms).
>
> I dimly recall doing this year ago, but have forgotten the details.  At the time, I was constructing a custom LUT.  This time, I just want to use
> one of the already installed LUT's.
>
> --
> Kenneth Sloan
> [hidden email]
> Vision is the art of seeing what is invisible to others.
>
>
>
>
>
>
> --
> 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: current window when using IJ.run() - Java

Kenneth Sloan-2
Thanks very much - this worked.
--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.





> On 25 Oct 2018, at 12:20 , Michael Schmid <[hidden email]> wrote:
>
> Hi Kenneth,
>
> ImagePlus.show() is only for displaying the image for the first time. If the image is already visible, it does nothing.
> If the window was not visible before, I think that it becomes the foreground image only after some delay (when it really becomes the foreground window on the screen; this is asynchronous).
>
> You need either
>
>  ImageWindow win = imp.getWindow; // (imp is the ImagePlus)
>  WindowManager.setCurrentWindow(ImageWindow win);
>
> or one of the IJ.selectWindow methods (e.d. based on image id).
>
> If you don't care whether the window appears as frontmost window on the screen, simply use
>  IJ.run(imp, "royal");
>
>
> Michael
> ________________________________________________________________
> On 25.10.18 18:21, Kenneth Sloan wrote:
>> A question about running commands which depend on the current window.  Java plugin.
>> I have a Java plugin which generates several ImagePlus objects, and shows them.
>> The last one is an 8-bit image to which I want to apply a LUT.
>> I (naîvely?) assumed that the last ImagePlus.show() call would make that window the current one, so I tried:
>>                 ...
>>                 ip1.show();
>>                 ip2.show();
>>                 ip3.show();
>>                 IJ.run("royal");
>> ip1 is an RGB image.
>> ip2 is a 32-bit float image.
>> ip3 is an 8-bit byte image.
>> My expectation was that the LUT would be applied to the 3rd image (the 8-bit byte image).  Instead, it was applied to
>> the 2nd image (the 32-bit float image).
>> I suspected some sort of race condition, so I tried this:
>>                 ...
>>                 ip1.show();
>>                 ip2.show();
>>                 ip3.show();
>>                 WindowManager.setWindow(ip3.getWindow());
>>                 IJ.run("royal");
>> No joy!  The LUT is *still* applied to ip2, the 32-bit float image.
>> What am I doing wrong?
>> For the time being, I'm leaving out the attempt to apply the LUT and simply telling the customer to use Image->Lookup Tables->royal
>> to get the color coding.  That has certain advantages, BUT...I'd really like to know how to do this automatically.
>> Do I need to explicitly load the LUT?  If so, what's the path to the pool of already installed LUTs? (needs to work across multiple platforms).
>> I dimly recall doing this year ago, but have forgotten the details.  At the time, I was constructing a custom LUT.  This time, I just want to use
>> one of the already installed LUT's.
>> --
>> Kenneth Sloan
>> [hidden email]
>> Vision is the art of seeing what is invisible to others.
>> --
>> 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