static public void DeleteInnerEffects(ref Bitmap b, int minsize, ProgressBar p1) { int w = b.Width; int h = b.Height; bool[,] Visited = new bool[w, h]; bool[,] Pixels = new bool[w, h]; BitmapFilter.GetBitArrayFromBitmap(b, Pixels); DeleteInnerEffects(Pixels, minsize, w, h, p1); ImageConverter.BitmapFromBool(ref b, Pixels, w, h); }
public static bool EmbossLaplacian(Bitmap b) { ConvMatrix m = new ConvMatrix(); m.SetAll(-1); m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 0; m.Pixel = 4; m.Offset = 127; return(BitmapFilter.Conv3x3(b, m)); }
public static bool EdgeDetectQuick(Bitmap b) { ConvMatrix m = new ConvMatrix(); m.TopLeft = m.TopMid = m.TopRight = -1; m.MidLeft = m.Pixel = m.MidRight = 0; m.BottomLeft = m.BottomMid = m.BottomRight = 1; m.Offset = 127; return(BitmapFilter.Conv3x3(b, m)); }
public static void GrayScaleMedian(byte[,] InP, byte[,] OutP, int size, int w, int h, ProgressBar P1) { P1.Minimum = 0; P1.Maximum = w; P1.Value = 0; int[] curc = new int[size * size + 2]; int ind, R, G, B, k1, p1, C; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { ind = 0; for (int k = i - size / 2; k <= i + size / 2; k++) { for (int p = j - size / 2; p <= j + size / 2; p++) { k1 = k; p1 = p; while (k < 0) { k++; } while (k >= w) { k--; } while (p < 0) { p++; } while (p >= h) { p--; } curc[ind] = InP[k, p]; ind++; k = k1; p = p1; } } C = BitmapFilter.GetKth(curc, 0, size * size - 1, (size * size - 1) / 2, false, 256); OutP[i, j] = (byte)C; P1.Value = i; } } }
static public void DeleteInnerEffects(bool[,] Pixels, int minsize, int w, int h, ProgressBar p1) { MainForm.UpdateLabel("Improving binarization"); int pvalue = 0; p1.Value = 0; p1.Minimum = 0; p1.Maximum = w / 10; bool[,] Visited = new bool[w, h]; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (Pixels[i, j] == true) { continue; } if (Visited[i, j]) { continue; } int GetA = (BitmapFilter.GetBinaryArea(Pixels, i, j, w, h, Visited)); if (GetA < minsize) { BitmapFilter.FillBinaryArea(Pixels, i, j, w, h, true); } } pvalue++; if (pvalue == 10) { p1.Value++; pvalue = 0; } } }
public static unsafe void Median(Bitmap b, int size) { int[] curR = new int[size * size]; int[] curG = new int[size * size]; int[] curB = new int[size * size]; byte[,] rc = new byte[b.Width, b.Height]; byte[,] gc = new byte[b.Width, b.Height]; byte[,] bc = new byte[b.Width, b.Height]; ProgressBar progressBar1 = (ProgressBar)ProgressBar.FromHandle(MainForm.ProgressBr); progressBar1.Value = 0; progressBar1.Maximum = 2 * b.Width / 10; int pvalue = 0; Color c = new Color(); BitmapData bData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, b.PixelFormat); byte bitsPerPixel = (byte)Image.GetPixelFormatSize(b.PixelFormat); byte * scan0 = (byte *)bData.Scan0.ToPointer(); for (int i = 0; i < b.Width; i++) { for (int j = 0; j < b.Height; j++) { byte *data = scan0 + j * bData.Stride + i * bitsPerPixel / 8; rc[i, j] = data[2]; gc[i, j] = data[1]; bc[i, j] = data[0]; } pvalue++; if (pvalue == 10) { progressBar1.Value++; pvalue = 0; } } int ind, R, G, B, k1, p1; for (int i = 0; i < b.Width; i++) { for (int j = 0; j < b.Height; j++) { byte *data = scan0 + j * bData.Stride + i * bitsPerPixel / 8; ind = 0; for (int k = i - size / 2; k <= i + size / 2; k++) { for (int p = j - size / 2; p <= j + size / 2; p++) { k1 = k; p1 = p; while (k < 0) { k++; } while (k >= b.Width) { k--; } while (p < 0) { p++; } while (p >= b.Height) { p--; } curR[ind] = rc[k, p]; curG[ind] = gc[k, p]; curB[ind] = bc[k, p]; ind++; k = k1; p = p1; } } data[2] = (byte)(R = (byte)BitmapFilter.GetKth(curR, 0, size * size - 1, (size * size - 1) / 2, false, 256)); data[1] = (byte)(G = (byte)BitmapFilter.GetKth(curG, 0, size * size - 1, (size * size - 1) / 2, false, 256)); data[0] = (byte)(B = (byte)BitmapFilter.GetKth(curB, 0, size * size - 1, (size * size - 1) / 2, false, 256)); } pvalue++; if (pvalue == 10) { progressBar1.Value++; pvalue = 0; } } b.UnlockBits(bData); }