/// <summary> /// Sets up the edge detection filter /// </summary> protected void CreateFilter() { EdgeDetectionFilter = new Filter(3, 3); if (Direction == Direction.TopBottom) { if (!Invert) { EdgeDetectionFilter.MyFilter[0, 0] = 1; EdgeDetectionFilter.MyFilter[1, 0] = 2; EdgeDetectionFilter.MyFilter[2, 0] = 1; EdgeDetectionFilter.MyFilter[0, 1] = 0; EdgeDetectionFilter.MyFilter[1, 1] = 0; EdgeDetectionFilter.MyFilter[2, 1] = 0; EdgeDetectionFilter.MyFilter[0, 2] = -1; EdgeDetectionFilter.MyFilter[1, 2] = -2; EdgeDetectionFilter.MyFilter[2, 2] = -1; } else { EdgeDetectionFilter.MyFilter[0, 0] = -1; EdgeDetectionFilter.MyFilter[1, 0] = -2; EdgeDetectionFilter.MyFilter[2, 0] = -1; EdgeDetectionFilter.MyFilter[0, 1] = 0; EdgeDetectionFilter.MyFilter[1, 1] = 0; EdgeDetectionFilter.MyFilter[2, 1] = 0; EdgeDetectionFilter.MyFilter[0, 2] = 1; EdgeDetectionFilter.MyFilter[1, 2] = 2; EdgeDetectionFilter.MyFilter[2, 2] = 1; } } else { if (!Invert) { EdgeDetectionFilter.MyFilter[0, 0] = -1; EdgeDetectionFilter.MyFilter[0, 1] = -2; EdgeDetectionFilter.MyFilter[0, 2] = -1; EdgeDetectionFilter.MyFilter[1, 0] = 0; EdgeDetectionFilter.MyFilter[1, 1] = 0; EdgeDetectionFilter.MyFilter[1, 2] = 0; EdgeDetectionFilter.MyFilter[2, 0] = 1; EdgeDetectionFilter.MyFilter[2, 1] = 2; EdgeDetectionFilter.MyFilter[2, 2] = 1; } else { EdgeDetectionFilter.MyFilter[0, 0] = 1; EdgeDetectionFilter.MyFilter[0, 1] = 2; EdgeDetectionFilter.MyFilter[0, 2] = 1; EdgeDetectionFilter.MyFilter[1, 0] = 0; EdgeDetectionFilter.MyFilter[1, 1] = 0; EdgeDetectionFilter.MyFilter[1, 2] = 0; EdgeDetectionFilter.MyFilter[2, 0] = -1; EdgeDetectionFilter.MyFilter[2, 1] = -2; EdgeDetectionFilter.MyFilter[2, 2] = -1; } } EdgeDetectionFilter.Offset = 127; }
/// <summary> /// Sets up the edge detection filter /// </summary> private void CreateFilter() { try { _EdgeDetectionFilter = new Filter(3, 3); if (_Direction == Direction.TopBottom) { if (!_Invert) { _EdgeDetectionFilter.MyFilter[0, 0] = 1; _EdgeDetectionFilter.MyFilter[1, 0] = 2; _EdgeDetectionFilter.MyFilter[2, 0] = 1; _EdgeDetectionFilter.MyFilter[0, 1] = 0; _EdgeDetectionFilter.MyFilter[1, 1] = 0; _EdgeDetectionFilter.MyFilter[2, 1] = 0; _EdgeDetectionFilter.MyFilter[0, 2] = -1; _EdgeDetectionFilter.MyFilter[1, 2] = -2; _EdgeDetectionFilter.MyFilter[2, 2] = -1; } else { _EdgeDetectionFilter.MyFilter[0, 0] = -1; _EdgeDetectionFilter.MyFilter[1, 0] = -2; _EdgeDetectionFilter.MyFilter[2, 0] = -1; _EdgeDetectionFilter.MyFilter[0, 1] = 0; _EdgeDetectionFilter.MyFilter[1, 1] = 0; _EdgeDetectionFilter.MyFilter[2, 1] = 0; _EdgeDetectionFilter.MyFilter[0, 2] = 1; _EdgeDetectionFilter.MyFilter[1, 2] = 2; _EdgeDetectionFilter.MyFilter[2, 2] = 1; } } else { if (!_Invert) { _EdgeDetectionFilter.MyFilter[0, 0] = -1; _EdgeDetectionFilter.MyFilter[0, 1] = -2; _EdgeDetectionFilter.MyFilter[0, 2] = -1; _EdgeDetectionFilter.MyFilter[1, 0] = 0; _EdgeDetectionFilter.MyFilter[1, 1] = 0; _EdgeDetectionFilter.MyFilter[1, 2] = 0; _EdgeDetectionFilter.MyFilter[2, 0] = 1; _EdgeDetectionFilter.MyFilter[2, 1] = 2; _EdgeDetectionFilter.MyFilter[2, 2] = 1; } else { _EdgeDetectionFilter.MyFilter[0, 0] = 1; _EdgeDetectionFilter.MyFilter[0, 1] = 2; _EdgeDetectionFilter.MyFilter[0, 2] = 1; _EdgeDetectionFilter.MyFilter[1, 0] = 0; _EdgeDetectionFilter.MyFilter[1, 1] = 0; _EdgeDetectionFilter.MyFilter[1, 2] = 0; _EdgeDetectionFilter.MyFilter[2, 0] = -1; _EdgeDetectionFilter.MyFilter[2, 1] = -2; _EdgeDetectionFilter.MyFilter[2, 2] = -1; } } _EdgeDetectionFilter.Offset = 127; } catch (Exception e) { throw e; } }
/// <summary> /// Sobel emboss function /// </summary> /// <param name="Image">Image to manipulate</param> /// <returns>A bitmap image</returns> public static Bitmap SobelEmboss(Bitmap Image) { Filter TempFilter = new Filter(3, 3); TempFilter.MyFilter[0, 0] = -1; TempFilter.MyFilter[0, 1] = 0; TempFilter.MyFilter[0, 2] = 1; TempFilter.MyFilter[1, 0] = -2; TempFilter.MyFilter[1, 1] = 0; TempFilter.MyFilter[1, 2] = 2; TempFilter.MyFilter[2, 0] = -1; TempFilter.MyFilter[2, 1] = 0; TempFilter.MyFilter[2, 2] = 1; TempFilter.Offset = 127; return TempFilter.ApplyFilter(Image); }
/// <summary> /// Does smoothing using a box blur /// </summary> /// <param name="Image">Image to manipulate</param> /// <param name="Size">Size of the aperture</param> public static Bitmap BoxBlur(Bitmap Image, int Size) { Filter TempFilter = new Filter(Size, Size); for (int x = 0; x < Size; ++x) { for (int y = 0; y < Size; ++y) { TempFilter.MyFilter[x, y] = 1; } } return TempFilter.ApplyFilter(Image); }
/// <summary> /// Sharpen focus function /// </summary> /// <param name="Image">Image to manipulate</param> /// <returns>A bitmap image</returns> public static Bitmap SharpenLess(Bitmap Image) { Filter TempFilter = new Filter(3, 3); TempFilter.MyFilter[0, 0] = -1; TempFilter.MyFilter[0, 1] = 0; TempFilter.MyFilter[0, 2] = -1; TempFilter.MyFilter[1, 0] = 0; TempFilter.MyFilter[1, 1] = 7; TempFilter.MyFilter[1, 2] = 0; TempFilter.MyFilter[2, 0] = -1; TempFilter.MyFilter[2, 1] = 0; TempFilter.MyFilter[2, 2] = -1; return TempFilter.ApplyFilter(Image); }