public void ReLayoutGraph() { //dane potrzebne w metodach obsługujących macierz MatrixMethod.NumberOfVertices = _numberOfVertices; MatrixMethod.ProbabilityValue = _probabilityValue; Graph = new Graph(true); //nowy graf _matrix = MatrixMethod.FillTheMatrix(); //macierz incydencji _existingVertices = new List <Vertex>(); //lista przechowująca wierzchołki //wygenerowanie odpowiedniej ilości wierzchołków for (int i = 0; i < _numberOfVertices; i++) { _existingVertices.Add(new Vertex((i + 1).ToString(), i)); Graph.AddVertex(_existingVertices[i]); } //generowanie krawędzi na podstawie macierzy EdgeMethod.GenerateEdges(_matrix, _existingVertices, Graph); //suma jest zapisana w ostatniej kolumnie macierzy oraz we właściwości obiektu vertex(VertexDegree)<=potrzebne w naprawie VertexMethod.CalculateTheSum(_matrix, _existingVertices); //zapisanie wierzołków sąsiadujących ze sobą(potrzebne w naprawie) VertexMethod.SetVertexNeighbors(_matrix, _existingVertices); UndirectedGraph = new UndirectedBidirectionalGraph <Vertex, Edge>(Graph);//coś jak canvas RefreshMatrixUi();//odświeżenie UI }
private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { //Example graph from AI GraphGenerationMethods graphGenerator = new GraphGenerationMethods(_parameters); graphGenerator.GenerateTriangulationOfGraph(); //Refresh pareto front var cutsSum = EdgeMethod.GetCutsWeightsSum(_parameters.GeneratedBasicGraph, _parameters.Population); var cutsCount = EdgeMethod.GetCutsCount(_parameters.GeneratedBasicGraph, _parameters.Population); var paretoArray = cutsCount. Zip(cutsSum, (first, second) => (first, second)). Select(x => new double[] { x.first, x.second }).ToList(); _parameters.RewriteThePoints(paretoArray); _parameters.MainWindow.ParetoChart.EditSeriesCollection(_parameters.ListOfPoints); //aktualizacja macierzy incydencji MatrixMethod matrixMethod = new MatrixMethod(_parameters); _parameters.incidenceMatrix = matrixMethod.FillTheSecondHalfOfTheMatrix(_parameters.incidenceMatrix); _parameters.GeneratedBasicGraph = EdgeMethod.GenerateEdges(_parameters.incidenceMatrix, _parameters.verticesBasicGeneratedGraph, _parameters.GeneratedBasicGraph); //aktualizacja wyświetlanej macierzy incydencji i wag (frontend) VertexMethod.CalculateTheSum(_parameters.incidenceMatrix, _parameters.verticesTriangulationOfGraph); VertexMethod.SetVertexNeighbors(_parameters.incidenceMatrix, _parameters.verticesTriangulationOfGraph); _parameters.MainWindow.OverallFluctuationChart.EditASeries( _parameters.FitnessArray.Average(), _parameters.IterationNumber); _parameters.MainWindow.SecondChart.EditBSeries( _parameters.FitnessArray.Min(), _parameters.IterationNumber); var minimumFitnessGraphIndex = _parameters.FitnessArray.ToList().IndexOf(_parameters.FitnessArray.Min()); //var minimumFitnessGraphIndex = 0; _parameters.CountedExtremum = $"({cutsCount[minimumFitnessGraphIndex]}; {cutsSum[minimumFitnessGraphIndex]})"; _parameters.MainWindow.ProgressBar.Value = _parameters.IterationNumber; _parameters.CurrentGroupsVertices = GraphGenerationMethods.GetGroupsVertices( _parameters.GeneratedBasicGraph, _parameters.Population, minimumFitnessGraphIndex); string groupsVerticesString = ""; if (_parameters.CurrentGroupsVertices.ContainsValue(0)) { groupsVerticesString += "Warning: group 0 detected. "; } _parameters.CurrentGroupsVertices.OrderBy(x => x.Key.Index).ToList().ForEach(x => groupsVerticesString += $"V: {x.Key.Index + 1}, G: {x.Value}; "); _parameters.MainWindow.GroupList.Content = groupsVerticesString; matrixMethod.RefreshMatrixUi(_parameters.TriangulationOfGraph); _parameters.MainWindow.ResetZoomControl(_parameters.MainWindow.TriangulationGraphZoomControl); }
private void worker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { ////aktualizacja macierzy _matrix = MatrixMethod.FillTheSecondHalfOfTheMatrix(_matrix); //EdgeMethod.RemoveAllGraphEdges(Graph); Graph = EdgeMethod.GenerateEdges(_matrix, _existingVertices, Graph); // int edgeCounter = Graph.Edges.Count(); ////aktualizacja tabeli VertexMethod.CalculateTheSum(_matrix, _existingVertices); VertexMethod.SetVertexNeighbors(_matrix, _existingVertices); RefreshMatrixUi(); }
//function to count edges public int[] EdgeCounts() { var population = parameters.Population; var result = new int[population[0].Length]; for (int i = 0; i < population[0].Length; i++) { //var edgeCount = 0; var groupGraphs = GraphGenerationMethods.GenerateGraphFromCaran(population, i). Where(x => x != null). Where(x => x.VertexCount != 0); groupGraphs.ToList().ForEach(x => EdgeMethod.ConnectAllVertices(x)); var edgeCount = groupGraphs.Select(x => x.EdgeCount).Sum(); result[i] = edgeCount; } return result; }
public static void Edge(Bitmap img, Edgevariant variant, EdgeMethod method, EdgeDirection direction) { LargeEdgeMethodVariant(img, variant, method, direction, 0); }
public static void Edge(Bitmap img, Edgevariant variant, EdgeMethod method, double threshold) { LargeEdgeMethodVariant(img, variant, method, EdgeDirection.def, threshold); }
// private static void LargeEdgeMethodVariant(Bitmap img, Edgevariant variant, EdgeMethod method, EdgeDirection direction, double threshold) { string imgExtension = GetImageInfo.Imginfo(Imageinfo.Extension); string imgName = GetImageInfo.Imginfo(Imageinfo.FileName); string defPath = GetImageInfo.MyPath("Segmentation\\Edge"); Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); int[,] result = new int[img.Height, img.Width]; string outName = String.Empty; double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat); double scale = 0; // for calculating the automatic threshold var imArray = MoreHelpers.BlackandWhiteProcessHelper(img); if (direction == EdgeDirection.def) { direction = EdgeDirection.both; } if ((imArray.GetLength(0) > 1 && imArray.GetLength(1) > 1) && (threshold >= 0 && threshold <= 1) && !(Checks.BinaryInput(img) && threshold == 0)) { switch (method) { case EdgeMethod.Sobel: scale = 4; // for calculating the automatic threshold if (variant == Edgevariant.var1) { result = EdgeHelperv1(scale, imArray, threshold, ImageFilter.Dx3FWindow("Sobel"), ImageFilter.Dx3FWindow("SobelT"), 8, direction, imgName, imgExtension, EdgeTempName._EdgeSobelVar1_temp); if (threshold == 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgeSobV1" + imgExtension; } else if (threshold == 0 && direction != EdgeDirection.def) { outName = defPath + imgName + "_EdgeSobV1_" + direction.ToString() + imgExtension; } else if (threshold != 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgeSobV1" + "Th_" + threshold.ToString() + imgExtension; } else { outName = defPath + imgName + "_EdgeSobV1" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension; } } else { result = EdgeHelperv2(scale, imArray, threshold, ImageFilter.Dx3FWindow("Sobel"), ImageFilter.Dx3FWindow("SobelT"), 8, direction); if (threshold == 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgeSobV2" + imgExtension; } else if (threshold == 0 && direction != EdgeDirection.def) { outName = defPath + imgName + "_EdgeSobV2_" + direction.ToString() + imgExtension; } else if (threshold != 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgeSobV2" + "Th_" + threshold.ToString() + imgExtension; } else { outName = defPath + imgName + "_EdgeSobV2" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension; } } break; case EdgeMethod.Prewitt: scale = 4; // for calculating the automatic threshold if (variant == Edgevariant.var1) { result = EdgeHelperv1(scale, imArray, threshold, ImageFilter.Dx3FWindow("Prewitt"), ImageFilter.Dx3FWindow("PrewittT"), 8, direction, imgName, imgExtension, EdgeTempName._EdgePrewittVar1_temp); if (threshold == 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgePrewV1" + imgExtension; } else if (threshold == 0 && direction != EdgeDirection.def) { outName = defPath + imgName + "_EdgePrewV1_" + direction.ToString() + imgExtension; } else if (threshold != 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgePrewV1" + "Th_" + threshold.ToString() + imgExtension; } else { outName = defPath + imgName + "_EdgePrewV1" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension; } } else { result = EdgeHelperv2(scale, imArray, threshold, ImageFilter.Dx3FWindow("Prewitt"), ImageFilter.Dx3FWindow("PrewittT"), 8, direction); if (threshold == 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgePrewV2" + imgExtension; } else if (threshold == 0 && direction != EdgeDirection.def) { outName = defPath + imgName + "_EdgePrewV2_" + direction.ToString() + imgExtension; } else if (threshold != 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgePrewV2" + "Th_" + threshold.ToString() + imgExtension; } else { outName = defPath + imgName + "_EdgePrewV2" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension; } } break; case EdgeMethod.Roberts: scale = 6; if (variant == Edgevariant.var1) { result = EdgeHelperv1(scale, imArray, threshold, ImageFilter.Dx3FWindow("Roberts"), ImageFilter.Dx3FWindow("RobertsT"), 2, direction, imgName, imgExtension, EdgeTempName._EdgeRobertsVar1_temp); if (threshold == 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgeRobV1" + imgExtension; } else if (threshold == 0 && direction != EdgeDirection.def) { outName = defPath + imgName + "_EdgeRobV1_" + direction.ToString() + imgExtension; } else if (threshold != 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgeRobV1" + "Th_" + threshold.ToString() + imgExtension; } else { outName = defPath + imgName + "_EdgeRobV1" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension; } } else { result = EdgeHelperv2(scale, imArray, threshold, ImageFilter.Dx3FWindow("Roberts"), ImageFilter.Dx3FWindow("RobertsT"), 2, direction); if (threshold == 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgeRobV2" + imgExtension; } else if (threshold == 0 && direction != EdgeDirection.def) { outName = defPath + imgName + "_EdgeRobV2_" + direction.ToString() + imgExtension; } else if (threshold != 0 && direction == EdgeDirection.def) { outName = defPath + imgName + "_EdgeRobV2" + "Th_" + threshold.ToString() + imgExtension; } else { outName = defPath + imgName + "_EdgeRobV2" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension; } } break; } image = Helpers.SetPixels(image, result, result, result); if (Depth == 8) { PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } Helpers.SaveOptions(image, outName, imgExtension); } else { Console.WriteLine("Also Threshold must be in range [0..1]." + "\nOr may be Binary image at input and threshold = 0 - can`t process with such condition."); } }