/// <summary> /// Sharpens an image /// </summary> /// <param name="Image">Image to manipulate</param> /// <returns>A SwiftBitmap image</returns> public static SwiftBitmap SharpenLess(this SwiftBitmap Image) { Contract.Requires<ArgumentNullException>(Image != null, "Image"); return Image.ApplyConvolutionFilter(new int[][]{ new int[] {-1, 0, -1}, new int[] {0, 7, 0}, new int[] {-1, 0, -1} }); }
/// <summary> /// Does smoothing using a box blur /// </summary> /// <param name="Image">Image to manipulate</param> /// <param name="Size">Size of the aperture</param> /// <returns>A SwiftBitmap object</returns> public static SwiftBitmap BoxBlur(this SwiftBitmap Image, int Size = 3) { Contract.Requires<ArgumentNullException>(Image != null, "Image"); int[][] TempFilter = new int[Size][]; for (int x = 0; x < Size; ++x) { TempFilter[x] = new int[Size]; for (int y = 0; y < Size; ++y) { TempFilter[x][y] = 1; } } return Image.ApplyConvolutionFilter(TempFilter); }
/// <summary> /// Creates the bump map /// </summary> /// <param name="Direction">Direction of the bump map</param> /// <param name="Image">Image to create a bump map from</param> /// <param name="Invert">Inverts the direction of the bump map</param> /// <returns>The resulting bump map</returns> public static SwiftBitmap BumpMap(this SwiftBitmap Image, Direction Direction = Direction.TopBottom, bool Invert = false) { Contract.Requires<ArgumentNullException>(Image != null, "Image"); int[][] EdgeDetectionFilter = null; if (Direction == Direction.TopBottom) { if (!Invert) { EdgeDetectionFilter = new int[][]{ new int[] {1, 2, 1}, new int[] {0, 0, 0}, new int[] {-1, -2, -1} }; } else { EdgeDetectionFilter = new int[][]{ new int[] {-1, -2, -1}, new int[] {0, 0, 0}, new int[] {1, 2, 1} }; } } else { if (!Invert) { EdgeDetectionFilter = new int[][]{ new int[] {-1, 0, 1}, new int[] {-2, 0, 2}, new int[] {-1, 0, 1} }; } else { EdgeDetectionFilter = new int[][]{ new int[] {1, 0, -1}, new int[] {2, 0, -2}, new int[] {1, 0, -1} }; } } return Image.ApplyConvolutionFilter(EdgeDetectionFilter, false, 127).BlackAndWhite(); }
/// <summary> /// Sobel emboss function /// </summary> /// <param name="Image">Image to manipulate</param> /// <returns>A SwiftBitmap image</returns> public static SwiftBitmap SobelEmboss(this SwiftBitmap Image) { Contract.Requires<ArgumentNullException>(Image != null, "Image"); return Image.ApplyConvolutionFilter(new int[][]{ new int[] {-1, 0, 1}, new int[] {-2, 0, 2}, new int[] {-1, 0, 1} }, offset: 127); }