public void blobcounter_test() { string basePath = Path.Combine(NUnit.Framework.TestContext.CurrentContext.TestDirectory, "Resources"); #region doc_process // Load an example image containing blobs (such the sample from the Blob Detection sample applications) // https://github.com/accord-net/framework/raw/development/Samples/Imaging/Detection%20(Blobs)/demo.png Bitmap image = Accord.Imaging.Image.FromFile(Path.Combine(basePath, "blob-input.png")); // Creeate a new blob counter object var blobCounter = new BlobCounter(); // Process the image looking for blobs blobCounter.ProcessImage(image); // Get information about all the image blobs found: Blob[] blobs = blobCounter.GetObjectsInformation(); // Prepare to extract their Convex Hull var grahamScan = new GrahamConvexHull(); var colors = new ColorSequenceCollection(); // For each blob in the image for (int i = 0; i < blobs.Length; i++) { // Get the blob Blob blob = blobs[i]; // Collect edge points List <IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blob); // Find convex hull List <IntPoint> hull = grahamScan.FindHull(edgePoints); // Prepare to mark the hull in the image var marker = new PointsMarker(colors[i]) { Points = hull, Connect = true // connect the points with line segments }; // Draw the hull lines marker.ApplyInPlace(image); } // Save the image to disk image.Save(Path.Combine(basePath, "test.png")); #endregion Assert.AreEqual(25, blobs.Length); }
public void CreateScatterplot(ZedGraphControl zgc, double[,] graph) { GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles myPane.Title.IsVisible = false; myPane.XAxis.Title.Text = columnNames[0]; myPane.YAxis.Title.Text = columnNames[1]; // Classification problem var lists = new Dictionary <double, PointPairList>(); var unique = graph.GetColumn(2).Distinct(); foreach (var u in unique) { lists[u] = new PointPairList(); } for (int i = 0; i < graph.GetLength(0); i++) { lists[graph[i, 2]].Add(graph[i, 0], graph[i, 1]); } var seq = new ColorSequenceCollection(); // Add the curve for (int i = 0; i < unique.Length; i++) { var color = seq.GetColor(i); LineItem myCurve = myPane.AddCurve("G" + i, lists[unique[i]], color, SymbolType.Diamond); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = false; myCurve.Symbol.Fill = new Fill(color); } // Fill the background of the chart rect and pane //myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); //myPane.Fill = new Fill(Color.White, Color.SlateGray, 45.0f); myPane.Fill = new Fill(Color.WhiteSmoke); zgc.AxisChange(); zgc.Invalidate(); }
public void CreateComponentDistributionGraph(ZedGraphControl zgc) { ColorSequenceCollection sequence = new ColorSequenceCollection(); GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the GraphPane title myPane.Title.Text = "Component Proportion"; myPane.Title.FontSpec.Size = 24f; myPane.Title.FontSpec.Family = "Tahoma"; // Fill the pane background with a color gradient // myPane.Fill = new Fill(Color.White, Color.WhiteSmoke, 45.0f); // No fill for the chart background myPane.Chart.Fill.Type = FillType.None; myPane.Legend.IsVisible = false; // Add some pie slices for (int i = 0; i < pca.Components.Count; i++) { myPane.AddPieSlice(pca.Components[i].Proportion, sequence[i], 0.1, pca.Components[i].Index.ToString()); } myPane.XAxis.Scale.MinAuto = true; myPane.XAxis.Scale.MaxAuto = true; myPane.YAxis.Scale.MinAuto = true; myPane.YAxis.Scale.MaxAuto = true; myPane.XAxis.Scale.MagAuto = true; myPane.YAxis.Scale.MagAuto = true; // Calculate the Axis Scale Ranges zgc.AxisChange(); zgc.Invalidate(); }
private void CreateBarGraph(double[] weights, string[] featureNames) { var zgc = graphSupportVectors; GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles myPane.Title.IsVisible = false; myPane.XAxis.Title.Text = "Weight importance"; myPane.YAxis.Title.Text = "Features"; var colors = new ColorSequenceCollection(); for (int i = 0; i < featureNames.Length; i++) { myPane.AddBar(featureNames[i], new double[] { i }, new[] { weights[i] }, colors[i]); } myPane.Fill = new Fill(Color.WhiteSmoke); zgc.AxisChange(); zgc.Invalidate(); }
/// <summary> /// Forces a update of the scatter plot. /// </summary> /// public void UpdateGraph() { zedGraphControl.GraphPane.Title.Text = scatterplot.Title; zedGraphControl.GraphPane.XAxis.Title.Text = Scatterplot.XAxisTitle; zedGraphControl.GraphPane.YAxis.Title.Text = Scatterplot.YAxisTitle; classes.Clear(); if (scatterplot.Classes != null) { if (scatterplot.Classes.Count == 0) { zedGraphControl.GraphPane.Legend.IsVisible = false; // Create space for unlabelled data PointPairList list = new PointPairList(scatterplot.XAxis, scatterplot.YAxis); LineItem item = new LineItem(String.Empty, list, Color.Black, SymbolType.Default); item.Line.IsVisible = LinesVisible; item.Symbol.Border.IsVisible = false; item.Symbol.Fill = new Fill(Color.Black); if (SymbolSize == 0) item.Symbol.IsVisible = false; else item.Symbol.Size = SymbolSize; classes.Add(item); } else { zedGraphControl.GraphPane.Legend.IsVisible = true; var colors = new ColorSequenceCollection(scatterplot.Classes.Count); // Create a curve item for each of the labels for (int i = 0; i < scatterplot.Classes.Count; i++) { // retrieve the x,y pairs for the label double[] x = scatterplot.Classes[i].XAxis; double[] y = scatterplot.Classes[i].YAxis; PointPairList list = new PointPairList(x, y); LineItem item = new LineItem(scatterplot.Classes[i].Text, list, colors[i], SymbolType.Default); item.Line.IsVisible = LinesVisible; item.Symbol.Border.IsVisible = false; item.Symbol.Fill = new Fill(colors[i]); if (SymbolSize == 0) item.Symbol.IsVisible = false; else item.Symbol.Size = SymbolSize; classes.Add(item); } } zedGraphControl.AxisChange(); zedGraphControl.Invalidate(); if (!ScaleTight) zedGraphControl.ZoomPane(zedGraphControl.GraphPane, 1.1, PointF.Empty, false); else zedGraphControl.RestoreScale(zedGraphControl.GraphPane); } }
public void CreateComponentDistributionGraph(ZedGraphControl zgc) { ColorSequenceCollection sequence = new ColorSequenceCollection(); GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the GraphPane title myPane.Title.Text = "Component Proportion"; myPane.Title.FontSpec.Size = 24f; myPane.Title.FontSpec.Family = "Tahoma"; // Fill the pane background with a color gradient // myPane.Fill = new Fill(Color.White, Color.WhiteSmoke, 45.0f); // No fill for the chart background myPane.Chart.Fill.Type = FillType.None; myPane.Legend.IsVisible = false; // Add some pie slices for (int i = 0; i < pca.Components.Count; i++) { myPane.AddPieSlice(pca.Components[i].Proportion, sequence[i], 0.1, pca.Components[i].Index.ToString()); } myPane.XAxis.Scale.MinAuto = true; myPane.XAxis.Scale.MaxAuto = true; myPane.YAxis.Scale.MinAuto = true; myPane.YAxis.Scale.MaxAuto = true; myPane.XAxis.Scale.MagAuto = true; myPane.YAxis.Scale.MagAuto = true; // Calculate the Axis Scale Ranges zgc.AxisChange(); zgc.Invalidate(); }
private static DataSeriesBox show(String title, double[][] series, bool hold) { DataSeriesBox form = null; Thread formThread = null; AutoResetEvent stopWaitHandle = new AutoResetEvent(false); formThread = new Thread(() => { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Show control in a form form = new DataSeriesBox(); form.Text = title; form.formThread = formThread; var sequence = new ColorSequenceCollection(series.Length); for (int i = 0; i < series.Length; i++) { form.series.Add(new LineItem(i.ToString(), Matrix.Indices(0, series[i].Length).ToDouble(), series[i], sequence.GetColor(i), SymbolType.None)); } form.zedGraphControl.GraphPane.AxisChange(); stopWaitHandle.Set(); Application.Run(form); }); formThread.SetApartmentState(ApartmentState.STA); formThread.Start(); stopWaitHandle.WaitOne(); if (!hold) formThread.Join(); return form; }
private static WavechartBox show(String title, bool hold, params Tuple<Signal, int>[] series) { WavechartBox form = null; Thread formThread = null; AutoResetEvent stopWaitHandle = new AutoResetEvent(false); formThread = new Thread(() => { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Show control in a form form = new WavechartBox(); form.Text = title; form.formThread = formThread; if (!String.IsNullOrEmpty(title)) { form.zedGraphControl.GraphPane.Title.IsVisible = true; form.zedGraphControl.GraphPane.Title.Text = title; } var sequence = new ColorSequenceCollection(series.Length); for (int i = 0; i < series.Length; i++) { var signal = series[i].Item1; int channel = series[i].Item2; ComplexSignal complex = signal as ComplexSignal; if (complex != null && complex.Status != ComplexSignalStatus.Normal) { double[] spectrum = Accord.Audio.Tools .GetPowerSpectrum(complex.GetChannel(channel)); double[] frequencies = Accord.Audio.Tools.GetFrequencyVector(signal.Length, signal.SampleRate); form.series.Add(new LineItem(i.ToString(), frequencies, spectrum, sequence.GetColor(i), SymbolType.None)); form.zedGraphControl.GraphPane.XAxis.Title.Text = "Frequency"; form.zedGraphControl.GraphPane.YAxis.Title.Text = "Power"; } else { double[] values; if (signal.Channels == 1) { values = signal.ToDouble(); } else { ExtractChannel extract = new ExtractChannel(channel); values = extract.Apply(signal).ToDouble(); } form.series.Add(new LineItem(i.ToString(), Matrix.Indices(0, signal.Length).ToDouble(), values, sequence.GetColor(i), SymbolType.None)); form.zedGraphControl.GraphPane.XAxis.Title.Text = "Time"; form.zedGraphControl.GraphPane.YAxis.Title.Text = "Amplitude"; } } form.zedGraphControl.GraphPane.AxisChange(); stopWaitHandle.Set(); Application.Run(form); }); formThread.SetApartmentState(ApartmentState.STA); formThread.Start(); stopWaitHandle.WaitOne(); if (!hold) formThread.Join(); return form; }
/// <summary> /// Constructs a new instance of the ScatterplotView. /// </summary> /// public ComponentView() { InitializeComponent(); zedGraphControl.GraphPane.Title.Text = "Components"; zedGraphControl.GraphPane.Title.FontSpec.Size = 24f; zedGraphControl.GraphPane.Title.FontSpec.Family = "Tahoma"; zedGraphControl.GraphPane.XAxis.Title.Text = "Components"; zedGraphControl.GraphPane.YAxis.Title.Text = "Percentage"; zedGraphControl.BorderStyle = System.Windows.Forms.BorderStyle.None; zedGraphControl.GraphPane.Border.IsVisible = false; zedGraphControl.GraphPane.Border.Color = Color.White; zedGraphControl.GraphPane.Border.Width = 0; zedGraphControl.GraphPane.Fill = new Fill(Color.White); zedGraphControl.GraphPane.Chart.Fill = new Fill(Color.GhostWhite); zedGraphControl.GraphPane.Legend.IsVisible = false; zedGraphControl.GraphPane.Legend.Position = LegendPos.Right; zedGraphControl.GraphPane.Legend.IsShowLegendSymbols = false; zedGraphControl.GraphPane.XAxis.Scale.MinAuto = true; zedGraphControl.GraphPane.XAxis.Scale.MaxAuto = true; zedGraphControl.GraphPane.YAxis.Scale.MinAuto = true; zedGraphControl.GraphPane.YAxis.Scale.MaxAuto = true; zedGraphControl.GraphPane.XAxis.Scale.MagAuto = true; zedGraphControl.GraphPane.YAxis.Scale.MagAuto = true; zedGraphControl.GraphPane.Chart.Fill.Type = FillType.None; zedGraphControl.GraphPane.Legend.IsVisible = false; zedGraphControl.GraphPane.Title.FontSpec.Size = 24f; zedGraphControl.GraphPane.Title.FontSpec.Family = "Tahoma"; colors = new ColorSequenceCollection(); }
private void CreateBarGraph(double[] weights, string[] featureNames) { var zgc = graphSupportVectors; GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles myPane.Title.IsVisible = false; myPane.XAxis.Title.Text = "Weight importance"; myPane.YAxis.Title.Text = "Features"; var colors = new ColorSequenceCollection(); for (int i = 0; i < featureNames.Length; i++) myPane.AddBar(featureNames[i], new double[] { i }, new[] { weights[i] }, colors[i]); myPane.Fill = new Fill(Color.WhiteSmoke); zgc.AxisChange(); zgc.Invalidate(); }
private static DataSeriesBox show(String title, double[] x, double[][] series, bool time = false) { DataSeriesBox form = null; Thread formThread = null; if (title == null) title = "Time series"; x = (double[])x.Clone(); var idx = Matrix.Indices(0, x.Length); Array.Sort(x, idx); for (int i = 0; i < series.Length; i++) series[i] = series[i].Submatrix(idx); AutoResetEvent stopWaitHandle = new AutoResetEvent(false); formThread = new Thread(() => { Accord.Controls.Tools.ConfigureWindowsFormsApplication(); // Show control in a form form = new DataSeriesBox(); form.Text = title; form.formThread = formThread; var pane = form.zedGraphControl.GraphPane; if (time) { pane.XAxis.Type = AxisType.Date; pane.XAxis.Scale.MajorUnit = DateUnit.Hour; pane.XAxis.Scale.Format = "T"; } var sequence = new ColorSequenceCollection(series.Length); for (int i = 0; i < series.Length; i++) { if (x == null) x = Matrix.Indices(0, series[i].Length).ToDouble(); var lineItem = new LineItem(i.ToString(), x, series[i], sequence.GetColor(i), SymbolType.None); form.series.Add(lineItem); } pane.Title.Text = title; pane.AxisChange(); stopWaitHandle.Set(); Application.Run(form); }); formThread.SetApartmentState(ApartmentState.STA); formThread.Start(); stopWaitHandle.WaitOne(); return form; }
private static DataBarBox show(string title, string[] labels, double[][] series) { DataBarBox form = null; Thread formThread = null; if (title == null) title = "Bar chart"; double[] x = Matrix.Indices(0, labels.Length).ToDouble(); AutoResetEvent stopWaitHandle = new AutoResetEvent(false); formThread = new Thread(() => { Accord.Controls.Tools.ConfigureWindowsFormsApplication(); // Show control in a form form = new DataBarBox(); form.Text = title; form.formThread = formThread; var sequence = new ColorSequenceCollection(series.Length); for (int i = 0; i < series.Length; i++) { form.series.Add(new BarItem(i.ToString(), x, series[i], sequence.GetColor(i))); } form.zedGraphControl.GraphPane.Title.Text = title; form.zedGraphControl.GraphPane.XAxis.Type = AxisType.Text; form.zedGraphControl.GraphPane.XAxis.Scale.TextLabels = labels; form.zedGraphControl.GraphPane.XAxis.Scale.MajorStep = 1; form.zedGraphControl.GraphPane.AxisChange(); stopWaitHandle.Set(); Application.Run(form); }); formThread.SetApartmentState(ApartmentState.STA); formThread.Start(); stopWaitHandle.WaitOne(); return form; }
/// <summary> /// Forces a update of the scatter plot. /// </summary> /// public void UpdateGraph() { classes.Clear(); if (scatterplot.LabelAxis == null) { // Create space for unlabelled data PointPairList unlabelled = new PointPairList(scatterplot.XAxis, scatterplot.YAxis); LineItem item = new LineItem(String.Empty, unlabelled, Color.Black, SymbolType.Diamond); item.Line.IsVisible = false; item.Symbol.Border.IsVisible = false; item.Symbol.Fill = new Fill(Color.Black); classes.Add(item); } else { ColorSequenceCollection colors = new ColorSequenceCollection(scatterplot.Classes.Count); // Create a curve item for each of the labels for (int i = 0; i < scatterplot.Classes.Count; i++) { // retrieve the x,y pairs for the label double[] x = scatterplot.Classes[i].XAxis; double[] y = scatterplot.Classes[i].YAxis; PointPairList list = new PointPairList(x, y); LineItem item = new LineItem(String.Empty, list, colors[i], SymbolType.Diamond); item.Line.IsVisible = false; item.Symbol.Border.IsVisible = false; item.Symbol.Fill = new Fill(colors[i]); classes.Add(item); } zedGraphControl.AxisChange(); zedGraphControl.Invalidate(); } }
public void CreateScatterplot(ZedGraphControl zgc, double[,] graph) { GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); // Set the titles myPane.Title.IsVisible = false; myPane.XAxis.Title.Text = columnNames[0]; myPane.YAxis.Title.Text = columnNames[1]; // Classification problem var lists = new Dictionary<double, PointPairList>(); var unique = graph.GetColumn(2).Distinct(); foreach (var u in unique) lists[u] = new PointPairList(); for (int i = 0; i < graph.GetLength(0); i++) lists[graph[i, 2]].Add(graph[i, 0], graph[i, 1]); var seq = new ColorSequenceCollection(); // Add the curve for (int i = 0; i < unique.Length; i++) { var color = seq.GetColor(i); LineItem myCurve = myPane.AddCurve("G" + i, lists[unique[i]], color, SymbolType.Diamond); myCurve.Line.IsVisible = false; myCurve.Symbol.Border.IsVisible = false; myCurve.Symbol.Fill = new Fill(color); } // Fill the background of the chart rect and pane //myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); //myPane.Fill = new Fill(Color.White, Color.SlateGray, 45.0f); myPane.Fill = new Fill(Color.WhiteSmoke); zgc.AxisChange(); zgc.Invalidate(); }