One-dimensional maximum entropy method of binary value

Source: Internet
Author: User

static int get1dmaxentropythreshold (const int* histgram, int const in_start, int const in_end) {int X, Y, Amou        NT = 0;        Double histgramd[256];        Double sumintegral, Entropyback, Entropyfore, maxentropy;        int MinValue = In_start, MaxValue = in_end;        int Threshold = 0; for (MinValue = In_start; MinValue < In_end && Histgram[minvalue] = = 0;        minvalue++); for (MaxValue = in_end; MaxValue > MinValue && histgram[minvalue] = = 0;        maxvalue--);          if (MaxValue = = MinValue) return MaxValue;      Only one color in the image if (MinValue + 1 = = MaxValue) return MinValue; There are only two colors in the image for (Y = MinValue; Y <= MaxValue;        y++) Amount + = Histgram[y]; Total number of pixels for (Y = MinValue; Y <= MaxValue;        y++) Histgramd[y] = (double) histgram[y]/Amount + 1e-17;        Maxentropy =-10000000; for (Y = MinValue + 1; Y < MaxValue;            y++) {sumintegral = 0; for (X = MinValue; X <= Y;            x + +) Sumintegral + = histgramd[x];            Entropyback = 0; for (X = MinValue; X <= Y;            x + +) Entropyback + = (-histgramd[x]/sumintegral * LOG (Histgramd[x]/sumintegral));            Entropyfore = 0; for (X = Y + 1; X <= MaxValue;            x + +) Entropyfore + = (-histgramd[x]/(1-sumintegral) * log (Histgramd[x]/(1-sumintegral)));                if (Maxentropy < Entropyback + Entropyfore) {Threshold = Y;            Maxentropy = Entropyback + Entropyfore;    }} return Threshold; }

  

One-dimensional maximum entropy method of binary value

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.