[ImageJ-devel] Fwd: Hist thresh toolbox license question

Gabriel Landini G.Landini at bham.ac.uk
Tue Feb 19 05:08:58 CST 2013

On Monday 18 Feb 2013 22:01:14 Antti Niemistö wrote:
> It seems like your ported version does not produce the correct threshold
> between the two peaks in the smoothed histogram in certain cases where you
> have flat areas in the smoothed histogram.
> For example, try this one.
> I = 40*ones(40);
> I(10:30,10:30) = 120;
> T = th_minimum(I);
> You'll find the threshold becomes 121. This is of course not between the
> two peaks at 40 and 120.
> The code in v1.02 did not assign any value to the threshold in this
> example case and in similar cases, so it clearly needed to be fixed.
> I now realize that a much more elegant fix than what I put in v1.03 would
> be this (gives T=41 in my simple example):
> for k = 2:n
>    if y(k-1) > y(k) & y(k+1) >= y(k)
>      T = k-1;
>      break
>    end
> end
> The "break" from the loop is essential, in addition to changing the latter
> ">" to a ">=". I would definitely use this code in your port.

Hi again,
Barry: I seem to have discussed this with Antti that in matlab the arrays 
start at 1, so the counts for greyscale 0 are in the index 1.
So for the Java version, the threshold should be set at:

You want the threshold at y(k), that bin should be smaller than y(k-1).
BTW that is what the current IJ plugin does. Antti codes compensates for the 
indexes starting at 1. IJ does not need that.

And do you really need the Break statement?
If there are 2 peaks guaranteed, then a 2nd instance of the test would not be 
found. Or am I wrong?


More information about the ImageJ-devel mailing list