The principle and realization of image global two-valued algorithm based on histogram--threshold based on Shuangfeng average value

Source: Internet
Author: User
Tags error code

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;
    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.