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.Get <List <double> >(sodFeatureKey); Signature.SetFeature(sodFeatureDescriptor, secondOrderDiff); return(secondOrderDiff); } }
//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.Get <List <double> >(fodFeatureKey); Signature.SetFeature(fodFeatureDescriptor, firstOrderDiff); return(firstOrderDiff); } }
public void TestIsCollection() { var fd1 = FeatureDescriptor <int> .Get("1"); var fd2 = FeatureDescriptor <List <int> > .Get("2"); Assert.AreEqual(false, fd1.IsCollection); Assert.AreEqual(true, fd2.IsCollection); }
public void TestGetterSetter() { string ID = "testid"; Origin origin = new Origin(); Signer signer = new Signer(); Signature signature = new Signature(); signature.ID = ID; signature.Origin = origin; signature.Signer = signer; Assert.AreEqual(ID, signature.ID); Assert.AreEqual(origin, signature.Origin); Assert.AreEqual(signer, signature.Signer); string feature = "test feature"; signature["test"] = feature; Assert.AreEqual(signature["test"], feature); FeatureDescriptor featureDescriptor = FeatureDescriptor.Get <String>("Desc"); signature[featureDescriptor] = "desc"; Assert.AreEqual(signature[featureDescriptor], "desc"); Assert.AreEqual(signature.GetFeature <String>("Desc"), "desc"); Assert.AreEqual(signature.GetFeature <String>(featureDescriptor), "desc"); var featureDescriptors = signature.GetFeatureDescriptors(); Assert.IsNotNull(featureDescriptors); signature.SetFeature <String>(featureDescriptor, "feat"); Assert.AreEqual(signature.GetFeature <String>("Desc"), "feat"); signature.SetFeature <String>("Desc", "feat2"); Assert.AreEqual(signature.GetFeature <String>("Desc"), "feat2"); FeatureDescriptor featureDescriptor2 = FeatureDescriptor.Get <String>("Desc2"); signature[featureDescriptor2] = "desc2"; var fs = new List <FeatureDescriptor>(); fs.Add(featureDescriptor); fs.Add(featureDescriptor2); //Assert.IsNotNull(signature.GetAggregateFeature(fs)); Assert.IsTrue(signature.HasFeature(featureDescriptor)); Assert.IsTrue(signature.HasFeature("Desc2")); Assert.IsNotNull(signature.ToString()); }
public void TestGetterSetters() { const string key = "Loop"; var fd = FeatureDescriptor <int> .Get(key); const string expectedName = "TestName"; fd.Name = expectedName; Type expectedType = typeof(int); Assert.AreEqual(expectedName, fd.Name); Assert.AreEqual(expectedType, fd.FeatureType); }
public void TestGet() { const string key = "Loop"; var fd1 = FeatureDescriptor.Get <int>(key); Assert.IsNotNull(fd1); Assert.AreEqual(key, fd1.Key); Assert.ThrowsException <KeyNotFoundException>(() => FeatureDescriptor.Get("Loop1")); var fd2 = FeatureDescriptor <int> .Get(key); Assert.AreSame(fd1, fd2); }
/// <summary>Initializes a new instance of the <see cref="TimeReset"/> class.</summary> public TimeReset() { var negMin = FeatureDescriptor.Get <List <double> >("NegMin");//TODO: ideiglenes dolgokat vhogy torolni Items = new List <ITransformation> { new Extrema(),//find minimum new Multiply(-1.0) { Output = negMin }, //negate new AddVector(negMin) { Inputs = { Input } }, //add the negated value }; }
/// <summary> /// Overwrite of the <see cref="JsonConverter"/> method /// Deserializes the <see cref="FeatureDescriptor"/> json created by the this class /// </summary> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { string value = (string)reader.Value; if (value.Contains("|")) { string[] strings = value.Split('|'); string key = strings[0].Trim(); string featureType = strings[1].Trim(); Type currType = Type.GetType(featureType); FeatureDescriptor fd = FeatureDescriptor.Register(key, currType); return(fd); } else { FeatureDescriptor fd = FeatureDescriptor.Get(value); return(fd); } }
/// <summary> Initializes a new instance of the <see cref="CentroidTranslate"/> class.</summary> public CentroidTranslate() { var C = FeatureDescriptor <List <double> > .Get("Centroid");//TODO: Register() Items = new List <ITransformation> { new CentroidExtraction { Inputs = new List <FeatureDescriptor <List <double> > >() { InputX, InputY }, OutputCentroid = C }, new Multiply(-1.0), new Translate(C) { OutputX = OutputX, OutputY = OutputY } }; }
/// <summary> /// Overwrite of the <see cref="JsonConverter"/> method /// Deserializes the <see cref="FeatureDescriptor{T}"/> json created by the this class /// </summary> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { string value = (string)reader.Value; if (value.Contains("|")) { string[] strings = value.Split('|'); string key = strings[0].Trim(); string featureType = strings[1].Trim(); Type currType = Type.GetType(featureType); var fdType = typeof(FeatureDescriptor <>).MakeGenericType(currType); var get = fdType.GetMethod("Get", BindingFlags.Public | BindingFlags.Static); return(get.Invoke(null, new object[] { key })); } else { FeatureDescriptor fd = FeatureDescriptor.Get(value); return(fd); } }
private object GetFeatureDesricptor(string json) { string value = json; if (value.Contains("|")) { string[] strings = value.Split('|'); string key = strings[0].Trim(); string featureType = strings[1].Trim(); Type currType = Type.GetType(featureType); var fdType = typeof(FeatureDescriptor <>).MakeGenericType(currType); var get = fdType.GetMethod("Get", BindingFlags.Public | BindingFlags.Static); return(get.Invoke(null, new object[] { key })); } else { FeatureDescriptor fd = FeatureDescriptor.Get(value); return(fd); } }
public void GetAggregateFeatureTest() { string ID = "testid"; Origin origin = new Origin(); Signer signer = new Signer(); Signature signature = new Signature(ID, origin, signer); FeatureDescriptor featureDescriptor = FeatureDescriptor.Get <String>("Desc"); signature[featureDescriptor] = "desc"; FeatureDescriptor featureDescriptor2 = FeatureDescriptor.Get <String>("Desc2"); signature[featureDescriptor2] = "desc2"; List <FeatureDescriptor> fs = new List <FeatureDescriptor>(); fs.Add(featureDescriptor); fs.Add(featureDescriptor2); // Assert.AreEqual(signature.GetAggregateFeature, featureDescriptor); }
/// <inheritdoc/> public void Transform(Signature signature) { if (OutputImage == null) { OutputImage = FeatureDescriptor <Image <Rgba32> > .Get(Input.Name + "Image");//TODO: <T> template-es Register() } bool[,] b = signature.GetFeature(Input); 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] ? ForegroundColor : BackgroundColor; } Progress = (int)(x / (double)w * 95); } signature.SetFeature(OutputImage, img); if (WriteToFile) { string signerString = (signature.Signer != null) ? signature.Signer.ID : "Null"; string filename = $"{signature.ID ?? "Null"}_{Input.Name}.png"; img.SaveAsPng(File.Create(filename)); this.LogInformation($"Image saved: {filename}"); } Progress = 100; this.LogInformation($"Image generation from binary raster done."); }