示例#1
0
        public static Bitmap Gradient(Bitmap origImageBMP)
        {
            Bitmap Dx = (Bitmap)origImageBMP.Clone();
            Bitmap Dy = (Bitmap)origImageBMP.Clone();

            Bitmap result = new Bitmap(Dx.Width, Dx.Height);

            Kernels kernel = new Kernels();

            Kernels.kerneldata kDx = (Kernels.kerneldata)kernel.KernelsAvail["First Derivative x"];
            Kernels.kerneldata kDy = (Kernels.kerneldata)kernel.KernelsAvail["First Derivative y"];
            ImageProcessing.Convolver(Dx, kDx.weights);
            ImageProcessing.Convolver(Dy, kDy.weights);


            for (int x = 0; x < Dx.Width; x++)
            {
                for (int y = 0; y < Dx.Height; y++)
                {
                    Color b1color = Dx.GetPixel(x, y);
                    Color b2color = Dy.GetPixel(x, y);

                    int blue  = (int)Math.Ceiling(Math.Sqrt(Math.Pow(b1color.B, 2) + Math.Pow(b2color.B, 2)));
                    int green = (int)Math.Ceiling(Math.Sqrt(Math.Pow(b1color.G, 2) + Math.Pow(b2color.G, 2)));
                    int red   = (int)Math.Ceiling(Math.Sqrt(Math.Pow(b1color.R, 2) + Math.Pow(b2color.R, 2)));;

                    blue  = (int)Math.Min(Math.Max(blue, 0), 255);
                    green = (int)Math.Min(Math.Max(green, 0), 255);
                    red   = (int)Math.Min(Math.Max(red, 0), 255);

                    result.SetPixel(x, y, Color.FromArgb(red, green, blue));
                }
            }
            return(result);
        }
 private void GetDefinedKernels()
 {
     Kernels = new List <string>();
     kernel  = new Kernels();
     foreach (string k in kernel.KernelsAvail.Keys)
     {
         Kernels.Add(k);
     }
     cmbKernels.ItemsSource = Kernels.OrderBy(x => x);
 }
        private void Test_OnClick(object sender, RoutedEventArgs e)
        {
            Kernels kernel = new Kernels();

            kernel.test();
        }