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