Re: API call for hyperstack to stack?

Posted by Michael Schmid on
URL: http://imagej.273.s1.nabble.com/API-call-for-hyperstack-to-stack-tp5023716p5023719.html

Hi Aryeh,

ok, I see the point of getting a handle to the ImagePlus that a command
returns.

Unfortunately, even if the HyperStackConverter.convertHSToStack(imp)
were public, in the current form it would not return the ImagePlus that
it creates, and it seems that the ImagePlus that it creates is always
displayed, even in BatchMode, because it gets displayed by 'new
StackWindow', not by the standard ImagePlus.show() method.
I think that this test macro should not display the image, but it does:
   setBatchMode(true);
   run("Mitosis (5D stack)");
   run("Hyperstack to Stack");

The other direction, "toHyperStack", has nice public methods that return
an ImagePlus.


Concerning:
 >> the ImageJ command finder (ctrl-L) tells you that the call to the
 >> class is
 >>   ij.plugin.HyperStackConverter("hstostack")
 > I do not understand how this would be used.
What I wanted to say is that this shows that the 'arg' String of the
'run' command is "hstostack".
So the IJ.run("Hyperstack to Stack") can be replaced by
   new HyperStackConverter().run("hstostack")
But it won't help because the problem of having the correct ImagePlus
remains the same.


Concerning timing issues:

I guess that timing issues are usually caused by delays in displaying
ImagePlus objects. When an ImagePlus gets displayed (which may be
asynchronous), the WindowActivated event makes it the active window, but
the program might in the meanwhile have made a different window active
and it may then access the wrong front window. This kind of problems
should be avoided in BatchMode for macros (where windows should not
become displayed), but

Anyhow, I have not seen such timing issues for quite some time; I have
the impression that ImageJ has become much better in this respect than
it was 10 years ago.


Best,

Michael
________________________________________________________________
On 16.07.20 14:33, Aryeh Weiss wrote:

> Hi Michael,
>
> Thank you for your reply.
>
> On 16/07/2020 14:59, Michael Schmid wrote:
>> Hi Aryeh,
>>
>> the ImageJ command finder (ctrl-L) tells you that the call to the
>> class is
>>   ij.plugin.HyperStackConverter("hstostack")
>> [you may have to enlarge the width of the 'Class' column to see it fully]
>>
> I do not understand how this would be used.
>
> Is it something like:
> hc = HyperStackConverter("hstostack")
>
> But then, what do I do with hc.
>
>> In the HyperStackConverter source code you will see that with
>> arg="hstostack", it calls the convertHSToStack(imp) method (line 289).
>> This method is not public, however.
>>
> So hc.convertHSToStack(imp) would not be possible.
>
>> Anyhow, the IJ.run method accepts an optional argument specifying the
>> input ImagePlus, so I see nothing bad in using
>>   IJ.run(imp, Hyperstack to Stack")
>>
> It works fine. I have had these issues with IJ.run calls:
>
> 1. If they create images, I have to grab those images after the call,
> since the image is not returned by the call.
>
> 2. There  are sometimes timing issues, where one must loop to wait for
> an output window to be opened. I have not seen that for a while but a
> few years ago it happened a lot.
>
> 3. Sometimes, an IJ.run(imp, "some command")  call will fail if I do not
> first do  imp.show() , because apparently the function needs to have the
> image in a window, and not just the ImagePlus.
>
> Besides that, when I succeed in replacing the IJ.run call will a direct
> call to the class.method, I feel that  I understand the API a little
> better.
> So I try to do things with fewer IJ.run calls
>
> Best regards
> --aryeh
>
>
>>
>> Michael
>> ________________________________________________________________
>> On 16.07.20 12:15, Aryeh Weiss wrote:
>>> The HyperStackConverter doc says that it
>>> Implements the "Stack to HyperStack", "RGB to HyperStack" and
>>> "HyperStack to Stack" commands.
>>>
>>> However, while I see three toHyperStack() methods, I do not see any
>>> toStack method, and I want to do Hypertack to Stack.
>>> I can do it with IJ.run, but I  am trying to replace IJ.run calls in
>>> my code.
>>>
>>> In the source
>>> https://imagej.nih.gov/ij/source/ij/plugin/HyperStackConverter.java
>>> I see code to do hyperstack to stack (covertHSToStack), but I do not
>>> know how to use it.
>>>
>>> What am I missing?
>>>
>>> Thanks in advance
>>> --aryeh
>>>
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
>

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