Exemple #1
0
        /// <summary>
        /// Applies convolution matrix/kernel to image.
        /// i.e. edge detection.
        /// </summary>
        /// <param name="bitmap">Image to apply kernel to</param>
        /// <param name="convolutionType">Type of convolution</param>
        /// <returns>Bitmap with kernel applied</returns>
        public static Bitmap ApplyKernel(Bitmap bitmap, ConvolutionType convolutionType)
        {
            // Get convolution kernel to apply
            int[,] matrix = convolutionType.GetConvolutionMatrix();

            return(ApplyKernel(bitmap, matrix));
        }
        public void TestGetConvolutionMatrix()
        {
            ConvolutionType type = ConvolutionType.Smoothing;

            // 2D matrix
            int[,] matrix = type.GetConvolutionMatrix();

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    // Smoothing filter contains all 1's
                    Assert.AreEqual(1, matrix.GetValue(i, j));
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Applies convolution matrix/kernel to image.
 /// </summary>
 /// <typeparam name="T">Image type to process and return</typeparam>
 /// <param name="image">Image to apply kernel to</param>
 /// <param name="convolutionType">Type of convolution</param>
 /// <returns>Image with kernel applied</returns>
 public static T ApplyKernel <T>(T image, ConvolutionType convolutionType) where T : Image
 {
     return(ApplyKernel(image, convolutionType.GetConvolutionMatrix()));
 }