示例#1
0
文件: Map.cs 项目: bmeaut/sigstat
        /// <summary> Initializes a new instance of the <see cref="Map"/> class with specified settings. </summary>
        /// <param name="minVal">New minimum value.</param>
        /// <param name="maxVal">New maximum value.</param>
        public Map(double minVal, double maxVal)
        {
            this.v0 = minVal;
            this.v1 = maxVal;

            this.Output(FeatureDescriptor <List <double> > .Descriptor("MapResult"));
        }
示例#2
0
文件: Extrema.cs 项目: bmeaut/sigstat
 /// <summary> Initializes a new instance of the <see cref="Extrema"/> class. </summary>
 public Extrema()
 {
     this.Output(
         FeatureDescriptor <List <double> > .Descriptor("Min"),
         FeatureDescriptor <List <double> > .Descriptor("Max")
         );
 }
示例#3
0
        //TODO: technikailag FODra, SODrea is meg lehet hívni ezeket a függvényeket
        public List <double> GetFirstOrderDifference(FeatureDescriptor <List <double> > baseFeatureDescriptor)
        {
            string fodFeatureKey = "FOD" + baseFeatureDescriptor.Key;

            if (Signature.HasFeature(fodFeatureKey))
            {
                return(Signature.GetFeature <List <double> >(fodFeatureKey));
            }

            else
            {
                List <double> baseFeature    = Signature.GetFeature(baseFeatureDescriptor);
                List <double> firstOrderDiff = new List <double>(baseFeature.Count);

                for (int i = 0; i < baseFeature.Count; i++)
                {
                    if (i < baseFeature.Count - SpacingParameter)
                    {
                        firstOrderDiff.Add(baseFeature[i + SpacingParameter] - baseFeature[i]);
                    }
                    //Lista kipótlása az utolsó számított értékkel
                    else
                    {
                        firstOrderDiff.Add(firstOrderDiff[baseFeature.Count - SpacingParameter - 1]);
                    }
                }


                FeatureDescriptor <List <double> > fodFeatureDescriptor = FeatureDescriptor <List <double> > .Descriptor(fodFeatureKey);

                Signature.SetFeature(fodFeatureDescriptor, firstOrderDiff);

                return(firstOrderDiff);
            }
        }
示例#4
0
        public List <double> GetSecondOrderDifference(FeatureDescriptor <List <double> > baseFeatureDescriptor)
        {
            string sodFeatureKey = "SOD" + baseFeatureDescriptor.Key;

            if (Signature.HasFeature(sodFeatureKey))
            {
                return(Signature.GetFeature <List <double> >(sodFeatureKey));
            }

            else
            {
                List <double> firstOrderDiff = GetFirstOrderDifference(baseFeatureDescriptor);

                List <double> secondOrderDiff = new List <double>(firstOrderDiff.Count);

                for (int i = 0; i < firstOrderDiff.Count - 1; i++)
                {
                    secondOrderDiff.Add(firstOrderDiff[i + 1] - firstOrderDiff[i]);
                }

                //Lista kipótlása az utolsó számított értékkel
                secondOrderDiff.Add(secondOrderDiff[firstOrderDiff.Count - 2]);

                FeatureDescriptor <List <double> > sodFeatureDescriptor = FeatureDescriptor <List <double> > .Descriptor(sodFeatureKey);

                Signature.SetFeature(sodFeatureDescriptor, secondOrderDiff);

                return(secondOrderDiff);
            }
        }
示例#5
0
 /// <summary> Initializes a new instance of the <see cref="EndpointExtraction"/> class. </summary>
 public EndpointExtraction()
 {
     this.Output(
         FeatureDescriptor <List <Point> > .Descriptor("EndPoints"),
         FeatureDescriptor <List <Point> > .Descriptor("CrossingPoints")
         );
 }
示例#6
0
 /// <summary> Initializes a new instance of the <see cref="BinaryRasterizer"/> class with specified raster size and pen width. </summary>
 /// <param name="resolutionX">Raster width.</param>
 /// <param name="resolutionY">Raster height.</param>
 /// <param name="penWidth"></param>
 public BinaryRasterizer(int resolutionX, int resolutionY, float penWidth)
 {
     this.w        = resolutionX;
     this.h        = resolutionY;
     this.penWidth = penWidth;
     pen           = new Pen <Byte4>(fg, penWidth);
     this.Output(FeatureDescriptor <bool[, ]> .Descriptor("Binarized"));
 }
