On Tue, 19 Feb 2013, Gabriel Landini wrote:

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:
T=k;

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?

Hi,

The break statement is needed for cases where the smoothed historgram has a flat tail on the right hand side of the second peak. The test is satisfied in that case due to changing the latter ">" to a ">=" (which was needed to make sure that the test is satisfied in case there is a flat area between the two peaks).

These flat areas do not occur with most images, but with simple images like the one I used as an example in my previous email, it does happen, typically with a tail of zeros in the smoothed histogram. And when it does, without the break statement the threshold value that is returned is on the right hand side of the second peak, as opposed to between the peaks like it should.

--
Antti Niemistö DSc(Tech)              office: TE410
Research Fellow                       phone:  +358-40-849-0587 (GSM)
Department of Signal Processing               +358-3-3115-4989 (fax)
Tampere University of Technology      URI:    http://www.cs.tut.fi/~ant/

_______________________________________________
ImageJ-devel mailing list
[email protected]
http://imagej.net/mailman/listinfo/imagej-devel

Reply via email to