예제 #1
0
        public Bitplane(Bitplane bitplane)
        {
            Width  = bitplane.Width;
            Height = bitplane.Height;

            for (int y = 0; y < this.Height; ++y)
            {
                for (int x = 0; x < this.Width; ++x)
                {
                    SetPixel(x, y, bitplane.GetPixel(x, y));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 应用深度学习模型进行分类
        /// </summary>
        /// <param name="rasterLayer"></param>
        private void RunClassify(GRasterLayer rasterLayer, bool useSLIC, string pbName, string centerName, string labelName)
        {
            //判断图层结构,选用不同的tensor输入
            ShapeEnum shapeEuum;

            if (rasterLayer.BandCount == 130)
            {
                shapeEuum = ShapeEnum.THIRTEEN_TEN;
            }
            else if (rasterLayer.BandCount == 100)
            {
                shapeEuum = ShapeEnum.TEN_TEN;
            }
            else if (rasterLayer.BandCount == 64)
            {
                shapeEuum = ShapeEnum.EIGHT_EIGHT;
            }
            else
            {
                shapeEuum = ShapeEnum.TEN_TEN;
            }
            //构建结果图层,用于动态绘制
            Bitmap   bmp          = new Bitmap(rasterLayer.XSize, rasterLayer.YSize);
            string   nodeName     = rasterLayer.Name + "结果图层";
            TreeNode childrenNode = new TreeNode(nodeName);

            _imageDic.Add(nodeName, new Bitmap2(name: nodeName, bmp: bmp));
            Invoke(new UpdateTreeNodeHandler(UpdateTreeNode), null, childrenNode);
            //获取波段
            TensorflowBootstrap model = new TensorflowBootstrap(pbName);

            //判断是否基于超像素
            if (!useSLIC)
            {
                for (int i = 0; i < rasterLayer.XSize; i++)
                {
                    for (int j = 0; j < rasterLayer.YSize; j++)
                    {
                        float[] input      = rasterLayer.GetPixelFloat(i, j).ToArray();
                        long    classified = model.Classify(input, shapeEuum);
                        Invoke(new PaintPointHandler(PaintPoint), bmp, i, j, Convert.ToByte(classified * 15));
                        Invoke(new UpdateStatusLabelHandler(UpdateStatusLabel), "应用分类中,总进度:" + i + "列" + j + "行", STATUE_ENUM.WARNING);
                    }
                }
            }
            else
            {
                //基于slic的超像素绘制方法
                using (StreamReader sr_center = new StreamReader(centerName))
                    using (StreamReader sr_label = new StreamReader(labelName))
                    {
                        Center[] centers = SuperPixelSegment.ReadCenter(sr_center.ReadToEnd());
                        Bitplane labels  = SuperPixelSegment.ReadLabel(sr_label.ReadToEnd());
                        int[]    mask    = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
                        for (int i = 0; i < centers.Length; i++)
                        {
                            Center  center     = centers[i];
                            float[] input      = rasterLayer.GetPixelFloatWidthConv((int)center.X, (int)center.Y, mask).ToArray();
                            long    classified = model.Classify(input, shapeEuum);
                            center.L = classified * 15;
                            center.A = classified * 15;
                            center.B = classified * 15;
                            Invoke(new UpdateStatusLabelHandler(UpdateStatusLabel), "已处理第" + i + "/" + centers.Length + "个中心", STATUE_ENUM.WARNING);
                        }
                        //遍历图片进行绘制
                        for (int i = 0; i < rasterLayer.XSize; i++)
                        {
                            for (int j = 0; j < rasterLayer.YSize; j++)
                            {
                                Invoke(new PaintPointHandler(PaintPoint), bmp, i, j, Convert.ToByte(centers[(int)Math.Floor(labels.GetPixel(i, j))].L));
                            }
                        }
                    }
            }
        }