示例#7
0
        /// <summary> Initializes a new instance of the <see cref="ComponentsToFeatures"/> class. </summary>
        public ComponentsToFeatures()
        {
            componentsFeature = FeatureDescriptor <List <List <PointF> > > .Descriptor("Components");

            this.Output(
                Features.X,
                Features.Y,
                Features.Button
                );
        }
示例#8
0
        }                                                //TODO erre jobbat kitalalni, pl. pipeline ososztaly

        /// <summary>Initializes a new instance of the <see cref="TimeReset"/> class.</summary>
        public TimeReset()
        {
            var negMin = FeatureDescriptor <List <double> > .Descriptor("NegMin");//TODO: ideiglenes dolgokat vhogy torolni

            Items = new List <ITransformation>()
            {
                new Extrema().Input(Features.T),         //find minimum
                new Multiply(-1.0).Output(negMin, null), //negate
                new AddVector(negMin).Input(Features.T), //add the negated value
            };

            this.Output(Features.T);
        }
示例#9
0
        /// <inheritdoc/>
        public void Transform(Signature signature)
        {
            bool[,] b = signature.GetFeature(FeatureDescriptor <bool[, ]> .Descriptor("Skeleton"));

            var endPoints      = new List <Point>();
            var crossingPoints = new List <Point /*, int ncnt*/>();
            int w = b.GetLength(0);
            int h = b.GetLength(1);

            for (int i = 1; i < w - 1; i++)
            {
                for (int j = 1; j < h - 1; j++)
                {
                    if (b[i, j])
                    {
                        bool[] ns =  //8 szomszed sorrendben
                        {
                            b[i - 1, j - 1],
                            b[i,     j - 1],
                            b[i + 1, j - 1],
                            b[i + 1, j],
                            b[i + 1, j + 1],
                            b[i,     j + 1],
                            b[i - 1, j + 1],
                            b[i - 1, j]
                        };
                        int ncnt = 0;//count neighbours
                        for (int ni = 0; ni < 8; ni++)
                        {
                            ncnt += ns[ni] ? 1 : 0;
                        }

                        if (ncnt == 1)//1 szomszed -> endpoint
                        {
                            endPoints.Add(new Point(i, j));
                        }
                        else if (ncnt > 2)//tobb mint 2 szomszed -> crossing point
                        {
                            crossingPoints.Add(new Point(i, j /*, ncnt*/));
                        }
                    }
                }
                Progress = (int)(i / (double)(w - 1) * 100);
            }

            signature.SetFeature(OutputFeatures[0], endPoints);
            signature.SetFeature(OutputFeatures[1], crossingPoints);

            Progress = 100;
            Log(LogLevel.Info, $"Endpoint extraction done. {endPoints.Count} endpoints and {crossingPoints.Count} crossingpoints found.");
        }
示例#10
0
        }                                                //TODO erre jobbat kitalalni, pl. pipeline ososztaly

        /// <summary> Initializes a new instance of the <see cref="CentroidTranslate"/> class.</summary>
        public CentroidTranslate()
        {
            Items = new List <ITransformation>()
            {
                new CentroidExtraction
                {
                    Features.X,
                    Features.Y
                },
                new Multiply(-1.0),
                new Translate(FeatureDescriptor <List <double> > .Descriptor("Centroid")).Input(Features.X, Features.Y)
            };

            this.Output(Features.X, Features.Y);
        }
示例#11
0
        /// <inheritdoc/>
        public void Transform(Signature signature)
        {
            //default output is '{input}', '{input}Image'
            if (OutputFeatures == null)
            {
                OutputFeatures = new List <FeatureDescriptor> {
                    InputFeatures[0],
                    FeatureDescriptor <Image <Rgba32> > .Descriptor(InputFeatures[0].Name + "Image")
                }
            }
            ;

            bool[,] b = signature.GetFeature <bool[, ]>(InputFeatures[0]);
            int w = b.GetLength(0);
            int h = b.GetLength(1);

            //itt pl lehetne Dilate meg ilyesmi

            Image <Rgba32> img = new Image <Rgba32>(w, h);

            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    img[x, h - 1 - y] = b[x, y] ? fg : bg;
                }
                Progress = (int)(x / (double)w * 95);
            }

            signature.SetFeature(OutputFeatures[1], img);

            if (writeToFile)
            {
                string signerString = (signature.Signer != null) ? signature.Signer.ID : "Null";
                string filename     = $"U_{signerString}_S_{signature.ID?? "Null"}_{OutputFeatures[1].Name}.png";
                img.SaveAsPng(File.Create(filename));
                Log(LogLevel.Info, $"Image saved: {filename}");
            }

            Progress = 100;
            Log(LogLevel.Info, $"Image generation from binary raster done.");
        }
    }
