I have a piece of code that I am translating and I am trying to understand the reasoning behind it. The application here is thresholding medical (cellular) images.

The function in question takes a histogram and returns the lower threshold value. The bit of code that I am translating mutates the histogram in a way that I do not fully understand.

It first finds the mode of the histogram. It then finds the signal which appears most often which is not the mode (i.e., the signal which appears most often behind the mode). I'll just call that the "secondary signal".

If the modal value appears more than twice the number of times as secondary signal, the modal value is scaled down to 1.5 times the modal value. For example:

mode = find_mode(hist);
second_max = 0;
for(int i = 0; i < hist.length; ++i) {
    if(hist[i] > second_max && i != mode) {
        second_max = hist[i];

max = hist[mode];
if(max > secondary_max * 2 && secondary_max > 0) {
    hist[mode] = secondary_max * 1.5;

My problem is the "magic" behind that 1.5 number as well as the logic behind scaling only when the modal value is > 2 times the secondary signal.

I realize that this results in a higher threshold value and I assume that it is to compensate for noise (move the floor and next signal closer together), but I just don't know if these constants are well understood or if they were just chosen via experimentation on some unknown data set.

BTW, the developer is unreachable and I'm the only one here who knows anything about image processing... but I'm no expert, hence me coming here.


1 Answer 1


Most likely this is chosen by experimental results. Seems like for the algorithm to scceed it needs a value that is lower than the modal value. But not significantly lower (this is where the 1.5 scaling factor comes in).

I suggest trying the mid-range value and its variants to see how that works. You might be able to skip the scaling procedure. mid-range = (max value + min value)/2

  • $\begingroup$ After some more digging I think you're right. Thanks. $\endgroup$ Sep 13, 2013 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.