public void apply(String directory) { if (directory[directory.Length - 1] != '\\') { directory += @"\"; } string[] files = System.IO.Directory.GetFiles(directory, "*.png", System.IO.SearchOption.TopDirectoryOnly); if (files.Length == 0) { System.Console.WriteLine("No *.png file found in the specified directory! "); } foreach (string currentFile in files) { String dir = directory; String fn = System.IO.Path.GetFileName(currentFile); System.Console.WriteLine(Environment.NewLine + String.Format("Processing {0} ...", fn)); //create new directory for processing and copy image to this new dir string oldDir = dir; dir += System.IO.Path.GetFileNameWithoutExtension(fn) + @"\"; System.IO.Directory.CreateDirectory(dir); System.IO.File.Copy(oldDir + fn, dir + fn, true); string outPutDir = dir + @"output\"; System.IO.Directory.CreateDirectory(outPutDir); //Find best K ColorSegmentationWorker csw = new ColorSegmentationWorker(); int bestK = csw.Apply(dir, fn); /* Extract layers for the best K csw = new ColorSegmentationWorker(); csw.Apply(dir + fn, bestK, bestK, true); */ /* //Compare extracted layrers and save report CompareImageLayers cp = new CompareImageLayers(); String fileFormat = System.IO.Path.GetFileNameWithoutExtension(fn) + "_ms_mc1024_k" + bestK + "_l{0}" + System.IO.Path.GetExtension(fn); List<KeyValuePair<int, int>> pairList = cp.analysisSimilarityOfLayers(bestK, dir, fileFormat); //Merge similar layers and copy distinct layers cp.generateOutput(pairList, bestK, dir, outPutDir, fileFormat); */ } }
protected override void OnClick() { string straboPath = Environment.GetEnvironmentVariable(ArcStrabo2Extension.EnvironmentVariableSTRABO_HOME, EnvironmentVariableTarget.User); string tessPath = Environment.GetEnvironmentVariable(ArcStrabo2Extension.EnvironmentVariableTESS_DATA, EnvironmentVariableTarget.User); if (ArcStrabo2Extension.PathSet == false) { if (String.IsNullOrEmpty(straboPath) == true) { MessageBox.Show(ArcStrabo2Extension.ErrorMsgNoStraboHome); return; } if (String.IsNullOrEmpty(tessPath) == true) { MessageBox.Show(ArcStrabo2Extension.ErrorMsgNoTess_Data); return; } bool Initialize_straboPath_Correct = ArcStrabo2Extension.initialize_straboPath_directories(straboPath); if (Initialize_straboPath_Correct == false) { MessageBox.Show(ArcStrabo2Extension.ErrorMsgNoStraboHomeWritePermission); return; } ArcStrabo2Extension.PathSet = true; } // // TODO: Sample code showing how to access button host // ArcMap.Application.CurrentTool = null; ComboBoxLayerSelector layerNameCombo = ComboBoxLayerSelector.GetLayerNameComboBox(); RasterLayer rasterlayer = new RasterLayer(); rasterlayer = ((RasterLayer)layerNameCombo.GetSelectedLayer()); //raster.Raster //RasterLayer raster2 = new RasterLayer(); //raster2.CreateFromRaster(raster.Raster); //IMap map = ArcMap.Document.FocusMap; //map.AddLayer((ILayer)raster2); //MessageBox.Show(layerNameCombo.selected_layer_name + " " + raster2.RowCount + " " + raster2.ColumnCount + " " + raster2.BandCount); ColorSegmentationWorker cs = new ColorSegmentationWorker(); try { IRaster2 iraster2 = rasterlayer.Raster as IRaster2; string[] bitmap_fns = cs.Apply(System.IO.Path.GetDirectoryName(iraster2.RasterDataset.CompleteName) + "\\", ArcStrabo2Extension.Text_Result_Path + "\\", System.IO.Path.GetFileName(iraster2.RasterDataset.CompleteName)); IMap map = ArcMap.Document.FocusMap; foreach (string path in bitmap_fns) { //RasterDataset rds = new RasterDataset(); //rds.OpenFromFile(path); RasterLayer rasterlayer2 = new RasterLayer(); rasterlayer2.CreateFromFilePath(path); map.AddLayer(rasterlayer2); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public static void test(String directory) { ColorSegmentationWorker cs = new ColorSegmentationWorker(); cs.Apply(@"C:\Users\yaoyichi\Desktop\Images-22-10\", @"C:\Users\yaoyichi\Desktop\Images-22-10\", "Yao-Yi.png"); }