Presentation is loading. Please wait.

Presentation is loading. Please wait.

02 – Object Modeling Overview Point Selection Bounding Box Line Equation Least Square Line Equation Conclusions.

Similar presentations


Presentation on theme: "02 – Object Modeling Overview Point Selection Bounding Box Line Equation Least Square Line Equation Conclusions."— Presentation transcript:

1 02 – Object Modeling Overview Point Selection Bounding Box Line Equation Least Square Line Equation Conclusions

2 Overview Assume that we have an image of a table How can we create a mathematical model this geometric object?

3 Overview One option is to calculate the the 2D line equations for the visible edges

4 Overview Assume that we have calculated the (x,y) coordinates of the table top edge pixels XY 1215 1317 1519 1619...

5 Point Selection How can we decide which points belong together on the same line? Trial and error point selection algorithm: –Take any two points at random (x 1,y 1 ), (x 2,y 2 ) –Calculate line equation Ax+By+C=0 where A=(y 1 -y 2 ), B=(x 2 -x 1 ), C=x 1 (y 2 -y 1 )+y 1 (x 1 -x 2 ) –Find all points (x i,y i ) that are close enough to the line by checking if Ax i +By i +C < threshold –Remove these points from the list and repeat until there are no points left to consider

6 Point Selection Select two points and calculate line equation Ax+By+C=0

7 Point Selection Set of points that are close to the first line equation

8 Point Selection Select two more points and calculate second line equation

9 Point Selection Set of points that are close to the second line equation

10 Point Selection Not all line equations will correspond to table top edges We must ignore these line equations and select two new points

11 Bounding Box Line Equation How can calculate the line equation for the set of points on one line? Simple bounding box based algorithm: –Examine the set of points and calculate the min_x, min_y, max_x, and max_y values –If (max_x-min_x) > (max_y-min_y) then calculate the line equation using min_x and max_x points –Otherwise calculate the line equation using the min_y and max_y points –This is robust for horizontal and vertical lines

12 Bounding Box Line Equation Calculate bounding box by finding min and max (x,y) values

13 Bounding Box Line Equation Define line equation using points with min_x and max_x

14 Bounding Box Line Equation void bounding_box_line(float x[], float y[], int count, float &A, float &B) { // Calculate min and max (x,y) values int min_x = 0, max_x = 0, min_y = 0, max_y = 0; for (int i=1; i<count; i++) { if (x[min_x] > x[i]) min_x = i; if (x[max_x] < x[i]) max_x = i; if (y[min_y] > y[i]) min_y = i; if (y[max_y] < y[i]) max_y = i; }

15 Bounding Box Line Equation // Calculate line equation float size_x = x[max_x] - x[min_x]; float size_y = y[max_y] - y[min_y]; if ((size_x > size_y) && (x[max_x] != x[min_x])) { B = (y[max_x] - y[min_x]) / (x[max_x] - x[min_x]); A = y[min_x] - B * x[min_x]; } else if (x[max_y] != x[min_y]) { B = (y[max_y] - y[min_y]) / (x[max_y] - x[min_y]); A = y[min_y] - B * x[min_y]; } }

16 Least Square Line Equation The goal of least square line fitting is to obtain a line equation that minimizes the square of the distances between the line and the points

17 Least Square Line Equation To simplify the analysis, we minimize the vertical offsets rather than the perpendicular offsets between the line and points

18 Least Square Line Equation The first step is to quantify vertical offsets using a basic line equation formula

19 Least Square Line Equation Then we take the partial derivatives with respect to the line parameters (a,b)

20 Least Square Line Equation Using S in place of summation, we can write the two equations in matrix form as follows

21 Least Square Line Equation To solve we calculate the 2x2 matrix inverse

22 Least Square Line Equation Multiplying we get expressions for (a,b)

23 Least Square Line Equation void least_square_line(float x[], float y[], int count, float &A, float&B) { // Calculate sums of (x,y) values float Sx = 0, Sy = 0, Sxx = 0, Sxy = 0; for (int i=0; i<count; i++) { Sx += x[i]; Sy += y[i]; Sxx += x[i] * x[i]; Sxy += x[i] * y[i]; }

24 Least Square Line Equation // Calculate line equation float denominator = count * Sxx - Sx * Sx; if (denominator != 0) { A = (Sxx * Sy - Sx * Sxy) / denominator; B = (-Sx * Sy + count * Sxy) / denominator; }

25 Least Square Line Equation For more information on least squares fitting see the Wolfram wiki page below: http://mathworld.wolfram.com/LeastSquaresFitting.h tml

26 Conclusions There are many other ways to detect edges in images and calculate line equations –Laplacian zero crossings –Canny edges –Hough transforms We will study these computer vision algorithms in more detail later in the class


Download ppt "02 – Object Modeling Overview Point Selection Bounding Box Line Equation Least Square Line Equation Conclusions."

Similar presentations


Ads by Google