输入原图和二值化阀值对图像进行二值化
/// <summary> /// 图像二值化 /// </summary> /// <param name="original">原图</param> /// <param name="threshold">阀值</param> /// <returns></returns> public static Bitmap ImageBinaryzation(Bitmap original,int threshold) { Bitmap output = new Bitmap(original.Width, original.Height); for (int i = 0; i < original.Width; i++) { for (int j = 0; j < original.Height; j++) { Color c = original.GetPixel(i, j); int average = ((c.R + c.B + c.G) / 3); if (average > threshold) output.SetPixel(i, j, Color.Black); else output.SetPixel(i, j, Color.White); } } return output; }
评论前必须登录!
注册