public LasPoint.ClassificationType[] Classify(LasFile file) { Stopwatch sw = Stopwatch.StartNew(); LasPointDataRecords points = file.LasPointDataRecords; LasPoint.ClassificationType[] output = new LasPoint.ClassificationType[points.Count]; Statistics stats = new Statistics(); stats.Count = points.Count; for (int i = 0; i < points.Count; i++) { LasPoint3Short point = (LasPoint3Short)points[i]; double green = point.Green - (point.Red + point.Blue) / 2; IMLData classed = Network.Compute( new BasicMLData(new double[] { file.LasHeader.ScaleZ(point.Z), point.Intensity, green })); output[i] = Utills.QuickClassess[classed.IndexOfMax()]; if (output[i] != points[i].Classification) { stats.ClassErrors[(int)points[i].Classification]++; } stats.PredictionMatrix[(int)points[i].Classification, (int)output[i]]++; stats.ClassCount[(int)output[i]]++; stats.ClassRealCount[(int)points[i].Classification]++; if (i % 1000 == 0) { Console.WriteLine(i); } } Console.Write(stats.ToString()); sw.Stop(); Console.WriteLine("Czas trwania [" + sw.Elapsed.TotalSeconds.ToString() + "s]"); stats.SaveMatrixAsCSV(); return(output); }
public static double[] ClassToVector(LasPoint.ClassificationType classType) { double[] ideal = new double[] { 0, 0, 0, 0, 0, 0 }; if (classType == LasPoint.ClassificationType.Building) { ideal[0] = 1; } else if (classType == LasPoint.ClassificationType.MediumVegetation) { ideal[1] = 1; } else if (classType == LasPoint.ClassificationType.HighVegetation) { ideal[2] = 1; } else if (classType == LasPoint.ClassificationType.LowVegetation) { ideal[3] = 1; } else if (classType == LasPoint.ClassificationType.Ground) { ideal[4] = 1; } else if (classType == LasPoint.ClassificationType.Water) { ideal[5] = 1; } return(ideal); }
public List <LasPoint> GetPointsByClassification(LasPoint.ClassificationType classType, double frac) { var random = new Random(); List <int> points; if (!_classificationMap.TryGetValue(classType, out points)) { points = new List <int>(); } int count = (int)Math.Floor(points.Count * frac); return(Enumerable.Range(0, count).Select(i => points[random.Next(points.Count - 1)]).Select(el => this[el]).ToList()); }
public LasPoint.ClassificationType[] Classify(LasFile file, int count = 0) { var sw = Stopwatch.StartNew(); LasPointDataRecords points = file.LasPointDataRecords; if (count == 0 || count > points.Count) { count = points.Count; } LasPoint.ClassificationType[] output = new LasPoint.ClassificationType[count]; Statistics stats = new Statistics(); stats.Count = count; OpenTK.Vector3[] abc = new OpenTK.Vector3[count]; Parallel.For(0, count, (i) => { abc[i] = LinearRegression.ComputeRegressionPoint(file, points[i], regressionCount, regressionRange); if (i % 1000 == 0) { Console.WriteLine(i); } }); for (int i = 0; i < count; i++) { //double[] regression = LinearRegression.ComputeRegressionNumerics(file, points[i], regressionCount, regressionRange); LasPoint3Short point = (LasPoint3Short)points[i]; //OpenTK.Vector3 abc = LinearRegression.ComputeRegressionPoint(file, points[i], regressionCount, regressionRange); double distanceFromPlane = Utills.DistanceFromPlane(point, abc[i]); double green = point.Green - (point.Red + point.Blue) / 2; IMLData classed = Network.Compute(new BasicMLData(new double[] { green, file.LasHeader.ScaleZ(point.Z), point.Intensity, abc[i].X, abc[i].Y, abc[i].Z, distanceFromPlane })); output[i] = Utills.QuickClassess[classed.IndexOfMax()]; if (output[i] != points[i].Classification) { stats.ClassErrors[(int)points[i].Classification]++; } stats.ClassCount[(int)output[i]]++; stats.ClassRealCount[(int)points[i].Classification]++; stats.PredictionMatrix[(int)points[i].Classification, (int)output[i]]++; if (i % 1000 == 0) { Console.WriteLine(i); } } Console.Write(stats.ToString()); sw.Stop(); Console.WriteLine("Czas trwania [" + sw.Elapsed.TotalSeconds.ToString() + "s]"); stats.SaveMatrixAsCSV(); return(output); }
public static bool IsSignificant(LasPoint.ClassificationType clType) { switch (clType) { case LasPoint.ClassificationType.Ground: case LasPoint.ClassificationType.LowVegetation: case LasPoint.ClassificationType.MediumVegetation: case LasPoint.ClassificationType.HighVegetation: case LasPoint.ClassificationType.Building: case LasPoint.ClassificationType.Water: return(true); } return(false); }
public LasPoint.ClassificationType[] Classify(LasFile file) { var sw = Stopwatch.StartNew(); LasPointDataRecords points = file.LasPointDataRecords; int pointsCount = points.Count(); LasPoint.ClassificationType[] output = new LasPoint.ClassificationType[pointsCount]; Statistics stats = new Statistics(); stats.Count = pointsCount; OpenTK.Vector3[] slopeVector = new OpenTK.Vector3[pointsCount]; Parallel.For(0, pointsCount, (i) => { slopeVector[i] = LinearRegression.ComputeRegressionPoint(file, points[i], regressionCount, regressionRange); if (i % 1000 == 0) { Console.WriteLine("ComputeRegression " + i); } }); for (int i = 0; i < pointsCount; i++) { LasPoint3Short point = (LasPoint3Short)points[i]; double distanceFromPlane = Utills.DistanceFromPlane(point, slopeVector[i]); double green = point.Green - (point.Red + point.Blue) / 2; output[i] = Utills.ClassificationClasses[knn.Compute(new double[] { green, file.LasHeader.ScaleZ(point.Z), point.Intensity, slopeVector[i].X, slopeVector[i].Y, slopeVector[i].Z, distanceFromPlane })]; if (output[i] != points[i].Classification) { stats.ClassErrors[(int)points[i].Classification]++; } stats.ClassCount[(int)output[i]]++; stats.ClassRealCount[(int)points[i].Classification]++; stats.PredictionMatrix[(int)points[i].Classification, (int)output[i]]++; if (i % 1000 == 0) { Console.WriteLine(i); } } Console.Write(stats.ToString()); sw.Stop(); Console.WriteLine("Czas trwania [" + sw.Elapsed.TotalSeconds.ToString() + "s]"); stats.SaveMatrixAsCSV(); return(output); }
public List <LasPoint> GetPointsByClassification(LasPoint.ClassificationType classType) { return(_classificationMap[classType].Select(el => this[el]).ToList()); }