public static Bitmap ThresholdingWithGrayScaleLevel(Bitmap bmp, int p1, int p2) { var grayscale = BitmapHelper.ToGrayscale(bmp); for (int x = 0; x < grayscale.Width; x++) { for (int y = 0; y < grayscale.Height; y++) { if (grayscale.GetPixel(x, y).R <= p1 || grayscale.GetPixel(x, y).R >= p2) { grayscale.SetPixel(x, y, Color.FromArgb(0, 0, 0, 0)); } } } return(grayscale); }
public static Bitmap Rozciaganie(Bitmap b, int p1, int p2) { var bmp = BitmapHelper.ToGrayscale(b); for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) //if (p1 < p2) { if (bmp.GetPixel(x, y).R > p1 && bmp.GetPixel(x, y).R <= p2) { var av = ((bmp.GetPixel(x, y).R - p1) * ((256 - 1) / (p2 - p1))); bmp.SetPixel(x, y, Color.FromArgb(bmp.GetPixel(x, y).A, av, av, av)); } } } //else bmp[x, y] = 0; return(bmp); }
public static Bitmap Thresholding(Bitmap bmp, int value) { var grayscale = BitmapHelper.ToGrayscale(bmp); for (int x = 0; x < grayscale.Width; x++) { for (int y = 0; y < grayscale.Height; y++) { if (grayscale.GetPixel(x, y).R <= value) { grayscale.SetPixel(x, y, Color.FromArgb(0, 0, 0, 0)); } else { grayscale.SetPixel(x, y, Color.FromArgb(255, 255, 255, 255)); } } } return(grayscale); }