Example #1
0
        public static Bitmap GaussianGap(Bitmap Orig, double Sigma1, double Sigma2)
        {
            Bitmap result = (Bitmap)Orig.Clone();

            Kernels.kerneldata sig1 = new Kernels.kerneldata(Kernels.GenerateGaussian, 3, Sigma1);
            Kernels.kerneldata sig2 = new Kernels.kerneldata(Kernels.GenerateGaussian, 3, Sigma2);
            int size = sig1.weights.GetLength(0);

            double[,] ggFilter = new double[size, size];
            for (int row = 0; row < size; row++)
            {
                for (int col = 0; col < size; col++)
                {
                    ggFilter[row, col] = (sig1.weights[row, col] - sig2.weights[row, col]) * size * size;
                }
            }

            double sum = 0;

            foreach (var num in ggFilter)
            {
                sum += num;
            }
            Convolver(result, ggFilter);
            return(result);
        }
Example #2
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 cmbKernels_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string SelItem = cmbKernels.SelectedItem.ToString();

            kernelselect = (Kernels.kerneldata)kernel.KernelsAvail[SelItem];
            if (kernelselect == null)
            {
                MessageBox.Show("Invalid Selection");
                return;
            }
            SetupKernel();
        }
 private void HPConvert_Click(object sender, RoutedEventArgs e)
 {
     kernelselect = kernelselect.ConvertToHP();
     SetupKernel();
 }