WaitForUser problem

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

WaitForUser problem

Ben G
I made up two macro files a) and b).  They are separate files.

I open them both in IJ and run them one at a time.  I decided to put them sequentially into a single file - maco a) and macro b).  When I install the macro and run it, macro a) works fine and macro b) crashes with a nonsensical error message that expects a ")" in the middle of a P=nSlice kind of statement.

After spending a week fighting with this bug (and using the pgms separately), I tried again and found the bug. For trouble shooting my code, I wrote a simply Pause function shown below.

function P(){waitForUser("Press any key to continue");}

located inside the end of each macro.

The function works fine in the separate macros.  After getting the macros working OK, I removed all calls to the function, but left the functions sitting there in a) and b).  

The fix to all the problems was to delete the code from a), then everything worked fine.
Reply | Threaded
Open this post in threaded view
|

Re: WaitForUser problem

dscho
Hi,

On Wed, 5 Nov 2008, Ben G wrote:

> [...] When I install the macro and run it, macro a) works fine and macro
> b) crashes with a nonsensical error message that expects a ")" in the
> middle of a P=nSlice kind of statement.
>
> After spending a week fighting with this bug (and using the pgms
> separately), I tried again and found the bug. For trouble shooting my code,
> I wrote a simply Pause function shown below.
>
> function P(){waitForUser("Press any key to continue");}
>
> located inside the end of each macro.

Just a guess: you try to assign to the variable "P" after defining a
function of the same name?

I think that is a bug in your macro.  Never use the same name for a
function _and_ for a variable.

Hth,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: WaitForUser problem

Ben G
You are probably right, but some aspects of this I don't understand.

1. Why wouldn't there be an error message?
2. I had deleted all calls to the function, only the function remained
3. Each separate macro ran fine with all the calls and function active
4. It only crashed when I put the two macros into one file.  At this
point, all the calls had been deleted.

I find the macro wrapper to be confusing, with no documentation on what
happens when you put a program inside a macro.

It turns oout that EXIT is an easier dubugging tool for me anyway.

Thanks for your help.

Ben Gravely
----------------------------------------------------


Johannes Schindelin (via Nabble) wrote:

> Hi,
>
> On Wed, 5 Nov 2008, Ben G wrote:
>
> > [...] When I install the macro and run it, macro a) works fine and
> macro
> > b) crashes with a nonsensical error message that expects a ")" in the
> > middle of a P=nSlice kind of statement.
> >
> > After spending a week fighting with this bug (and using the pgms
> > separately), I tried again and found the bug. For trouble shooting
> my code,
> > I wrote a simply Pause function shown below.
> >
> > function P(){waitForUser("Press any key to continue");}
> >
> > located inside the end of each macro.
>
> Just a guess: you try to assign to the variable "P" after defining a
> function of the same name?
>
> I think that is a bug in your macro.  Never use the same name for a
> function _and_ for a variable.
>
> Hth,
> Dscho
>
>
> ------------------------------------------------------------------------
> This email is a reply to your post @
> http://n2.nabble.com/WaitForUser-problem-tp1461344p1464114.html
> You can reply by email or by visting the link above.
>

Reply | Threaded
Open this post in threaded view
|

Re: WaitForUser problem

dscho
Hi,

[please Cc: me at all times, I often have only time to read mails
addressed directly to me.]

On Thu, 6 Nov 2008, Ben G wrote:

> You are probably right, but some aspects of this I don't understand.
>
> 1. Why wouldn't there be an error message?

There was.

> 2. I had deleted all calls to the function, only the function remained

And by that you already assigned "something" to the name "P".

> 3. Each separate macro ran fine with all the calls and function active

You assigned the function at the end.

> I find the macro wrapper to be confusing, with no documentation on what
> happens when you put a program inside a macro.

I do not agree.

> It turns oout that EXIT is an easier dubugging tool for me anyway.

If that is better for you, you should definitely stick with it.

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Histogram manipultion

Ben G
In reply to this post by dscho
I want to examine the data inside a run("Histogram", "stack") command.
In particular, I want access to the "value" and "counts" data inside the
stack Histogram.

I want to use the data to calculate a high and low gray level bounding
the histogram.
I have looked at the getStatictics commands and they seem very inelegant
for my purpose.

