//灰度转换到栅格 private void ConvertToAAIGridToolStripMenuItem_Click(object sender, EventArgs e) { try { FrmImgSelect FIS = new FrmImgSelect(Images, "灰度影像转换到栅格 - 选择影像..."); if (FIS.ShowDialog(this) == DialogResult.OK) { FrmExport E = new FrmExport(Filter: "All files|*.*|AAIGrid files|*.asc"); E.EFFilePathSelector.OutDataType = FIS.SelectedImg.GDALDataset.GetRasterBand(1).DataType; if (E.ShowDialog(this) == DialogResult.OK) { if (Tools.BaseProcess.ConvertToAAIGrid(FIS.SelectedImg.GDALDataset, "AAIGrid", E.OutPath)) { CheckFile(E.OutPath); ManageTreeView(); } } E.Dispose(); } FIS.Dispose(); } catch (Exception err) { MessageBox.Show(err.ToString()); } }
//直方图匹配 private void HistogramMatchingToolStripMenuItem_Click(object sender, EventArgs e) { try { FrmImgSelect FIS1 = new FrmImgSelect(Images, "直方图匹配 - 选择要进行直方图匹配的影像..."); if (FIS1.ShowDialog(this) == DialogResult.OK) { FrmImgSelect FIS2 = new FrmImgSelect(Images, "直方图匹配 - 选择要匹配到的影像..."); if (FIS2.ShowDialog(this) == DialogResult.OK) { if (FIS1.SelectedImg.BandNum != FIS2.SelectedImg.BandNum) { throw new ArgumentException("选择的两影像波段数不一致。"); } FrmExport E = new FrmExport(); if (E.ShowDialog(this) == DialogResult.OK) { if (Tools.BaseProcess.HistogramMatching(FIS1.SelectedImg.GDALDataset, FIS2.SelectedImg.GDALDataset, FIS1.SelectedImg.CumulativeProbability, FIS2.SelectedImg.CumulativeProbability, E.OutDataType, E.OutPath)) { CheckFile(E.OutPath); ManageTreeView(); } } E.Dispose(); } FIS2.Dispose(); } FIS1.Dispose(); } catch (Exception err) { MessageBox.Show(err.ToString()); } }
//IHS融合 private void IHSToolStripMenuItem_Click(object sender, EventArgs e) { try { //选择全色影像 FrmImgSelect FIS1 = new FrmImgSelect(Images, "IHS融合 - 选择全色影像..."); if (FIS1.ShowDialog(this) == DialogResult.OK) { if (FIS1.SelectedImg.BandNum != 1) { throw new ArgumentException("全色影像光谱数不为1。"); } //选择多光谱影像 FrmImgSelect FIS2 = new FrmImgSelect(Images, "IHS融合 - 选择多光谱影像..."); if (FIS2.ShowDialog(this) == DialogResult.OK) { //选择多光谱影像波段组合 FrmBandSelector FBS = new FrmBandSelector(FIS2.SelectedImg); if (FBS.ShowDialog(this) == DialogResult.OK) { //选择导出位置 FrmExport E = new FrmExport(); if (E.ShowDialog(this) == DialogResult.OK) { if (Tools.ImageFusion.IHSFusion(FIS1.SelectedImg.GDALDataset, FIS2.SelectedImg.GDALDataset, FIS1.SelectedImg.CumulativeProbability, FIS2.SelectedImg.CumulativeProbability, FBS.BandList, E.OutDataType, E.OutPath)) { CheckFile(E.OutPath); ManageTreeView(); } E.Dispose(); } FBS.Dispose(); } FIS2.Dispose(); } FIS1.Dispose(); } } catch (Exception err) { MessageBox.Show(err.ToString()); } }
//导出当前视图 private void ExportViewToolStripMenuItem_Click(object sender, EventArgs e) { try { Img img = Images[DisplayImageIndex]; FrmExport EF = new FrmExport(); if (EF.ShowDialog(this) == DialogResult.OK) { if (Tools.Common.ExportView(img, EF.OutDataType, EF.OutPath)) { CheckFile(EF.OutPath); ManageTreeView(); } } EF.Dispose(); } catch (Exception err) { MessageBox.Show(err.ToString()); } }
//变化检测 private void ChangeDetectionToolStripMenuItem_Click(object sender, EventArgs e) { try { //选择第一张影像 FrmImgSelect FIS1 = new FrmImgSelect(Images, "变化检测 - 选择变化前影像..."); if (FIS1.ShowDialog(this) == DialogResult.OK) { //选择第二张影像 FrmImgSelect FIS2 = new FrmImgSelect(Images, "变化检测 - 选择变化后影像..."); if (FIS2.ShowDialog(this) == DialogResult.OK) { //选择差值影像导出位置 FrmExport E1 = new FrmExport("选择差值计算结果存储位置。"); if (E1.ShowDialog(this) == DialogResult.OK) { //选择比值影像导出位置 FrmExport E2 = new FrmExport("选择比值计算结果存储位置。"); if (E2.ShowDialog(this) == DialogResult.OK) { string tmpD1Gray = Tools.Common.GetTempFileName(); string tmpD2Gray = Tools.Common.GetTempFileName(); string tmpMinus = Tools.Common.GetTempFileName(); string tmpDivide = Tools.Common.GetTempFileName(); bool divSucc = false; bool minusSucc = false; //灰度化 if (Tools.Common.RGB2GrayScale(FIS1.SelectedImg, new double[3] { 0.299, 0.587, 0.114 }, DataType.GDT_Float32, tmpD1Gray)) { OSGeo.GDAL.Dataset tmpD1GrayDS = OSGeo.GDAL.Gdal.Open(tmpD1Gray, OSGeo.GDAL.Access.GA_ReadOnly); if (Tools.Common.RGB2GrayScale(FIS2.SelectedImg, new double[3] { 0.299, 0.587, 0.114 }, DataType.GDT_Float32, tmpD2Gray)) { OSGeo.GDAL.Dataset tmpD2GrayDS = OSGeo.GDAL.Gdal.Open(tmpD2Gray, OSGeo.GDAL.Access.GA_ReadOnly); //相减 if (Tools.BaseProcess.Minus(tmpD2GrayDS, tmpD1GrayDS, DataType.GDT_Float32, tmpMinus)) { OSGeo.GDAL.Dataset tmpMinusDS = OSGeo.GDAL.Gdal.Open(tmpMinus, OSGeo.GDAL.Access.GA_ReadOnly); if (Tools.ImageSplit.Binarize(tmpMinusDS, Tools.ImageSplit.IterateThreshold(tmpMinusDS), 0, 1, E1.OutDataType, E1.OutPath)) { minusSucc = true; } tmpMinusDS.Dispose(); if (File.Exists(tmpMinus)) { File.Delete(tmpMinus); } } //相除 if (Tools.BaseProcess.Divide(tmpD2GrayDS, tmpD1GrayDS, DataType.GDT_Float32, tmpDivide)) { OSGeo.GDAL.Dataset tmpDivideDS = OSGeo.GDAL.Gdal.Open(tmpDivide, OSGeo.GDAL.Access.GA_ReadOnly); if (Tools.ImageSplit.Binarize(tmpDivideDS, Tools.ImageSplit.IterateThreshold(tmpDivideDS), 0, 1, E2.OutDataType, E2.OutPath)) { divSucc = true; } tmpDivideDS.Dispose(); if (File.Exists(tmpDivide)) { File.Delete(tmpDivide); } } tmpD2GrayDS.Dispose(); if (File.Exists(tmpD2Gray)) { File.Delete(tmpD2Gray); } } tmpD1GrayDS.Dispose(); if (File.Exists(tmpD1Gray)) { File.Delete(tmpD1Gray); } } if (minusSucc) { CheckFile(E1.OutPath); ManageTreeView(); } if (divSucc) { CheckFile(E2.OutPath); ManageTreeView(); } } E2.Dispose(); } E1.Dispose(); } FIS2.Dispose(); } FIS1.Dispose(); } catch (Exception err) { MessageBox.Show(err.ToString()); } }
//地理配准 private void GeoreferncingToolStripMenuItem_Click(object sender, EventArgs e) { try { FrmImgSelect FIS1 = new FrmImgSelect(Images, "地理配准 - 选择栅格底图..."); if (FIS1.ShowDialog(this) == DialogResult.OK) { FrmImgSelect FIS2 = new FrmImgSelect(Images, "地理配准 - 选择要配准的栅格影像..."); if (FIS2.ShowDialog(this) == DialogResult.OK) { FrmExport FE = new FrmExport(); if (FE.ShowDialog(this) == DialogResult.OK) { //string fileName = @"D:\Documents\VSProjects\RSImage\ImgGeoReg\bin\Debug\ImgGeoReg.exe"; string fileName = @"REG\ImgGeoReg.exe"; if (!File.Exists(fileName)) { MessageBox.Show("配准程序不存在,请重新指定位置。"); OpenFileDialog OFD = new OpenFileDialog() { CheckFileExists = true, Filter = "可执行文件(*.exe)|*.exe", FilterIndex = 1, Multiselect = false, Title = "指定配准程序...", }; if (OFD.ShowDialog() == DialogResult.OK) { fileName = OFD.FileName; } else { throw new OperationCanceledException("操作被用户取消。"); } } File.Copy(FIS2.SelectedImg.Path, FE.OutPath); ProcessStartInfo startInfo = new ProcessStartInfo { FileName = fileName, //启动的应用程序路径 Arguments = FIS1.SelectedImg.Path + " " + FE.OutPath, WindowStyle = ProcessWindowStyle.Maximized, }; Process P = Process.Start(startInfo); P.WaitForExit(); if (P.ExitCode == 1) { MessageBox.Show("配准已完成,GCP存储在xml文件中。"); } else { MessageBox.Show("配准程序出现异常或操作被用户取消。"); } } FE.Dispose(); } FIS2.Dispose(); } FIS1.Dispose(); } catch (Exception err) { MessageBox.Show(err.ToString()); } }