示例#12
0
文件: Program.cs 项目: bmeaut/sigstat
        static void OnlineVerifierDemo()
        {
            Logger debugLogger = new Logger(
                LogLevel.Debug,
                new FileStream($@"Logs\OnlineDemo_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.log", FileMode.Create),
                LogConsole);

            var timer1 = FeatureDescriptor <DateTime> .Descriptor("Timer1");

            var verifier = new Verifier()
            {
                Logger            = debugLogger,
                TransformPipeline = new SequentialTransformPipeline
                {
                    new TimeMarkerStart().Output(timer1),
                    new ParallelTransformPipeline
                    {
                        new Normalize().Input(Features.Pressure),
                        new Map(0, 1).Input(Features.X),
                        new Map(0, 1).Input(Features.Y),
                        new TimeReset(),
                    },
                    new CentroidTranslate(),//is a sequential pipeline of other building blocks
                    new TangentExtraction(),

                    /*new AlignmentNormalization(Alignment.Origin),
                     * new Paper13FeatureExtractor(),*/
                    new TimeMarkerStop().Output(timer1),
                    new LogMarker(LogLevel.Info).Input(timer1),
                },
                ClassifierPipeline = new WeightedClassifier
                {
                    {
                        (new DTWClassifier(Accord.Math.Distance.Manhattan)
                        {
                            Features.X,
                            Features.Y
                        }, 0.15)
                    },
示例#13
0
        /// <inheritdoc/>
        public void Transform(Signature signature)
        {
            b = signature.GetFeature(FeatureDescriptor <bool[, ]> .Descriptor("Skeleton"));
            var endPoints      = signature.GetFeature(FeatureDescriptor <List <Point> > .Descriptor("EndPoints"));
            var crossingPoints = signature.GetFeature(FeatureDescriptor <List <Point> > .Descriptor("CrossingPoints"));

            if (samplingResolution < 1)
            {
                Log(LogLevel.Warn, $"Invalid sampling resolution {samplingResolution}. It must be a positive integer.");
            }

            //TODO: megtalalni a vegpont nelkulieket (pl. perfekt O betu), ebbol egy pontot hozzaadni a crossingpointokhoz es jo lesz

            //meglevo endpointokhoz hozzaadjuk a crossingpointok szomszedait
            var crossings = SplitCrossings(crossingPoints);

            //neha a szukito miatt tobbnek erzekelunk egy crossingot -> tul kozelieket vonjuk ossze
            crossings = UniteCloseCrossings(crossings, 45);


            foreach (var endings in crossings)
            {
                endPoints.AddRange(endings);
            }
            Progress = 33;
            Log(LogLevel.Debug, $"{crossings.Count} crossings found.");

            var sectionlist = Trace(endPoints);

            Log(LogLevel.Debug, $"{sectionlist.Count} sections found");
            Progress = 66;
            //megvannak a sectionok, de meg ossze kell oket kotni a crossingoknal

            var componentlist = JoinSections(sectionlist, crossings);

            signature.SetFeature(OutputFeatures[0], componentlist);
            Progress = 100;
            Log(LogLevel.Info, $"Component extraction done. {componentlist.Count} components found.");
        }
示例#14
0
 /// <summary>Stops a timer to measure completion time of previous transforms.</summary>
 public TimeMarkerStop()
 {
     this.Output(FeatureDescriptor <DateTime> .Descriptor("DefaultTimer"));
 }
示例#15
0
 /// <summary> Initializes a new instance of the <see cref="Binarization"/> class with specified settings. </summary>
 /// <param name="foregroundType"></param>
 /// <param name="binThreshold">Use this threshold value instead of iteratively calculating it. Range from 0 to 1</param>
 public Binarization(ForegroundType foregroundType, double?binThreshold)
 {
     this.foregroundType = foregroundType;
     this.binThreshold   = binThreshold;
     this.Output(FeatureDescriptor <bool[, ]> .Descriptor("Binarized"));
 }
示例#16
0
        /// <summary> Initializes a new instance of the <see cref="ComponentSorter"/> class. </summary>
        public ComponentSorter()
        {
            componentsFeature = FeatureDescriptor <List <List <PointF> > > .Descriptor("Components");

            this.Output(componentsFeature);
        }
示例#17
0
 /// <summary> Initializes a new instance of the <see cref="HSCPThinning"/> class. </summary>
 public HSCPThinning()
 {
     this.Output(FeatureDescriptor <bool[, ]> .Descriptor("HSCPThinningResult"));
 }
示例#18
0
        private void TestTransformation()
        {
            if (Signers == null)
            {
                LoadSignatures();
            }

            Signature signature = Signers[0].Signatures[0];
            string    selectedTransformation = "";

            App.Current.Dispatcher.Invoke(delegate
            {
                selectedTransformation = (string)TransformationChooserComboBox.SelectedValue;
            });

            if (selectedTransformation == "Translate")
            {
                var originalValues = signature.GetFeature(Features.X);

                new Transformation.Translate(Features.X, OriginType.CenterOfGravity,
                                             FeatureDescriptor <List <double> > .Descriptor(OriginType.CenterOfGravity + "TranslationResult")).Transform(signature);
                var cogValues = signature.GetFeature <List <double> >(OriginType.CenterOfGravity + "TranslationResult");

                new Transformation.Translate(Features.X, OriginType.Minimum,
                                             FeatureDescriptor <List <double> > .Descriptor(OriginType.Minimum + "TranslationResult")).Transform(signature);
                var minValues = signature.GetFeature <List <double> >(OriginType.Minimum + "TranslationResult");

                new Transformation.Translate(Features.X, OriginType.Maximum,
                                             FeatureDescriptor <List <double> > .Descriptor(OriginType.Maximum + "TranslationResult")).Transform(signature);
                var maxValues = signature.GetFeature <List <double> >(OriginType.Maximum + "TranslationResult");

                new Transformation.Translate(Features.X, 100.0,
                                             FeatureDescriptor <List <double> > .Descriptor(OriginType.Predefined + "TranslationResult")).Transform(signature);
                var predefValues = signature.GetFeature <List <double> >(OriginType.Predefined + "TranslationResult");

                string       outputFileName = selectedTransformation + "TransformationOutputTest.csv";
                StreamWriter sw             = new StreamWriter(outputFileName);
                sw.WriteLine("Original ; COG translated ; Min translated ; Max translated ; 100.0 translated");
                for (int i = 0; i < signature.GetFeature(Features.X).Count; i++)
                {
                    sw.WriteLine($"{originalValues[i]};{cogValues[i]};{minValues[i]};{maxValues[i]};{predefValues[i]}");
                }
                sw.Close();

                Process.Start(outputFileName);
            }
            else if (selectedTransformation == "UniformScale")
            {
                var originalXValues = signature.GetFeature(Features.X);
                var originalYValues = signature.GetFeature(Features.Y);


                new UniformScale(Features.X, Features.Y, 100, 200, 150,
                                 FeatureDescriptor <List <double> > .Descriptor("UniformScalingResultBaseDim"),
                                 FeatureDescriptor <List <double> > .Descriptor("UniformScalingResultProportionalDim")).Transform(signature);
                var defScaledXValues = new List <double>(signature.GetFeature <List <double> >("UniformScalingResultBaseDim"));
                var defScaledYValues = new List <double>(signature.GetFeature <List <double> >("UniformScalingResultProportionalDim"));


                new UniformScale
                {
                    BaseDimension               = Features.X,
                    ProportionalDimension       = Features.Y,
                    BaseDimensionOutput         = FeatureDescriptor <List <double> > .Descriptor("UniformScalingResultBaseDim"),
                    ProportionalDimensionOutput = FeatureDescriptor <List <double> > .Descriptor("UniformScalingResultProportionalDim")
                }.Transform(signature);

                var autoScaledXValues = new List <double>(signature.GetFeature <List <double> >("UniformScalingResultBaseDim"));
                var autoScaledYValues = new List <double>(signature.GetFeature <List <double> >("UniformScalingResultProportionalDim"));

                string       outputFileName = selectedTransformation + "TransformationOutputTest.csv";
                StreamWriter sw             = new StreamWriter(outputFileName);
                sw.WriteLine("OriginalX; OriginalY ; DefScaledX ; DefScaledY ; AutoScaledX; AutoScaledY");
                for (int i = 0; i < signature.GetFeature(Features.X).Count; i++)
                {
                    sw.WriteLine($"{originalXValues[i]};{originalYValues[i]};{defScaledXValues[i]};{defScaledYValues[i]};{autoScaledXValues[i]}; {autoScaledYValues[i]}");
                }
                sw.Close();

                Process.Start(outputFileName);
            }
            else if (selectedTransformation == "Scale")
            {
                var originalXValues = signature.GetFeature(Features.X);
                new Scale(Features.X, 100, 500,
                          FeatureDescriptor <List <double> > .Descriptor("ScalingResult")).Transform(signature);
                var defScaledXValues = new List <double>(signature.GetFeature <List <double> >("ScalingResult"));

                new Scale
                {
                    InputFeature  = Features.X,
                    OutputFeature = FeatureDescriptor <List <double> > .Descriptor("ScalingResult")
                }.Transform(signature);
                var autoScaledXValues = new List <double>(signature.GetFeature <List <double> >("ScalingResult"));

                string       outputFileName = selectedTransformation + "TransformationOutputTest.csv";
                StreamWriter sw             = new StreamWriter(outputFileName);
                sw.WriteLine("OriginalX;  DefScaledX ;  AutoScaledX");
                for (int i = 0; i < signature.GetFeature(Features.X).Count; i++)
                {
                    sw.WriteLine($"{originalXValues[i]};{defScaledXValues[i]};{autoScaledXValues[i]}");
                }
                sw.Close();

                Process.Start(outputFileName);
            }
            else if (selectedTransformation == "NormalizeRotation")
            {
                var originalXValues = new List <double>(signature.GetFeature(Features.X));
                var originalYValues = new List <double>(signature.GetFeature(Features.Y));
                new NormalizeRotation().Transform(signature);
                var rotatedXValues = new List <double>(signature.GetFeature(Features.X));
                var rotatedYValues = new List <double>(signature.GetFeature(Features.Y));

                string       outputFileName = selectedTransformation + "TransformationOutputTest.csv";
                StreamWriter sw             = new StreamWriter(outputFileName);
                sw.WriteLine("OriginalX; OriginalY; RotatedX ; RotatedY");
                for (int i = 0; i < signature.GetFeature(Features.X).Count; i++)
                {
                    sw.WriteLine($"{originalXValues[i]};{originalYValues[i]};{rotatedXValues[i]};{rotatedYValues[i]}");
                }
                sw.Close();

                Process.Start(outputFileName);
            }
        }
示例#19
0
 /// <summary> Initializes a new instance of the <see cref="TangentExtraction"/> class. </summary>
 public TangentExtraction()
 {
     this.Output(FeatureDescriptor <List <double> > .Descriptor("Tangent"));
 }
示例#20
0
 /// <summary> Initializes a new instance of the <see cref="CentroidExtraction"/> class. </summary>
 public CentroidExtraction()
 {
     //this.Input(Features.X, Features.X);
     InputFeatures = new List <FeatureDescriptor>();
     this.Output(FeatureDescriptor <List <double> > .Descriptor("Centroid"));
 }
示例#21
0
 /// <summary> Initializes a new instance of the <see cref="OnePixelThinning"/> class. </summary>
 public OnePixelThinning()
 {
     this.Output(FeatureDescriptor <bool[, ]> .Descriptor("OnePixelThinningResult"));
 }
示例#22
0
 /// <summary> Initializes a new instance of the <see cref="Map"/> class with specified settings. </summary>
 public Normalize()
 {
     this.Output(FeatureDescriptor <List <double> > .Descriptor("NormalizationResult"));
 }
示例#23
0
 public PrepareForThinning()
 {
     this.Output(FeatureDescriptor <bool[, ]> .Descriptor("Prepared"));
 }
示例#24
0
 /// <summary> Initializes a new instance of the <see cref="ComponentExtraction"/> class with specified sampling resolution.</summary>
 /// <param name="samplingResolution">Steps to trace before a new point is sampled. Smaller values result in a more precise tracing. Provide a positive value.</param>
 public ComponentExtraction(int samplingResolution)
 {
     this.samplingResolution = samplingResolution;
     this.Output(FeatureDescriptor <List <List <PointF> > > .Descriptor("Components"));
 }
示例#25
0
 /// <param name="framewidth">Leave a border around the trimmed area. framewidth > 0</param>
 public Trim(int framewidth)
 {
     this.framewidth = framewidth;
     this.Output(FeatureDescriptor <bool[, ]> .Descriptor("Trimmed"));
 }