Win8 Metro (C #) Digital image processing--2.57 image binary with one-dimensional maximum entropy method

Source: Internet
Author: User

Original: Win8 Metro (C #) Digital image processing--2.57 image binary with one-dimensional maximum entropy method



[ function name ]

    One-dimensional maximum entropy method image binary writeablebitmap  entropymaxthsegment ( writeablebitmap  src"

[ algorithm description ]

One-dimensional maximum entropy method image segmentation is to use the gray distribution density function of image to define the information entropy of image, by optimizing certain entropy

The criterion obtains the threshold value corresponding to the maximum entropy, thus the method of image segmentation.

Algorithm process:

1, for a grayscale image, the gray range is [0,l-1], the minimum gray level of the image is obtained , themaximum gray level max;

[ function Code ]

< Span style= "Font-family:calibri" >

       <summary>//Entropy Max method of image segmention. </summary>//<param name= "src" >the source iamge.</param>//<returns></ret             urns> public static WriteableBitmap entropymaxthsegment (WriteableBitmap src)////One-dimensional entropy maximum threshold segmentation { if (src! = null) {int w = src.                 Pixelwidth; int h = src.                 Pixelheight;                 WriteableBitmap dstimage = new WriteableBitmap (w, h); byte[] temp = src.                 Pixelbuffer.toarray (); Byte[] Tempmask = (byte[]) temp.                 Clone ();                 Defining grayscale image information storage variables int[] Srcdata = new int[w * h];                 Define a threshold variable int Th = 0;                 Define the histogram storage variable int[] histogram = new int[256];                 Define the Entropy value variable double Ht = 0.0;                 Double Hl = 0.0;                 Double sigma = 0.0;           Define grayscale Maximum variables      int max = 0;                 int min = 255;                 Define temporary variable Double t = 0.0, pt = 0.0, Tempmax = 0.0;                 int TEMPV = 0;                         for (int j = 0; J < H; j + +) {for (int i = 0; i < W; i++) { TEMPV = (int) ((double) tempmask[i * 4 + J * W * 4] * 0.114 + (double) tempmask[i * 4 + 1 + J * W * 4                         ] * 0.587 + (double) tempmask[i * 4 + 2 + J * W * 4] * 0.299);                         Srcdata[i + J * W] = TEMPV;                         histogram[tempv]++;                         if (TEMPV > Max) {max = TEMPV;                         } if (TEMPV < min) {min = TEMPV;                 }}} for (int i = min; i < Max; i++) {t = (double) ((Double) Histogram[i]/(Double) (w * h));                     if (T > 0.00000001) {Hl + =-T * MATH.LOG10 (T);                 } else continue; } for (int i = min; i < Max; i++) {t = (double) (double) histogram[                     I]/(double) (w * h));                     PT + = t;                         if (T > 0.00000001) {Ht + =-T * MATH.LOG10 (T);                         Sigma = Math.log10 (PT * (1-PT)) * ht/pt + (HL-HT)/(1-PT);                             if (Sigma > Tempmax) {tempmax = (int) sigma;                         Th = i;                 }} else continue;                    } for (int j = 0; J < H; j + +) { for (int i = 0; i < W; i++) {Temp[i * 4 + J * W * 4] = temp[i * 4 + 1 + j                     * W * 4] = temp[i * 4 + 2 + J * W * 4] = (byte) (Srcdata[i + j * W] < Th? 0:255);                 }} Stream Stemp = DstImage.PixelBuffer.AsStream ();                 Stemp.seek (0, Seekorigin.begin);                 Stemp.write (temp, 0, W * 4 * h);             return dstimage;             } else {return null; }         }

Win8 Metro (C #) Digital image processing--2.57 image binary with one-dimensional maximum entropy method

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.