API call for hyperstack to stack?

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

API call for hyperstack to stack?

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

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

Re: API call for hyperstack to stack?

Michael Schmid
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]

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.

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")


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

Re: API call for hyperstack to stack?

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


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

Re: API call for hyperstack to stack?

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

Re: API call for hyperstack to stack?

Aryeh Weiss
Hi Michael

Thank you for your reply.

In this case, there is no problem, because a new image is not created,
and nothing else needs to be returned.

I also found that when one wants to operate on a stack (for example,
clear inside an Roi), it is easier to use IJ.run,
because there is often a "stack" keyword that easily enables operation
on the stack.
Using the API calls, it is necessary to loop over the ImageProcessor of
each slice, while the IJ.run command will do it in one line.

Best regards
--aryeh

On 16/07/2020 18:07, Michael Schmid wrote:

> 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


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

Re: API call for hyperstack to stack?

Wayne Rasband-2
In reply to this post by Aryeh Weiss
> On Jul 16, 2020, at 6:15 AM, Aryeh Weiss <[hidden email]> 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  an 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.

The ImageJ 1.53d30 daily build adds a HyperStackConverter.toStack() method. Here is an example:

  imp = IJ.createImage("HyperStack", "8-bit color-mode label", 400, 300, 3, 4, 5);
  print("hyperstack: "+imp);
  HyperStackConverter.toStack(imp);
  print("stack: "+imp);
  imp.show();

Here is the output:

  hyperstack: img["HyperStack" (-7), 8-bit, 400x300x3x4x5]
  stack: img["HyperStack" (-7), 8-bit, 400x300x1x60x1]

-wayne

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

Re: API call for hyperstack to stack?

Aryeh Weiss
Thank you Wayne.

Works as advertised.

Best regards
--aryeh

On 16/07/2020 20:43, Wayne Rasband wrote:

>> On Jul 16, 2020, at 6:15 AM, Aryeh Weiss <[hidden email]> 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  an 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.
> The ImageJ 1.53d30 daily build adds a HyperStackConverter.toStack() method. Here is an example:
>
>    imp = IJ.createImage("HyperStack", "8-bit color-mode label", 400, 300, 3, 4, 5);
>    print("hyperstack: "+imp);
>    HyperStackConverter.toStack(imp);
>    print("stack: "+imp);
>    imp.show();
>
> Here is the output:
>
>    hyperstack: img["HyperStack" (-7), 8-bit, 400x300x3x4x5]
>    stack: img["HyperStack" (-7), 8-bit, 400x300x1x60x1]
>
> -wayne
>
> --
> 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