public void RasterBandStatisticTool() { GRasterLayer rasterLayer = new GRasterLayer(fullFilename); IRasterBandStatisticTool pRasterBandStasticTool = new GRasterBandStatisticTool(); pRasterBandStasticTool.Visit(rasterLayer.BandCollection[0]); var rawGraph = pRasterBandStasticTool.StaisticalRawGraph; var rawTable = pRasterBandStasticTool.StatisticalRawQueryTable; Assert.AreEqual(rawGraph.Count, 255); Assert.AreEqual(rawTable.Length, 768000); }
/// <summary> /// 分析标注道路区域 /// </summary> public void Prepare() { //set cursor tool to featureRasterLayer _pRasterLayerCursorTool.Visit(_featureRasterLayer); //statical label raw graph IRasterBandStatisticTool pLabelBandStaticTool = new GRasterBandStatisticTool(); pLabelBandStaticTool.Visit(_labelRasterLayer.BandCollection[0]); //set visitor band _memory = pLabelBandStaticTool.StaisticalRawGraph; //convert memory to queryable structure _queryTable = pLabelBandStaticTool.StatisticalRawQueryTable; //random seeds _randomSeedKeys = _memory.Keys.ToArray(); //initial x, y, action (_current_x, _current_y, _current_action) = RandomAccessMemory(); }
/// <summary> /// 分析标注道路区域 /// </summary> public void Prepare() { // IRasterBandStatisticTool pBandStasticTool = new GRasterBandStatisticTool(); pBandStasticTool.Visit(_labelRasterLayer.BandCollection[0]); // _pGRasterLayerCursorTool.Visit(_featureRasterLayer); //将memory限定成4800总量 _memory = pBandStasticTool.StaisticalRawGraph; //limited the environment _memory size to cetrain number _memory = _memory.LimitedDictionaryCapcaity(); //}{debug 保存成.txt // using(StreamWriter sw = new StreamWriter(@"C:\Users\81596\Desktop\B\Samples.txt")) // { // string str=""; // foreach (var element1 in _memory) // foreach (var element2 in element1.Value) // str += string.Join(",",_pGRasterLayerCursorTool.PickRawValue(element2.X, element2.Y)) + "," + element1.Key + "\r\n"; // sw.Write(str); // } //random seeds //}{debug 保存图位置 //Bitmap samplesBitmap = new Bitmap(_featureRasterLayer.XSize, _featureRasterLayer.YSize); //Graphics g = Graphics.FromImage(samplesBitmap); //Color c; //Pen p; //SolidBrush brush; //foreach (var element1 in _memory) // foreach (var element2 in element1.Value) // { // int gray = element1.Key; // c = Color.FromArgb(gray, gray, gray); // p = new Pen(c); // brush = new SolidBrush(c); // g.FillRectangle(brush, new Rectangle(element2.X, element2.Y, 1, 1)); // } //// //samplesBitmap.Save(@"C:\Users\81596\Desktop\B\Samples.jpg"); // _randomSeedKeys = _memory.Keys.ToArray(); // (_current_x, _current_y, _current_classindex) = RandomAccessMemory(); }
public static (int[, ] matrix, double kappa, int actionsNumber, double oa) Calcute(GRasterLayer truthLayer, GRasterLayer predLayer) { //statical label band graph IRasterBandStatisticTool pBandStaticTool = new GRasterBandStatisticTool(); pBandStaticTool.Visit(truthLayer.BandCollection[0]); Dictionary <int, List <Point> > memory = pBandStaticTool.StaisticalRawGraph; //key index List <int> Keys = memory.Keys.ToList(); int actionsNumber = Keys.Count; int[,] matrix = new int[actionsNumber, actionsNumber]; IRasterBandCursorTool pBandCursorTool = new GRasterBandCursorTool(); pBandCursorTool.Visit(predLayer.BandCollection[0]); // pBandStaticTool.Visit(predLayer.BandCollection[0]); var m = pBandStaticTool.StaisticalRawGraph; // for (int i = 0; i < actionsNumber; i++) { int key = Keys[i]; List <Point> points = memory[key]; //计算realKey类分类结果,存入混淆矩阵 points.ForEach(p => { int rawType = (int)pBandCursorTool.PickRawValue(p.X, p.Y); int indexType = Keys.IndexOf(rawType); if (indexType != -1) { matrix[i, indexType]++; } }); } // Create a new multi-class Confusion Matrix var cm = new GeneralConfusionMatrix(matrix); // int totalNum = cm.NumberOfSamples; //p0 double p0 = 0; for (int i = 0; i < actionsNumber; i++) { p0 += Convert.ToDouble(matrix[i, i]); } //pc double pc = 0; for (int i = 0; i < actionsNumber; i++) { pc += Convert.ToDouble(cm.ColumnTotals[i]) * Convert.ToDouble(cm.RowTotals[i]); } pc = pc / totalNum; // double kappa = (p0 - pc) / (totalNum - pc); double oa = p0 / totalNum; // return(matrix, kappa, actionsNumber, oa); }