/// <summary> /// 底图区域功能按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Map_function_Click(object sender, EventArgs e) { ToolStripItem item = sender as ToolStripItem; switch (item.Name) { case "Export_Bitmap_ToolStripMenuItem": Bitmap saveBmp = map_pictureBox.Image as Bitmap; SaveBitmap(saveBmp); //导出图片 break; case "DL_CLASS_toolStripButton": if (map_treeView.SelectedNode == null) { UpdateStatusLabel("请选择一副图像或者一个图层后,进行分类操作", STATUE_ENUM.ERROR); return; } else { DLClassifyForm dlclassify = new DLClassifyForm(); if (dlclassify.ShowDialog() == DialogResult.OK) { //1.选择处理那副图像 string imageName = map_treeView.SelectedNode.Text; Bitmap2 imageBitmap2 = _imageDic[imageName]; GRasterLayer rasterLayer = imageBitmap2.GdalLayer; ThreadStart clsfy_ts = delegate { RunClassify(rasterLayer, dlclassify.UseSLIC, dlclassify.PBName, dlclassify.CenterName, dlclassify.LabelName); }; Thread clsfy_t = new Thread(clsfy_ts); clsfy_t.IsBackground = true; clsfy_t.Start(); } } break; case "open_toolstripmenuitem": //添加图像 ReadImage(); break; case "open_contextMenuStrip": ReadImage(); break; //超像素分割 case "SLIC_toolStripButton": case "SLIC_toolStripMenu": Bitmap bmp = map_pictureBox.Image as Bitmap; if (bmp != null) { ThreadStart slic_ts = delegate { RunSLIC(bmp); }; Thread slic_t = new Thread(slic_ts); slic_t.IsBackground = true; slic_t.Start(); } else { UpdateStatusLabel("未选中待计算图像,地图区域无图片", STATUE_ENUM.ERROR); } break; //超像素中心应用 case "SLIC_Center_toolStripButton": case "SLIC_Center_toolStripMenu": OpenFileDialog opg = new OpenFileDialog { Filter = "JSON文件|*.json" }; if (opg.ShowDialog() == DialogResult.OK) { //1.读取center中心 using (StreamReader sr = new StreamReader(opg.FileName)) { List <byte> colors = new List <byte>(); Center[] centers = SuperPixelSegment.ReadCenter(sr.ReadToEnd()); //2.设置使用图层 CenterApplyForm centerApplyForm = new CenterApplyForm(); if (centerApplyForm.ShowDialog() == DialogResult.OK) { ThreadStart s = delegate { RunCenter(centerApplyForm.FileNameCollection, centers); }; Thread t = new Thread(s) { IsBackground = true }; t.Start(); } } } break; default: break; } }
/// <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)); } } } } }
/// <summary> /// 底图区域功能按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Map_function_Click(object sender, EventArgs e) { ToolStripItem item = sender as ToolStripItem; switch (item.Name) { //rpc transform case "RPC_ToolStripMenuItem": RPCForm rpcForm = new RPCForm(); if (rpcForm.ShowDialog() == DialogResult.OK) { IJob rpcRectifyJob = new IJobRPCRectify(rpcForm.A, rpcForm.B, rpcForm.C, rpcForm.D, rpcForm.RPCParamaters, rpcForm.RawBinRasterFullFilenames); RegisterJob(rpcRectifyJob); rpcRectifyJob.Start(); } break; //cov matrix case "cov_toolStripButton": COVForm covForm = new COVForm(); covForm.RasterDic = _rasterDic; if (covForm.ShowDialog() == DialogResult.OK) { GRasterBand band1 = _rasterDic[covForm.Target1Key].BandCollection[0]; GRasterBand band2 = _rasterDic[covForm.Target2Key].BandCollection[0]; IJob covRasterJob = new JobCOVRaster(band1, band2); RegisterJob(covRasterJob); covRasterJob.Start(); } break; //task case "task_toolStripButton": TaskMonitor taskForm = new TaskMonitor(); taskForm.Jobs = _jobs; taskForm.ShowDialog(); break; //calucte kappa case "kappa_toolStripButton": KappaForm kappaForm = new KappaForm(); kappaForm.RasterDic = _rasterDic; kappaForm.ShowDialog(); break; //添加图像 case "open_toolstripmenuitem": case "open_contextMenuStrip": ReadImage(); break; //超像素分割 case "SLIC_toolStripButton": case "SLIC_toolStripMenu": Bitmap bmp = map_pictureBox.Image as Bitmap; if (bmp != null) { ThreadStart slic_ts = delegate { RunSLIC(bmp); }; Thread slic_t = new Thread(slic_ts); slic_t.IsBackground = true; slic_t.Start(); } else { UpdateStatusLabel("未选中待计算图像,地图区域无图片", STATUE_ENUM.ERROR); } break; //super pixel case "SLIC_Center_toolStripButton": case "SLIC_Center_toolStripMenu": OpenFileDialog opg = new OpenFileDialog { Filter = "JSON文件|*.json" }; if (opg.ShowDialog() == DialogResult.OK) { //1.读取center中心 using (StreamReader sr = new StreamReader(opg.FileName)) { List <byte> colors = new List <byte>(); Center[] centers = SuperPixelSegment.ReadCenter(sr.ReadToEnd()); //2.设置使用图层 SLICForm centerApplyForm = new SLICForm(); if (centerApplyForm.ShowDialog() == DialogResult.OK) { ThreadStart s = delegate { RunCenter(centerApplyForm.FileNameCollection, centers); }; Thread t = new Thread(s); t.IsBackground = true; t.Start(); } } } break; //dqn classification case "DQN_toolStripButton": DQNForm dqnForm = new DQNForm(); dqnForm.RasterDic = _rasterDic; if (dqnForm.ShowDialog() == DialogResult.OK) { //"Image Classification", if (dqnForm.TaskName == "Image Classification") { IJob dqnClassifyJob = new JobDQNClassify(_rasterDic[dqnForm.SelectedFeatureRasterLayer], _rasterDic[dqnForm.SelectedLabelRasterLayer], dqnForm.Epochs); RegisterJob(dqnClassifyJob); dqnClassifyJob.Start(); } //"Road Extraction" else if (dqnForm.TaskName == "Road Extraction") { } } break; //cnn classification case "CNN_toolStripButton": CNNForm cnnForm = new CNNForm(); cnnForm.RasterDic = _rasterDic; if (cnnForm.ShowDialog() == DialogResult.OK) { IJob cnnClassifyJob = new JobCNNClassify(_rasterDic[cnnForm.SelectedFeatureRasterLayer], _rasterDic[cnnForm.SelectedLabelRasterLayer], cnnForm.Epochs, cnnForm.Model, cnnForm.ImageWidth, cnnForm.ImageHeight, 1); RegisterJob(cnnClassifyJob); cnnClassifyJob.Start(); } break; //random forest classification case "rf_toolStripButton": RandomForestForm rfForm = new RandomForestForm(); rfForm.RasterDic = _rasterDic; if (rfForm.ShowDialog() == DialogResult.OK) { IJob rfJob = new JobRFClassify(rfForm.TreeCount, rfForm.FullFilename, _rasterDic[rfForm.FeatureKey]); RegisterJob(rfJob); rfJob.Start(); } break; //drawing comparsion multi-reslut curve case "Compare_Plot_toolStripButton": ComparedPlotForm cp_form = new ComparedPlotForm(); cp_form.ShowDialog(); break; default: break; } }