For example, I can execute the run(Histogram... command above, then
click on LIST, which shows the data.
I would like a way to list and read the data by software commands.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Histogram manipultion

Wayne Rasband
On Dec 4, 2008, at 12:10 PM, Ben G wrote:

> I want to examine the data inside a run("Histogram", "stack") command.
> In particular, I want access to the "value" and "counts" data inside
> the
> stack Histogram.
>
> I want to use the data to calculate a high and low gray level bounding
> the histogram.
> I have looked at the getStatictics commands and they seem very
> inelegant
> for my purpose.
>
> For example, I can execute the run(Histogram... command above, then
> click on LIST, which shows the data.
> I would like a way to list and read the data by software commands.

You can retrieve the values displayed when you click the "List" button
in a histogram window using the Plot.getValues() macro function. Here
is an example:

     requires("1.41k");
     run("T1 Head (2.4M, 16-bits)");
     run("Histogram", "stack");
     Plot.getValues(counts, values);
     for (i=0; i< counts.length; i++)
         print(counts[i], values[i]);

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: Histogram manipultion

Gluender-2
In reply to this post by Ben G
>I want to examine the data inside a run("Histogram", "stack") command.
>In particular, I want access to the "value" and "counts" data inside the
>stack Histogram.
>
>I want to use the data to calculate a high and low gray level bounding
>the histogram.
>I have looked at the getStatictics commands and they seem very inelegant
>for my purpose.

What is inelegant with
        getHistogram(values, counts, nBins[, histMin, histMax])
and why don't you carefully read the doc "Built-in Macro Functions"

>
>For example, I can execute the run(Histogram... command above, then
>click on LIST, which shows the data.
>I would like a way to list and read the data by software commands.
>
>Thanks.
>
>--
>View this message in context:
>http://n2.nabble.com/WaitForUser-problem-tp1461344p1614389.html
>Sent from the ImageJ mailing list archive at Nabble.com.

hth
--

                   Herbie

          ------------------------
          <http://www.gluender.de>
Reply | Threaded
Open this post in threaded view
|

Histogram

Ben G
In reply to this post by dscho
Thanks for the posts.  From what I can tell the getHistogram command
will not do a stack, so the program requires a slice loop, a total
counts array, and a sum array, about 10 lines of code.  This is what I
mean by not elegant for a stack histogram.

I have already implemented this approach.

However, I have found another problem.  I don't get the same values when
I do the above code and run a stack histogram manually.

The slice loop code sets up an array of new bins and sums the counts
into them as each histogram is made.  The output is the sum of counts in
each bin for all slices.  I checked it out on a few slices and the math
is right.

When I manually run the Analysis/histogram/<include all images>, I get
different counts in the bins.

Maybe I don't understand what the Histogram Stack command does.


Ben
Reply | Threaded
Open this post in threaded view
|

Re: Histogram

Michael Schmid
Hi Ben,

your approach should work.

Maybe your macro has a bug?
One problem might be wrong addressing of stack slices. They are  
numbered 1...NSlices, not 0...(nSlices-1).

setSlice(0); will cause an error message, but
run("Set Slice...","slice=0"); will be simply ignored.

One problem that might occur with extremely large stacks is an  
integer overflow when adding to bins with more than roughly 2e9 pixels.
Analysis/histogram/<include all images> would suffer from this; the  
macro language uses double arrays and won't have this problem.


Michael
________________________________________________________________

On 4 Dec 2008, at 23:09, Ben G wrote:

> Thanks for the posts.  From what I can tell the getHistogram command
> will not do a stack, so the program requires a slice loop, a total
> counts array, and a sum array, about 10 lines of code.  This is what I
> mean by not elegant for a stack histogram.
>
> I have already implemented this approach.
>
> However, I have found another problem.  I don't get the same values  
> when
> I do the above code and run a stack histogram manually.
>
> The slice loop code sets up an array of new bins and sums the counts
> into them as each histogram is made.  The output is the sum of  
> counts in
> each bin for all slices.  I checked it out on a few slices and the  
> math
> is right.
>
> When I manually run the Analysis/histogram/<include all images>, I get
> different counts in the bins.
>
> Maybe I don't understand what the Histogram Stack command does.
>
>
> Ben
>