Beispiel #1
0
        private void InitGaussianDerivative(double standardDeviation, int order, double norm)
        {
            Debug.Assert(order >= 0);
            if (order == 0)
            {
                InitGaussian(standardDeviation, norm);
                return;
            }

            Debug.Assert(standardDeviation > 0.0);
            Gaussian gauss = new Gaussian(standardDeviation, order);

            // First calculate the required kernel size
            int radius = (int)(3.0 * standardDeviation + 0.5 * order + 0.5);

            if (radius == 0)
            {
                radius = 1;
            }
            kernel.Clear();
            kernel.Capacity = radius * 2 + 1;

            // Fill the kernel and calculate the DC component
            // introduced by truncation of the Gaussian
            double dc = 0.0;

            for (int x = -radius; x <= radius; ++x)
            {
                kernel.Add(gauss.Value(x));
                dc += kernel[kernel.Count - 1];
            }
            dc /= 2.0 * radius + 1.0;

            // Remove the DC component, but only if kernel correction
            // is permitted by a non-zero value for the norm
            if (norm != 0.0)
            {
                for (int i = 0; i < kernel.Count; ++i)
                {
                    kernel[i] -= dc;
                }
            }

            left  = -radius;
            right = radius;

            if (norm != 0.0)
            {
                Normalize(norm, order);
            }
            else
            {
                this.norm = 1.0;
            }

            // The best border treatment for Gaussian derivatives in repeat
            borderTreatment = BorderTreatmentMode.BorderTreatmentRepeat;
        }
Beispiel #2
0
        public void InitGaussian(double standardDeviation, double norm)
        {
            Debug.Assert(standardDeviation >= 0.0);
            Gaussian gauss = new Gaussian(standardDeviation);

            if (standardDeviation > 0.0)
            {
                int radius = (int)(3 * standardDeviation + 0.5);
                if (radius == 0)
                {
                    radius = 1;
                }
                kernel.Clear();
                kernel.Capacity = radius * 2 + 1;
                for (int x = -radius; x <= radius; ++x)
                {
                    kernel.Add(gauss.Value(x));
                }
                left  = -radius;
                right = radius;
            }
            else
            {
                kernel.Clear();
                kernel.Add(1.0);
                left  = 0;
                right = 0;
            }

            if (norm != 0.0)
            {
                Normalize(norm);
            }
            else
            {
                this.norm = 1.0;
            }

            // Best border treatment for Gaussians is clip
            borderTreatment = BorderTreatmentMode.BorderTreatmentClip;
        }