C#圖象處置之頭發檢測的辦法。本站提示廣大學習愛好者:(C#圖象處置之頭發檢測的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#圖象處置之頭發檢測的辦法正文
本文實例講述了C#圖象處置之頭發檢測的辦法。分享給年夜家供年夜家參考。詳細以下:
//發色檢測(YCbCr色彩空間) public Bitmap HairD(Bitmap a) { Rectangle rect = new Rectangle(0, 0, a.Width, a.Height); System.Drawing.Imaging.BitmapData bmpData = a.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); int stride = bmpData.Stride; unsafe { byte* pIn = (byte*)bmpData.Scan0.ToPointer(); byte* p; int R, G, B; double Cr, Cb,BrightV; for (int y = 0; y < a.Height; y++) { for (int x = 0; x < a.Width; x++) { p = pIn; R = p[2]; G = p[1]; B = p[0]; Cb = 128 - 37.797 * R / 255 - 74.203 * G / 255 + 112 * B / 255; Cr = 128 + 112 * R / 255 - 93.768 * G / 255 - 18.214 * B / 255; BrightV = (R + G + B) / 3; if (!(Cb >= 115 && Cb <= 141 && Cr >= 115 && Cr <= 143 && (R < 35))) { pIn[0] = (byte)255; pIn[1] = (byte)255; pIn[2] = (byte)255; } pIn += 3; } pIn += stride - a.Width * 3; } } a.UnlockBits(bmpData); return a; } //界說最小值函數 public double Min(double a, double b, double c) { double e = (a <= b ? a : b) <= c ? (a <= b ? a : b) : c; return e; } //界說最年夜值函數 public int Max(int a, int b, int c) { int e = (a >= b ? a : b) <= c ? c : (a >= b ? a : b); return e; }
成果圖象後果:
願望本文所述對年夜家的C#法式設計有所贊助。