예제 #1
0
        public void RasterBandPickValueTool()
        {
            GRasterLayer          rasterLayer           = new GRasterLayer(fullFilename);
            IRasterBandCursorTool pRasterBandCursorTool = new GRasterBandCursorTool();

            pRasterBandCursorTool.Visit(rasterLayer.BandCollection[0]);
            double normalValue = pRasterBandCursorTool.PickNormalValue(100, 100);

            //the col and row should be odd number
            double[] rangeNormalValue = pRasterBandCursorTool.PickRangeNormalValue(100, 100, 3, 3);
            double   rawValue         = pRasterBandCursorTool.PickRawValue(100, 100);

            //the col and row should be odd number
            double[] rangeRawValue = pRasterBandCursorTool.PickRangeRawValue(100, 100, 3, 3);
            //
            Assert.AreEqual(normalValue, 0.62204724409448819);
            Assert.AreEqual(string.Join(",", rangeNormalValue), "0.645669291338583,0.637795275590551,0.661417322834646,0.614173228346457,0.622047244094488,0.645669291338583,0.614173228346457,0.618110236220472,0.622047244094488");
            Assert.AreEqual(rawValue, 159);
            Assert.AreEqual(string.Join(",", rangeRawValue), "165,163,169,157,159,165,157,158,159");
        }
예제 #2
0
 public JobCOVRaster(GRasterBand target1band, GRasterBand target2band)
 {
     _t = new Thread(() => {
         IRasterBandCursorTool pRasterBandCursorTool1 = new GRasterBandCursorTool();
         IRasterBandCursorTool pRasterBandCursorTool2 = new GRasterBandCursorTool();
         pRasterBandCursorTool1.Visit(target1band);
         pRasterBandCursorTool2.Visit(target2band);
         //
         int seed        = 0;
         int totalPixels = target1band.Width * target1band.Height;
         Bitmap bitmap   = new Bitmap(target1band.Width, target1band.Height);
         Graphics g      = Graphics.FromImage(bitmap);
         //
         for (int i = 0; i < target1band.Width; i++)
         {
             for (int j = 0; j < target1band.Height; j++)
             {
                 double[] raw1 = pRasterBandCursorTool1.PickRangeRawValue(i, j, 3, 3);
                 double[] raw2 = pRasterBandCursorTool2.PickRangeRawValue(i, j, 3, 3);
                 double cov    = ConvarianceIndex.CalcuteConvarianceIndex(raw1, raw2);
                 //拉伸-1 - 1
                 int gray         = Convert.ToInt32((cov + 1.0) * 20);
                 Color c          = Color.FromArgb(gray, gray, gray);
                 Pen p            = new Pen(c);
                 SolidBrush brush = new SolidBrush(c);
                 g.FillRectangle(brush, new Rectangle(i, j, 1, 1));
                 Process = (double)(seed++) / totalPixels;
             }
         }
         //save result
         string fullFileName = Directory.GetCurrentDirectory() + @"\tmp\" + DateTime.Now.ToFileTimeUtc() + ".png";
         bitmap.Save(fullFileName);
         //
         Summary  = "计算完成";
         Complete = true;
         OnTaskComplete?.Invoke(Name, fullFileName);
     });
 }
예제 #3
0
        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);
        }