# Scaling down the modal value when thresholding

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.