private void ellipseDetectionToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // load image imMat = FxMatrixF.Load(ofd.FileName); ieEllipseImage = new ImageElement(imMat, new ColorMap(ColorMapDefaults.Jet)); ieEllipseImage.lockMoving = true; canvas_ellipse.AddElement(ieEllipseImage); // add plot element gpeEllipseImage = new GeometryPlotElement(); canvas_ellipse.AddElement(gpeEllipseImage); var contours = new FxContour(imMat<0.2f); WriteLine("Num Contours : " + contours.NumChains); int i = 0; float pe_pos_y = ieEllipseImage._Position.y; foreach (var cont in contours.ChainList) { // draw the rectanges in main image FxVector2f start = cont.RectStart ; FxVector2f end = start + cont.RectSize; FxMaths.Geometry.Rectangle r = new FxMaths.Geometry.Rectangle(start, end); gpeEllipseImage.AddGeometry(r, false); // draw the centroids FxVector2f cen = cont.GetCentroid(); var l = new FxMaths.Geometry.Line(cen - new FxVector2f(0, 2), cen + new FxVector2f(0, 2)); l.LineWidth = 0.5f; gpeEllipseImage.AddGeometry(l, false); l = new FxMaths.Geometry.Line(cen - new FxVector2f(2, 0), cen + new FxVector2f(2, 0)); l.LineWidth = 0.5f; gpeEllipseImage.AddGeometry(l, false); // add the numbering of the contours var t = new TextElement(i.ToString()); t._Position = cen; t.FontColor = SharpDX.Color.Green; t._TextFormat.fontSize = 16.0f; canvas_ellipse.AddElement(t); // show the chain vector in plot { FxVectorF vec_i = new FxVectorF(cont.Count); FxVectorF vec_r = new FxVectorF(cont.Count); vec_i[0] = cont[0].i; vec_r[0] = cont[0].r; for (int j = 1; j < cont.Count; j++) { vec_i[j] = vec_i[j - 1] + cont[j].i; vec_r[j] = vec_r[j - 1] + cont[j].r; } // show the plot of this vector var pe = new PloterElement(vec_i, PlotType.Lines, System.Drawing.Color.Blue); pe._Position.x = ieEllipseImage._Position.x + ieEllipseImage.Size.x; pe._Position.y = pe_pos_y; pe.AddPlot(vec_r, PlotType.Lines, System.Drawing.Color.Red); pe.CenterYOrigin(); pe.FitPlots(); canvas_ellipse.AddElement(pe); // update the y of pe for the next one pe_pos_y += pe.Size.y; // debug the ellipse for (int j = 0; j < cont.Count; j++) { imMat[(int)(vec_r[j] + cont.StartPoint.x), (int)(vec_i[j] + cont.StartPoint.y)] = 0.8f/contours.NumChains + 0.1f; } ieEllipseImage.UpdateInternalImage(imMat, new ColorMap(ColorMapDefaults.Jet)); } i++; } canvas_ellipse.ReDraw(); } }