Algorithmix.Utility.Convolute C# (CSharp) Méthode

Convolute() public static méthode

Performs 1D convolution an a given input array xx, with a convolution kernel hh
public static Convolute ( double xx, double hh, int indicies ) : double[]
xx double series input
hh double convolution kernel
indicies int time index of the kernel
Résultat double[]
        public static double[] Convolute(double[] xx, double[] hh, int[] indicies)
        {
            double[] result = new double[xx.Length];

            //  Flip Shift and Aggregate
            for (int ii = 0; ii < xx.Length; ii++)
            {
                for (int jj = 0; jj < hh.Length; jj++)
                {
                    int index = (ii - indicies[jj]);
                    if (index >= 0 && index < xx.Length)
                    {
                        result[ii] += xx[index] * hh[jj];
                    }
                }
            }
            return result;
        }

Usage Example

Exemple #1
0
        /// <summary>
        ///   Create a shred object given a filepath to a bitmap image
        /// </summary>
        /// <param name="filepath"> destination path of the shred image </param>
        /// <param name="ignoreTopBottom"> Default is true, set to false to scan top and bottom aswell </param>
        public Shred(string filepath, bool ignoreTopBottom = true)
        {
            InitializeINode();
            Filepath = filepath;
            Id       = _count++;

            Logger.Trace("Starting Chamfer From Left");

            int directions = ignoreTopBottom ? 4 : 8;

            Convolution = new List <double[]>(directions);
            Luminousity = new List <double[]>(directions);
            Chamfer     = new List <int[]>(directions);
            Thresholded = new List <double[]>(directions);
            Sparsity    = new List <long>(directions);
            Offsets     = new List <int[]>(directions);

            using (Bitmap source = new Bitmap(filepath))
            {
                var image = new Image <Bgra, Byte>(source);

                // Initialize List for Random Access
                for (int ii = 0; ii < directions; ii++)
                {
                    Convolution.Add(new double[0]);
                    Luminousity.Add(new double[0]);
                    Thresholded.Add(new double[0]);
                    Chamfer.Add(new int[0]);
                    Sparsity.Add((long)-1.0);
                    Offsets.Add(new int[0]);
                }

                foreach (int side in Enum.GetValues(typeof(Direction)))
                {
                    // 2 per side
                    if (side * 2 >= directions)
                    {
                        continue;
                    }

                    int regularIndex = Index((Direction)side, Orientation.Regular);
                    int reverseIndex = regularIndex + 1; //Index((Direction) side, Orientation.Reversed);

                    Logger.Trace("Measuring Side no:" + side);

                    int[] offset = EdgeDetector.EdgePoints(source, (Direction)side);
                    Offsets[regularIndex] = offset;
                    Offsets[reverseIndex] = Utility.Reverse(offset);

                    double[] luminousity = Forensics.Luminousity.RepresentativeLuminousity(image, BUFFER, SAMPLE_SIZE,
                                                                                           (Direction)side);
                    Luminousity[regularIndex] = luminousity;
                    Luminousity[reverseIndex] = Utility.Reverse(luminousity);

                    int[]    indicies     = Utility.GetKernelIndicies(ConvolutionKernel, -1);
                    double[] convolutions = Utility.Convolute(Luminousity[regularIndex], ConvolutionKernel, indicies);
                    Convolution[regularIndex] = convolutions;
                    Convolution[reverseIndex] = Utility.Reverse(convolutions);

                    double[] thresholded = Utility.Threshold(Utility.Absolute(Convolution[regularIndex]), THRESHOLD);
                    Thresholded[regularIndex] = thresholded;
                    Thresholded[reverseIndex] = Utility.Reverse(thresholded);

                    int[] chamfer = Forensics.Chamfer.Measure(Thresholded[regularIndex]);
                    Chamfer[regularIndex] = chamfer;
                    Chamfer[reverseIndex] = Utility.Reverse(chamfer);

                    long sparsity = Forensics.Chamfer.Sparsity(Chamfer[regularIndex]);
                    Sparsity[regularIndex] = sparsity;
                    Sparsity[reverseIndex] = sparsity;
                }
            }
        }