Algorithmix.Shred.Shred C# (CSharp) Method

Shred() public method

Create a shred object given a filepath to a bitmap image
public Shred ( string filepath, bool ignoreTopBottom = true ) : System
filepath string destination path of the shred image
ignoreTopBottom bool Default is true, set to false to scan top and bottom aswell
return System
        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;
                }
            }
        }