public BilateralFiltering(float[,] image, float sigmaD, float sigmaR)
        {
            this.image = image;
            int sigmaMax = (int)FastMath.Max(sigmaD, sigmaR);

            this.kernelRadius = (int)FastMath.Ceiling(2 * sigmaMax);


            float twoSigmaRSquared = 2 * sigmaR * sigmaR;

            int kernelSize = this.kernelRadius * 2 + 1;

            this.kernelD = new float[kernelSize, kernelSize];

            int center = (kernelSize - 1) / 2;

            for (int x = -center; x < -center + kernelSize; x++)
            {
                for (int y = -center; y < -center + kernelSize; y++)
                {
                    this.kernelD[x + center, y + center] = this.gauss(sigmaD, x, y);
                }
            }


            this.gaussSimilarity = new float[256];
            for (int i = 0; i < this.gaussSimilarity.Length; i++)
            {
                this.gaussSimilarity[i] = FastMath.Exp((float)-((i) / twoSigmaRSquared));
            }



            //rimage = cvCloneImage(image);
        }
Beispiel #2
0
        public BilateralFiltering(float[,] image, float sigmaD, float sigmaR)
        {
            this.image = image;
            var sigmaMax = (int)FastMath.Max(sigmaD, sigmaR);

            kernelRadius = (int)FastMath.Ceiling(2 * sigmaMax);

            var twoSigmaRSquared = 2 * sigmaR * sigmaR;

            var kernelSize = kernelRadius * 2 + 1;

            kernelD = new float[kernelSize, kernelSize];

            var center = (kernelSize - 1) / 2;

            for (var x = -center; x < -center + kernelSize; x++)
            {
                for (var y = -center; y < -center + kernelSize; y++)
                {
                    kernelD[x + center, y + center] = gauss(sigmaD, x, y);
                }
            }

            gaussSimilarity = new float[256];
            for (var i = 0; i < gaussSimilarity.Length; i++)
            {
                gaussSimilarity[i] = FastMath.Exp(-(i / twoSigmaRSquared));
            }

            //rimage = cvCloneImage(image);
        }
 private float gauss(float sigma, int x, int y)
 {
     return(FastMath.Exp(-((x * x + y * y) / (2 * sigma * sigma))));
 }