Win8 Metro (C #) Digital Image processing--2.51 image statistics filtering algorithm

Source: Internet
Author: User

Original: Win8 Metro (C #) Digital Image processing--2.51 image statistical filtering algorithm

??

[ function name ]

? ? image statistics filter ??? WriteableBitmap ? Statisticalfilter ( writeablebitmap ? src, Double ? T)

<summary>//statistical filtering process. </summary>//<param name= "src" >the source image.</param>//<param name= "T" >t He threshould to adjust filter effect.</param>//<returns></returns> public static Write                Ablebitmap statisticalfilter (writeablebitmap src,double T)////Image Statistics Filter {if (src! = null) { int w = src.                Pixelwidth; int h = src.                Pixelheight;                WriteableBitmap srcimage = new WriteableBitmap (w, h); byte[] temp = src.                Pixelbuffer.toarray (); Byte[] Tempmask = (byte[]) temp.                Clone ();                Double mean = 0;                Double std = 0;                int[] Windowvalue = new INT[9];                Double MR = 0;                Double MG = 0;                Double MB = 0; for (int j = 1; j < H-1; J + +) {for (int i = 1; i < W1; i++) {windowvalue[0] = (int) (tempmask[(i-1) * 4 + (j-1) * W * 4] * 0.114 +                        tempmask[(i-1) * 4 + 1 + (j-1) * W * 4] * 0.587 + tempmask[(i-1) * 4 + 2 + (j-1) * W * 4] * 0.299);  WINDOWVALUE[1] = (int) (TEMPMASK[I * 4 + (j-1) * W * 4] * 0.114 + tempmask[i * 4 + 1 + (j-1) * W * 4] * 0.587                        + tempmask[i * 4 + 2 + (j-1) * W * 4] * 0.299); WINDOWVALUE[2] = (int) (tempmask[(i + 1) * 4 + (j-1) * W * 4] * 0.114 + tempmask[(i + 1) * 4 + 1 + (j-1) * W * 4] * 0.5                        + tempmask[(i + 1) * 4 + 2 + (j-1) * W * 4] * 0.299);  WINDOWVALUE[3] = (int) (tempmask[(i-1) * 4 + J * W * 4] * 0.114 + tempmask[(i-1) * 4 + 1 + J * W * 4] * 0.587 + tempmask[(i                        -1) * 4 + 2 + J * W * 4] * 0.299); WINDOWVALUE[4] = (int) (Tempmask[i * 4 + J * W * 4] * 0.114 + tempmask[i * 4 + 1 + J * W * 4] * 0.587 + tempmask[i * 4 + 2                        + J * W * 4] * 0.299); WindOWVALUE[5] = (int) (tempmask[(i + 1) * 4 + J * W * 4] * 0.114 + tempmask[(i + 1) * 4 + 1 + J * W * 4] * 0.587 + tempmask[(i                        + 1) * 4 + 2 + J * W * 4] * 0.299); WINDOWVALUE[6] = (int) (tempmask[(i-1) * 4 + (j + 1) * W * 4] * 0.114 + tempmask[(i-1) * 4 + 1 + (j + 1) * W * 4] * 0.5                        + tempmask[(i-1) * 4 + 2 + (j + 1) * W * 4] * 0.299); WINDOWVALUE[7] = (int) (TEMPMASK[I * 4 + (j + 1) * W * 4] * 0.114 + tempmask[i * 4 + 1 + (j + 1) * W * 4] * 0.587 + tempmas                        K[i * 4 + 2 + (j + 1) * W * 4] * 0.299); WINDOWVALUE[8] = (int) (tempmask[(i + 1) * 4 + (j + 1) * W * 4] * 0.114 + tempmask[(i + 1) * 4 + 1 + (j + 1) * W * 4] * 0.5                        + tempmask[(i + 1) * 4 + 2 + (j + 1) * W * 4] * 0.299); for (int n = 0; n < 9; n++) {mean + = (double) ((double) (windowvalue[n                        ])/9);               } for (int n = 0; n < 9; n++)         {std + = Math.pow ((double) (windowvalue[n])-mean, 2)/9;                            } if (Windowvalue[4] >= T * MATH.SQRT (STD)) { for (int k =-1, k < 2; k++) {for (int m =-1; m < 2; m++                      ) {MB + = (double) tempmask[(i + M) * 4 + (j + k) * W * 4]/9;                      MG + = (double) tempmask[(i + M) * 4 + 1 + (j + k) * W * 4]/9;                                MR + = (double) tempmask[(i + M) * 4 + 2 + (j + k) * W * 4]/9;                            }} Temp[i * 4 + J * W * 4] = (byte) MB;                            Temp[i * 4 + 1 + J * W * 4] = (byte) MG;                        Temp[i * 4 + 2 + J * W * 4] = (byte) MR;                        } mean = 0;         std = 0;               MR = MG = MB = 0;                }} Stream Stemp = SrcImage.PixelBuffer.AsStream ();                Stemp.seek (0, Seekorigin.begin);                Stemp.write (temp, 0, W * 4 * h);            return srcimage;            } else {return null; }        }

Win8 Metro (C #) Digital Image processing--2.51 image statistics filtering algorithm

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.