コード例 #1
0
 //K-Means非监督分类
 private void KMeansToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         FrmImgSelect FIS = new FrmImgSelect(Images, "K-Means非监督分类 - 选择影像...");
         if (FIS.ShowDialog(this) == DialogResult.OK)
         {
             FrmKMeans FKM = new FrmKMeans();
             if (FKM.ShowDialog(this) == DialogResult.OK)
             {
                 if (Tools.ImageClassification.KMeans(FIS.SelectedImg.GDALDataset, FKM.NumOfClass, FKM.MaxIterate, FKM.ChangeThreshold, FKM.Path))
                 {
                     CheckFile(FKM.Path);
                     ManageTreeView();
                 }
             }
             FKM.Dispose();
         }
         FIS.Dispose();
     }
     catch (Exception err)
     {
         MessageBox.Show(err.ToString());
     }
 }
コード例 #2
0
 //Iso Data非监督分类
 private void IsoDataToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         FrmImgSelect FIS = new FrmImgSelect(Images, "Iso Data非监督分类 - 选择影像...");
         if (FIS.ShowDialog(this) == DialogResult.OK)
         {
             FrmIsoData FID = new FrmIsoData();
             if (FID.ShowDialog(this) == DialogResult.OK)
             {
                 if (Tools.ImageClassification.IsoData(FIS.SelectedImg.GDALDataset, FID.MinNumOfClass, FID.MaxNumOfClass, FID.MaxIterate, FID.MaxClassStddev, FID.MinPixCountInClass, FID.MaxClassStddev, FID.MinClassDistance, FID.Path))
                 {
                     CheckFile(FID.Path);
                     ManageTreeView();
                 }
             }
             FID.Dispose();
         }
         FIS.Dispose();
     }
     catch (Exception err)
     {
         MessageBox.Show(err.ToString());
     }
 }
コード例 #3
0
 //辐射定标
 private void ApplyGainAndOffsetToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         FrmImgSelect FIS = new FrmImgSelect(Images, "辐射定标 - 选择要进行辐射定标的影像...");
         if (FIS.ShowDialog(this) == DialogResult.OK)
         {
             FrmApplyGainOffset AGAO = new FrmApplyGainOffset(FIS.SelectedImg.BandNum);
             if (AGAO.ShowDialog(this) == DialogResult.OK)
             {
                 if (Tools.RadiometricCalibration.ApplyGainAndOffset(FIS.SelectedImg.GDALDataset, AGAO.OutDataType, AGAO.Gains, AGAO.Offsets, AGAO.OutPath))
                 {
                     CheckFile(AGAO.OutPath);
                     ManageTreeView();
                 }
             }
             AGAO.Dispose();
         }
         FIS.Dispose();
     }
     catch (Exception err)
     {
         MessageBox.Show(err.ToString());
     }
 }
コード例 #4
0
 //灰度转换到栅格
 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());
     }
 }
コード例 #5
0
 //直方图匹配
 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());
     }
 }
コード例 #6
0
        //重分类
        private void ReclassifyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FrmImgSelect FIS = new FrmImgSelect(Images, "重分类 - 选择单波段影像...");
                if (FIS.ShowDialog(this) == DialogResult.OK)
                {
                    if (FIS.SelectedImg.BandNum != 1)
                    {
                        throw new ArgumentException("选择的影像不是灰度影像。");
                    }
                    FrmRoughness RF = new FrmRoughness(FIS.SelectedImg);
                    if (RF.ShowDialog(this) == DialogResult.OK)
                    {
                        switch (RF.ConvertMode)
                        {
                        case 0:
                        {
                            if (Tools.BaseProcess.ReplaceNoData(FIS.SelectedImg.GDALDataset, RF.NoDataValue, RF.ReplaceValue, RF.OutDataType, RF.OutPath, RF.NewNoDataValue))
                            {
                                break;
                            }
                            else
                            {
                                throw new OperationCanceledException("操作中断。");
                            }
                        }

                        case 1:
                        {
                            if (Tools.BaseProcess.Reclassify(FIS.SelectedImg.GDALDataset, RF.ReplaceList, RF.OutDataType, RF.OutPath))
                            {
                                break;
                            }
                            else
                            {
                                throw new OperationCanceledException("操作中断。");
                            }
                        }

                        default:
                        {
                            throw new ArgumentException("重分类模式参数错误。");
                        }
                        }
                        CheckFile(RF.OutPath);
                        ManageTreeView();
                    }
                    RF.Dispose();
                }
                FIS.Dispose();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }
コード例 #7
0
 //监督分类(选ROI)
 private void SupervisedClassificationToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         FrmImgSelect FIS = new FrmImgSelect(Images, "监督分类 - 选择栅格底图...");
         if (FIS.ShowDialog(this) == DialogResult.OK)
         {
             //string fileName = @"D:\Documents\VSProjects\RSImage\supervised_test\bin\Debug\CreateROI.exe";
             string fileName = @"ROI\CreateROI.exe";
             if (!File.Exists(fileName))
             {
                 MessageBox.Show("勾选ROI程序不存在,请重新指定位置。");
                 OpenFileDialog OFD = new OpenFileDialog()
                 {
                     CheckFileExists = true,
                     Filter          = "可执行文件(*.exe)|*.exe",
                     FilterIndex     = 1,
                     Multiselect     = false,
                     Title           = "指定勾选ROI程序...",
                 };
                 if (OFD.ShowDialog() == DialogResult.OK)
                 {
                     fileName = OFD.FileName;
                 }
                 else
                 {
                     throw new OperationCanceledException("操作被用户取消。");
                 }
             }
             ProcessStartInfo startInfo = new ProcessStartInfo
             {
                 FileName    = fileName, //启动的应用程序路径
                 Arguments   = FIS.SelectedImg.Path,
                 WindowStyle = ProcessWindowStyle.Maximized,
             };
             Process P = Process.Start(startInfo);
             P.WaitForExit();
             if (P.ExitCode == 1)
             {
                 MessageBox.Show("ROI勾选已完成,请在ENVI中完成监督分类。\r\n(没时间写了,这个程序是我拿的群里曹老大的改的o(=•ェ•=)m)。");
             }
             else
             {
                 MessageBox.Show("ROI勾选程序出现异常或操作被用户取消。");
             }
         }
         FIS.Dispose();
     }
     catch (Exception err)
     {
         MessageBox.Show(err.ToString());
     }
 }
コード例 #8
0
 //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());
     }
 }
コード例 #9
0
 //平滑锐化
 private void SmoothSharpToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         FrmImgSelect FIS = new FrmImgSelect(Images, "平滑锐化 - 选择影像...");
         if (FIS.ShowDialog(this) == DialogResult.OK)
         {
             FrmSmooth S = new FrmSmooth(FIS.SelectedImg);
             if (S.ShowDialog(this) == DialogResult.OK)
             {
                 CheckFile(S.OutPath);
                 ManageTreeView();
                 S.Dispose();
             }
             FIS.Dispose();
         }
     }
     catch (Exception err)
     {
         MessageBox.Show(err.ToString());
     }
 }
コード例 #10
0
        //变化检测
        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());
            }
        }
コード例 #11
0
 //地理配准
 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());
     }
 }
コード例 #12
0
        //阈值分割
        private void ThresholdToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FrmImgSelect FIS = new FrmImgSelect(Images, "阈值分割 - 选择单波段影像...");
                if (FIS.ShowDialog(this) == DialogResult.OK)
                {
                    if (FIS.SelectedImg.BandNum != 1)
                    {
                        throw new ArgumentException("选择的影像不是灰度影像。");
                    }
                    FrmBinarize FB = new FrmBinarize(FIS.SelectedImg);
                    if (FB.ShowDialog(this) == DialogResult.OK)
                    {
                        switch (FB.method)
                        {
                        //手动
                        case ImageSplitMethods.Manual_None:
                        {
                            if (Tools.ImageSplit.Binarize(FIS.SelectedImg.GDALDataset, FB.Threshold, FB.ZeroValueSelector.Value, FB.OneValueSelector.Value, FB.BFilePathSelector.OutDataType, FB.BFilePathSelector.Path))
                            {
                                CheckFile(FB.BFilePathSelector.Path);
                                ManageTreeView();
                            }
                            break;
                        }

                        //Otsu
                        case ImageSplitMethods.Auto_Otsu:
                        {
                            double tmpThreshold = Tools.ImageSplit.Otsu(FIS.SelectedImg.GDALDataset);
                            if (Tools.ImageSplit.Binarize(FIS.SelectedImg.GDALDataset, tmpThreshold, FB.ZeroValueSelector.Value, FB.OneValueSelector.Value, FB.BFilePathSelector.OutDataType, FB.BFilePathSelector.Path))
                            {
                                CheckFile(FB.BFilePathSelector.Path);
                                ManageTreeView();
                            }
                            break;
                        }

                        //迭代
                        case ImageSplitMethods.Auto_Iterate:
                        {
                            double tmpThreshold = Tools.ImageSplit.IterateThreshold(FIS.SelectedImg.GDALDataset);
                            if (Tools.ImageSplit.Binarize(FIS.SelectedImg.GDALDataset, tmpThreshold, FB.ZeroValueSelector.Value, FB.OneValueSelector.Value, FB.BFilePathSelector.OutDataType, FB.BFilePathSelector.Path))
                            {
                                CheckFile(FB.BFilePathSelector.Path);
                                ManageTreeView();
                            }
                            break;
                        }
                        }
                    }
                    FB.Dispose();
                }
                FIS.Dispose();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }