private void updateButton_Click(object sender, EventArgs e) { logic.SunoLogic suno = new logic.SunoLogic(); if (image_path.Text.Equals("")) { return; } Bitmap tempImage = (Bitmap)Bitmap.FromFile(image_path.Text); TrajectorySet ts = suno.CalculateTrajectorySet(tempImage, Double.Parse(Hough_relativeIntensityTextBox.Text), Int32.Parse(Susan_differenceTresholdTextBox.Text), Int32.Parse(Susan_geometricalTresholdTextBox.Text), Int32.Parse(Suno_lineScanThresholdTextBox.Text), Int32.Parse(Suno_lineScanRadialTextBox.Text), Int32.Parse(Suno_radialThresholdTextbox.Text), geometricalCheckBox.Checked); tempImage = suno.renderSunoPreview(ts, Int32.Parse(cornerRadiusTextbox.Text), Int32.Parse(lineWidthTextbox.Text), renderSusanCornerCheckbox.Checked, renderHoughLinesCheckbox.Checked, renderBlackPointsCheckbox.Checked, renderTrajectoryPointsCheckbox.Checked); previewPictureBox.Image = tempImage; //populate stats blackSegmentsLabel.Text = "" + ts.black_segments.Count; elaborationTimeLabel.Text = "" + ((ts.elaboration_end_time.Ticks - ts.elaboration_start_time.Ticks) / 10000000) + " s"; trajectoryPointsLabel.Text = "" + ts.trajectory_points.Count; }
public TrajectorySet CalculateDiscontinuityPoints(TrajectorySet ts, int lineScanThreshold, int lineScanRadius, int radialThreshold, Boolean geometrical) { //foreach hough line foreach (HoughLine line in ts.lines) { int r = line.Radius; double t = line.Theta; // check if line is in lower part of the image if (r < 0) { t += 180; r = -r; } // convert degrees to radians t = (t / 180) * Math.PI; // get image centers (all coordinate are measured relative // to center) int w2 = ts.image.Width / 2; int h2 = ts.image.Height / 2; double x0 = 0, x1 = 0, y0 = 0, y1 = 0; if (line.Theta != 0) { // none vertical line x0 = -w2; // most left point x1 = w2; // most right point // calculate corresponding y values y0 = (-Math.Cos(t) * x0 + r) / Math.Sin(t); y1 = (-Math.Cos(t) * x1 + r) / Math.Sin(t); } else { // vertical line x0 = line.Radius; x1 = line.Radius; y0 = h2; y1 = -h2; } int X0, Y0, X1, Y1; X0 = (int)x0 + w2; Y0 = h2 - (int)y0; X1 = (int)x1 + w2; Y1 = h2 - (int)y1; PlotFunction plot = AddPlotPoint; Line((int)X0, (int)Y0, (int)X1, (int)Y1, plot); double R = -((double)Y1 - (double)Y0) / ((double)X1 - (double)X0); ts.bresenhamsLines.Add(current_line_points); List <System.Drawing.Point> black_points = new List <System.Drawing.Point>(); int end_segments = 10; Boolean start_segment = false; BlackSegment current_segment = new BlackSegment(); int segment_tollerance = 10; foreach (System.Drawing.Point current in current_line_points) { //get pixel neighbours average colour double average; if (geometrical) { average = GetNeightbourAveragePixelColor(ts.elaborated_image, current, lineScanRadius); } else { average = GetNeightbourAveragePixelColor(ts.elaborated_image, current, lineScanRadius, R); } if (average > lineScanThreshold) { if (!start_segment) { current_segment.start = current; start_segment = true; } black_points.Add(current); } else { if (start_segment) { segment_tollerance--; if (segment_tollerance <= 0) { current_segment.end = current; start_segment = false; ts.black_segments.Add(current_segment); current_segment = new BlackSegment(); segment_tollerance = 10; } } } } current_line_points = new List <System.Drawing.Point>(); ts.black_points = new List <System.Drawing.Point>(black_points); //foreach segment check the size and get the central pixel foreach (BlackSegment current in ts.black_segments) { if (geometrical) { /* Algoritmo basato su punto medio dei segmenti * restituisce alcuni falsi positivi a causa dell'imprecisione introdotta dal calcolo della media dei punti * inoltre non restituisce i punti esatti intermedi della discontinuità.*/ int len = SunoLogic.distanceBetween2Points(current.start, current.end); int mid_len = len / 2; Boolean start = false; foreach (System.Drawing.Point current_point in ts.black_points) { if (current_point.X == current.start.X && current_point.Y == current.start.Y) { start = true; } if (start) { mid_len--; if (mid_len <= 0) { ts.trajectory_points.Add(current_point); start = false; break; } } } } else { List <System.Drawing.Point> start_neightbour = new List <System.Drawing.Point>(); List <System.Drawing.Point> end_neightbour = new List <System.Drawing.Point>(); foreach (IntPoint current_corner in ts.corners) { System.Drawing.Point current_corner_point = new System.Drawing.Point(current_corner.X, current_corner.Y); //check start points int distance_from_start = SunoLogic.distanceBetween2Points(current_corner_point, current.start); if (distance_from_start - radialThreshold <= 0) { start_neightbour.Add(current_corner_point); } int distance_from_end = SunoLogic.distanceBetween2Points(current_corner_point, current.end); if (distance_from_end - radialThreshold <= 0) { end_neightbour.Add(current_corner_point); } } int ts_x = 0, ts_y = 0, te_x = 0, te_y = 0; int count = 0; foreach (System.Drawing.Point current_pount in start_neightbour) { //media tra le coordinate X dello start //media tra le coordinate Y dello start ts_x += current_pount.X; ts_y += current_pount.Y; count++; } if (count == 0) { ts_x = current.start.X; ts_y = current.start.Y; } else { ts_x /= count; ts_y /= count; } count = 0; foreach (System.Drawing.Point current_pount in end_neightbour) { //media tra le coordinate X dell'end //media tra le coordinate Y dell'end te_x += current_pount.X; te_y += current_pount.Y; count++; } if (count == 0) { te_x = current.end.X; te_y = current.end.Y; } else { te_x /= count; te_y /= count; } //calculate segment lenght System.Drawing.Point mid = SunoLogic.midPoint(new System.Drawing.Point(ts_x, ts_y), new System.Drawing.Point(te_x, te_y)); //add point ts.trajectory_points.Add(mid); } } } return(ts); }