public IFeatureMatcher GetFeatureMatcher() { IFeatureMatcher matcher = new FeatureMatcher(); switch (MatcherKind) { case LayerMatcher.Kind.PropertyRange: double?min = MinRangeEnabled ? (double)MinRange : (double?)null; double?max = MaxRangeEnabled ? (double)MaxRange : (double?)null; matcher = FeatureMatcher.HasPropertyInRange(PropertyKey, min, max); break; case LayerMatcher.Kind.Property: matcher = FeatureMatcher.HasProperty(PropertyKey); break; case LayerMatcher.Kind.PropertyValue: matcher = FeatureMatcher.HasPropertyWithValue(PropertyKey, PropertyValue); break; case LayerMatcher.Kind.PropertyRegex: try { matcher = FeatureMatcher.HasPropertyWithRegex(PropertyKey, RegexPattern); } catch (ArgumentException ae) { Debug.LogError(ae.Message); } break; } return(matcher); }
// Use this for initialization void Start() { featureMatcher = new FeatureMatcher(); imageList = new ImageList(); ui = GameObject.Find("UIScripts").GetComponent <UIMethods>(); InAppBrowserBridge bridge = GameObject.Find("InAppBrowserBridge").GetComponent <InAppBrowserBridge>(); bridge.onJSCallback.AddListener(OnMessageFromJS); }
public FeatureFilter GetFilter() { var filter = new FeatureFilter(); foreach (MapzenFeatureCollection collection in Enum.GetValues(typeof(MapzenFeatureCollection))) { if ((FeatureCollection & collection) != 0) { filter.CollectionNameSet.Add(collection.ToString().ToLower()); } } if (Matchers == null || Matchers.Count == 0) { return(filter); } else { IFeatureMatcher[] predicates = Matchers.Select(m => m.GetFeatureMatcher()).ToArray(); switch (Combiner) { case MatcherCombiner.None: filter.Matcher = predicates.First(); break; case MatcherCombiner.AllOf: filter.Matcher = FeatureMatcher.AllOf(predicates); break; case MatcherCombiner.AnyOf: filter.Matcher = FeatureMatcher.AnyOf(predicates); break; case MatcherCombiner.NoneOf: filter.Matcher = FeatureMatcher.NoneOf(predicates); break; default: break; } } return(filter); }
/// <summary> /// Aligns features to the baseline correcting for drift time. /// </summary> /// <param name="fullObservedEnumerable">All features.</param> /// <param name="observedEnumerable">Filtered features to use for drift time correction.</param> /// <param name="targetEnumerable">Expected features that should be filtered.</param> /// <param name="massTolerance">PPM Mass Tolerance.</param> /// <param name="netTolerance">Normalized Elution Time Tolerance.</param> public static DriftTimeAlignmentResults <TTarget, TObserved> AlignObservedEnumerable(IEnumerable <UMCLight> fullObservedEnumerable, IEnumerable <TTarget> observedEnumerable, IEnumerable <TObserved> targetEnumerable, double massTolerance, double netTolerance) { // Setup Tolerance for Feature Matching var featureMatcherParameters = new FeatureMatcherParameters(); featureMatcherParameters.SetTolerances(massTolerance, netTolerance, DRIFT_TIME_TOLERANCE); featureMatcherParameters.UseDriftTime = true; // Find all matches based on defined tolerances var featureMatcher = new FeatureMatcher <TTarget, TObserved>(observedEnumerable.ToList(), targetEnumerable.ToList(), featureMatcherParameters); var matchList = featureMatcher.FindMatches(observedEnumerable.ToList(), targetEnumerable.ToList(), featureMatcherParameters.UserTolerances, 0); // Create <ObservedDriftTime, TargetDriftTime> XYData List var xyDataList = new List <XYData>(); foreach (var featureMatch in matchList) { var xyData = new XYData(featureMatch.ObservedFeature.DriftTime, featureMatch.TargetFeature.DriftTime); xyDataList.Add(xyData); } var linearRegression = new LinearRegressionModel(); // Find the Linear Equation for the <ObservedDriftTime, TargetDriftTime> XYData List var linearEquation = linearRegression.CalculateRegression(xyDataList); // Set the Aligned Drift Time value for each of the observed Features, even if they were not found in matching foreach (var observedT in fullObservedEnumerable) { observedT.DriftTimeAligned = linearRegression.Transform(linearEquation, observedT.DriftTime); } var results = new DriftTimeAlignmentResults <TTarget, TObserved>(matchList, linearEquation); return(results); }
/// <summary> /// Does a zero mean drift time correction. /// </summary> /// <param name="observedEnumerable">All observed features to shift that should already be drift time aligned.</param> /// <param name="targetEnumerable">Expected features</param> /// <param name="massTolerance">PPM Mass Tolerance</param> /// <param name="netTolerance">Normalized Elution Time tolerance.</param> /// <param name="driftTimeTolerance">Drift time tolerance to use.</param> public static DriftTimeAlignmentResults <TTarget, TObserved> CorrectForOffset(IEnumerable <TTarget> observedEnumerable, IEnumerable <TObserved> targetEnumerable, double massTolerance, double netTolerance, double driftTimeTolerance) { // Setup Tolerance for Feature Matching var featureMatcherParameters = new FeatureMatcherParameters(); featureMatcherParameters.SetTolerances(massTolerance, netTolerance, (float)driftTimeTolerance); featureMatcherParameters.UseDriftTime = true; // Find all matches based on defined tolerances var featureMatcher = new FeatureMatcher <TTarget, TObserved>(observedEnumerable.ToList(), targetEnumerable.ToList(), featureMatcherParameters); var matchList = featureMatcher.FindMatches(observedEnumerable.ToList(), targetEnumerable.ToList(), featureMatcherParameters.UserTolerances, 0); // Create List of Drift Time differences var differenceList = new List <double>(matchList.Count); foreach (var featureMatch in matchList) { var observedFeature = featureMatch.ObservedFeature; var targetFeature = featureMatch.TargetFeature; double observedDriftTime; if (observedFeature.DriftTimeAligned != double.NaN && observedFeature.DriftTimeAligned > 0.0) { observedDriftTime = observedFeature.DriftTimeAligned; } else { observedDriftTime = observedFeature.DriftTime; } double targetDriftTime; if (!double.IsNaN(targetFeature.DriftTimeAligned) && targetFeature.DriftTimeAligned > 0.0) { targetDriftTime = targetFeature.DriftTimeAligned; } else { targetDriftTime = targetFeature.DriftTime; } differenceList.Add(observedDriftTime - targetDriftTime); } // Create bins for histogram var bins = new List <double>(); for (var i = -driftTimeTolerance; i <= driftTimeTolerance; i += (driftTimeTolerance / 100.0)) { bins.Add(i); } bins.Add(driftTimeTolerance); // Group drift time differences into the bins var groupings = differenceList.GroupBy(difference => bins.First(bin => bin >= difference)); // Order the groupings by their count, so the group with the highest count will be first var orderGroupingsByCount = from singleGroup in groupings orderby singleGroup.Count() descending select singleGroup; // Grab the drift time from the group with the most counts var driftTimeOffset = orderGroupingsByCount.First().Key; // Update all of the observed features with the new drift time foreach (var observedFeature in observedEnumerable) { if (!double.IsNaN(observedFeature.DriftTimeAligned) && observedFeature.DriftTimeAligned > 0.0) { observedFeature.DriftTimeAligned -= driftTimeOffset; } else { observedFeature.DriftTime -= (float)driftTimeOffset; } } var linearEquation = new LinearRegressionResult { Slope = 0, Intercept = driftTimeOffset }; var results = new DriftTimeAlignmentResults <TTarget, TObserved>(matchList, linearEquation); return(results); }
static void Main(string[] args) { Stopwatch st = new Stopwatch(); string path = "D:\\palmprint_database\\cut_polyU"; int numPalms = 10; int numImages = 100; float[,] distMat = new float[numImages, numImages]; // should be read in Matlab using 'float32' precision Bitmap[] images = new Bitmap[numImages]; int cnt = 0; // read all images for (int i = 1; i <= numPalms; i++) { for (int j = 1; j <= 50; j++) { string fileName = path + string.Format("\\{0:D4}_{1:D2}.bmp", i, j); FileInfo f = new FileInfo(fileName); if (f.Exists) { images[cnt] = (Bitmap)Bitmap.FromFile(f.FullName); cnt++; } } } // feature extract and match //FeatureExtractor extractor = new FeatureExtractor(); FeatureMatcher matcher = new FeatureMatcher(); for (int i = 0; i < numImages; i++) { Console.WriteLine(string.Format("Matching person {0}...", i)); float[] distVect = new float[numImages]; st.Start(); for (int j = i + 1; j < numImages; j++) { distMat[i, j] = (float)matcher.Match(images[i], images[j]); distMat[j, i] = distMat[i, j]; distVect[j] = (float)matcher.Match(images[i], images[j]); } st.Stop(); System.Console.WriteLine(string.Format("Person {0} used {1} seconds.", i, (double)st.ElapsedMilliseconds / 1000)); st.Reset(); using (FileStream fs = new FileStream(string.Format("{0}.sim", i), FileMode.OpenOrCreate, FileAccess.ReadWrite)) { BinaryWriter w = new BinaryWriter(fs); for (int j = 0; j < numImages; j++) { w.Write(distVect[j]); } w.Close(); } } matcher.Dispose(); // write distances using (FileStream fs = new FileStream("similarity.sim", FileMode.OpenOrCreate, FileAccess.ReadWrite)) { BinaryWriter w = new BinaryWriter(fs); for (int i = 0; i < numImages; i++) { for (int j = 0; j < numImages; j++) { w.Write(distMat[i, j]); } } w.Close(); } }