public static Binary ( |
||
img | ||
return |
public static Bitmap Binary(Bitmap img)
{
int width = img.Width;
int height = img.Height;
BitmapData bdata = img.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite,
PixelFormat.Format32bppRgb);
unsafe
{
byte* start = (byte*)bdata.Scan0.ToPointer();
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if (start[0] != 255)
{
start[0] = start[1] = start[2] = 0;
}
start += 4;
}
start += bdata.Stride - width * 4;
}
}
img.UnlockBits(bdata);
return img;
}
/// <summary> /// 二值化处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_binary_Click(object sender, EventArgs e) { //去噪处理后的图片 Image imgBinary = (Image)pb_noise.Image.Clone(); //int v2 = ccccccmd.ImageHelper.ComputeThresholdValue((Bitmap)imgBinary); // int v2 = ImageProcess.ComputeThresholdValue((Bitmap)imgBinary); // imgBinary = ImageProcess.PBinary((Bitmap)imgBinary, v2); imgBinary = ImageProcess.Binary((Bitmap)imgBinary); imgBinaried = Image2Num((Bitmap)imgBinary); WriteToFile(imgBinaried, "experiment\\" + Path.GetFileNameWithoutExtension(imgurl) + "_binaried.txt"); pb_noise_binary.Image = imgBinary; }