Win8 Metro (C #) Digital Image Processing--2.58 Shuangfeng method image Binary

Source: Internet
Author: User

Original: Win8 Metro (C #) Digital Image Processing--2.58 Shuangfeng method image Binary

??

[ function name ]

?? binary image of Shuangfeng method ? WriteableBitmap ?? Peakshistogramthsegment (writeablebitmap? src)

        <summary>//Peaks histogram method of image segmention. </summary>//<param name= "src" >the source image.</param>//<returns></ret            urns> public static WriteableBitmap peakshistogramthsegment (writeablebitmap src)////Shuangfeng method threshold Split { 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 the histogram access variable int[] histvalues = new int[256];                Define Shuangfeng position variable H1,H2, corresponding grayscale variable t1,t2, Valley gray variable t int h1 = 0, h2 = 0, t1 = 0, t2 = 0, t = 255;                Define a threshold variable int Th = 0;              for (int j = 0; J < H; j + +)  {for (int i = 0, i < W; i++) {srcdata[i + j * W] = (in T) ((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);                    Histvalues[srcdata[i + J * w]]++;                    }} for (int i = 0; i < i++) {if (I < 129)  {if (histvalues[i] > T1) {h1                            = i;                        T1 = Histvalues[i];                        }} else {if (histvalues[i] > T2)                            {H2 = i;                        t2 = Histvalues[i]; }}} for (int n = h1; n <= H2; n+ +) {if (Histvalues[n] < T) {Th = n;                    t = Histvalues[n]; }} for (int j = 0; J < H; j + +) {for (int i = 0; I &lt ; 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.58 Shuangfeng method image Binary

Related Article

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.