public static void PrintLn(Object Message, AdvColor backcolor, AdvColor forceColor) { BackColorCheck(backcolor); ForceColorCheck(forceColor); Console.WriteLine(Message); Console.ResetColor(); }
private void button1_Click(object sender, EventArgs e) { Histogram histogram = img.BuildHistogram(); //low bins to 0 out int low_bins = histogram.GetNumBinsWithItems(Convert.ToInt32(img.GetHeight() * img.GetWidth() * .10)); AdvColor low_color = histogram.GetBinColor(low_bins); int high_bins = histogram.GetNumBinsWithItems(Convert.ToInt32(img.GetHeight() * img.GetWidth() * .90)); AdvColor high_color = histogram.GetBinColor(high_bins); AdvColor[,] pixels = img.HistogramStretch(low_color, high_color, histogram, ColorPlane.eGreen); SortedDictionary <AdvColor, int> bins = histogram.GetHistogram(); foreach (KeyValuePair <AdvColor, int> bin in bins) { chart1.Series["Series1"].Points.AddXY(bin.Key.GetColor(ColorPlane.eGreen), bin.Value); } RGBImage img2 = new RGBImage(pixels); img.SaveToImage(pixels, "histo_stretch.png"); Histogram histogram2 = img2.BuildHistogram(); SortedDictionary <AdvColor, int> bins2 = histogram2.GetHistogram(); foreach (KeyValuePair <AdvColor, int> bin in bins2) { chart2.Series["Series1"].Points.AddXY(bin.Key.GetColor(ColorPlane.eGreen), bin.Value); } }
public static void Print(Object Message, AdvColor Backcolor, AdvColor ForceColor) { BackColorCheck(Backcolor); ForceColorCheck(ForceColor); Console.Write(Message); Console.ResetColor(); }
public static void Print(Object Message, AdvColor ForceColor) { ForceColorCheck(ForceColor); Console.Write(Message); //rasool Console.ResetColor(); }
/// <summary> /// Calculate closest color name and return it as string /// </summary> /// <param name="currentColor"></param> /// <returns>Closest color name</returns> private string CalculateCloseColor(Color currentColor) { double res = double.MaxValue; var resColor = AdvColor.CreateInstance(Color.Black); var current = AdvColor.CreateInstance(currentColor); foreach (var color in ColorsData.Colors) { double tmp = ColorCalc.DeltaE2000(color, current); if (!(res > tmp)) { continue; } resColor = color; res = tmp; } return(resColor.Name); }
private static void BackColorCheck(AdvColor color) { switch (color) { case AdvColor.Blue: Console.BackgroundColor = ConsoleColor.Blue; break; case AdvColor.Black: Console.BackgroundColor = ConsoleColor.Black; break; case AdvColor.Red: Console.BackgroundColor = ConsoleColor.Red; break; case AdvColor.Yellow: Console.BackgroundColor = ConsoleColor.Yellow; break; case AdvColor.Green: Console.BackgroundColor = ConsoleColor.Green; break; case AdvColor.Cyan: Console.BackgroundColor = ConsoleColor.Cyan; break; case AdvColor.White: Console.BackgroundColor = ConsoleColor.White; break; case AdvColor.Magenta: Console.BackgroundColor = ConsoleColor.Magenta; break; case AdvColor.Gray: Console.BackgroundColor = ConsoleColor.Gray; break; case AdvColor.DarkBlue: Console.BackgroundColor = ConsoleColor.DarkBlue; break; case AdvColor.DarkCyan: Console.BackgroundColor = ConsoleColor.DarkCyan; break; case AdvColor.DarkGray: Console.BackgroundColor = ConsoleColor.DarkGray; break; case AdvColor.DarkGreen: Console.BackgroundColor = ConsoleColor.DarkGreen; break; case AdvColor.DarkMagenta: Console.BackgroundColor = ConsoleColor.DarkMagenta; break; case AdvColor.DarkRed: Console.BackgroundColor = ConsoleColor.DarkRed; break; case AdvColor.DarkYellow: Console.BackgroundColor = ConsoleColor.DarkYellow; break; } }
private void btnLoadImage_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { img = new RGBImage(openFileDialog1.FileName, ColorPlane.eGreen); List <int> shapes = img.FindShapes(); List <List <BoundaryMove> > shape_boundaries = new List <List <BoundaryMove> >(); List <List <double> > moments = new List <List <double> >(); List <List <BoundaryMove> > hull_bounadaries = new List <List <BoundaryMove> >(); ConvexHull hull = new ConvexHull(); for (int i = 0; i < shapes.Count; i++) { List <BoundaryMove> boundary = img.GetBoundaryPixels(shapes[i]); shape_boundaries.Add(boundary); moments.Add(img.CalcMoments(shapes[i])); hull_bounadaries.Add(hull.CalcQuickHull(boundary)); } for (int i = 0; i < shapes.Count; i++) { String filename = String.Format("boundary{0}.txt", i + 1); StreamWriter writer = new StreamWriter(filename); List <double> boundary_moments = moments[i]; for (int ii = 0; ii < boundary_moments.Count; ii++) { writer.Write(boundary_moments[ii]); if (ii < boundary_moments.Count) { writer.Write(", "); } } writer.Write(System.Environment.NewLine); List <BoundaryMove> convexHull = hull_bounadaries[i]; for (int ii = 0; ii < convexHull.Count; ii++) { writer.WriteLine("" + convexHull[ii].X + ", " + convexHull[ii].Y); } List <BoundaryMove> boundary = shape_boundaries[i]; for (int ii = 0; ii < boundary.Count; ii++) { if (ii == 0) { writer.Write(boundary[ii].X + ", " + boundary[ii].Y); } writer.Write(boundary[ii].GetDirectionString() + " "); } writer.Flush(); writer.Close(); } AdvColor[,] black_img = new AdvColor[256, 256]; for (int i = 0; i < black_img.GetLength(0); i++) { for (int j = 0; j < black_img.GetLength(1); j++) { black_img[i, j] = new AdvColor(0, 0, 0, ColorPlane.eGreen); } } /*foreach (List<BoundaryMove> shape in shape_boundaries) * { * img.OutlineShape(shape, black_img); * }*/ foreach (List <BoundaryMove> _hull in hull_bounadaries) { img.OutlineHull(_hull, black_img); } img.SaveToImage(black_img, "TestConvexHullOutput.png"); } }