1. Description:
The algorithm is similar to the threshold based on Valley minimum, except that the last step is not to get the valley value between Shuangfeng, but to take the average of Shuangfeng as the threshold value.
2. Reference code: INT getintermodesthreshold (int * histgram)
{int Y, Iter = 0, Index; double* HISTGRAMC = new double[256]; Based on the accuracy problem, must use the floating point number to deal with, otherwise cannot get the correct result double* HISTGRAMCC = new double[256]; The process of averaging destroys the previous data, so it takes two copies of the data for (Y = 0; Y < 256;
y++) {Histgramc[y] = Histgram[y];
Histgramcc[y] = Histgram[y]; }//By averaging three points to smooth the histogram while (Isdimodal (HISTGRAMCC) = = False) Determine if it is already an image of Shuangfeng {histgramcc[0] = (Histgramc[0] + histgramc[0] + histgramc[1])/3; 1th for (Y = 1; Y < 255; y++) Histgramcc[y] = (Histgramc[y-1] + histgramc[y] + histgramc[y + 1])/3; Middle point histgramcc[255] = (histgramc[254] + histgramc[255] + histgramc[255])/3; Last point memcpy (HISTGRAMCC, HISTGRAMC, N. sizeof (double));
Backup data, prepare for the next iteration iter++; if (Iter >= 10000) Return-1;
It seems that the histogram cannot be smoothed to Shuangfeng, return error code}//Threshold value is the average of two peaks int* peak = new Int[2]; for (Y = 1, Index = 0; Y < 255; y++) if (Histgramcc[y-1] < Histgramcc[y] && Histgramcc[y + 1] < Histgramcc[y]) peak[index++] =
Y-1;
Return ((Peak[0] + peak[1])/2); }
BOOL Isdimodal (double* Histgram) //Check whether the histogram is Shuangfeng
{
//The peak of the histogram is counted, only the peak number bit 2 is Shuangfeng
int count = 0;
for (int Y = 1; Y < 255; y++)
{
if (Histgram[y-1] < Histgram[y] && Histgram[y + 1] < Histgram[y])
{
count++;
if (Count > 2) return false;
}
}
if (Count = = 2)
return true;
else
return false;
}