Assignment: Line Fitting and RANSAC Algorithm, Assignments of Computer Science

An assignment for students, consisting of both standard and advanced parts. The standard part includes programming exercises on ransac algorithm and line distance calculation. The advanced part involves implementing em algorithm for line fitting and estimating the number of lines that can be successfully separated using ransansac. Students are required to write functions, test their code, and submit their results.

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-ver-1
koofers-user-ver-1 🇺🇸

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Problem Set 3 CMSC 426
Due: Thursday, April 3
Overview:
This problem set will work a little different. There will be a standard part,
and an advanced part. Students may choose to do either part. Alternately, they may
choose to complete the standard par
t, and hand in any portions of the advanced part for
extra credit. Not that the standard part totals 100 points, while the advanced part totals
120. A student may receive no more than 140 points total. Grad students may feel that
they should focus on th
e advanced part.
Remember, everything you do should be turned in as a hardcopy. All code should be
emailed to the TA. Write the date that you hand in assignments on the hardcopy,
especially if you hand them in late. If you leave an assignment under my
door on in my
mailbox, always include the date.
Standard Assignment
1)
Programming RANSAC. 70 points total.
a.
Write a function of the form: [a, b, c] = gen_line(pt1, pt2). This function
should take two points as input, and return the parameters of a line t
hat fit
these points. The line should be ax + by + c = 0, where sqrt(a*a + b*b) =
1. Test this function using the pairs of points: i) (1,1) (2,1) ii) (1,1)
(1,2); iii) (1,1) (3,2). Turn in your code, and show calls to the routine and
responses for these inputs.
5 points
b.
Write a function of the form: d = line_dist(L, p). L represents a line
(perhaps as a vector of [a,b,c]). p represents a point. d is the distance
from the point to the line. Test your code with i) The line formed by the
points:
(0,1) (2,1) and the point (5,2). ii) The line formed by the points
(1,1) and (3,2) and the point (7,4). Turn in your code and show calls to the
routine and responses for these inputs.
5 points
c.
Compute the correct answers to the problems in (b) by hand.
Show your
work and the results.
5 points
d.
Write a function of the form: k = num_samples(n, m, p). If there are n
points in an image, and m of them come from a single line, then if we
randomly sample k pairs of points we should have a probability greater
t
han p of picking a pair of points that come from the line. k should be the
smallest integer for which this is true. Test this with n = 20, m = 8, p = .9.
Turn in your code, and show calls to the routine and responses for these
inputs.
10 points
e.
Write a
function of the form: pts_cor = verify(p1, p2, pts, eps). p1 and p2
are points that will be used to form a line. pts is a list of different pts.
pts_cor should contain a list of all points in pts whose distance to the line
formed by p1 and p2 is less t
han eps. Test this routine with p1 = (1,1), p2
= (2,2), pts = [(3,4), (5,7), (3,8)], eps = 2. Turn in your code, and show
calls to the routine and responses for these inputs.
10 points
pf3
pf4
pf5

Partial preview of the text

Download Assignment: Line Fitting and RANSAC Algorithm and more Assignments Computer Science in PDF only on Docsity!

Problem Set 3 CMSC 426

Due: Thursday, April 3

Overview: This problem set will work a little different. There will be a standard part, and an advanced part. Students may choose to do either part. Alternately, they may choose to complete the standard part, and hand in any portions of the advanced part for extra credit. Not that the standard part totals 100 points, while the advanced part totals

  1. A student may receive no more than 140 points total. Grad students may feel that they should focus on the advanced part.

Remember, everything you do should be turned in as a hardcopy. All code should be emailed to the TA. Write the date that you hand in assignments on the hardcopy, especially if you hand them in late. If you leave an assignment under my door on in my mailbox, always include the date.

Standard Assignment

  1. Programming RANSAC. 70 points total. a. Write a function of the form: [a, b, c] = gen_line(pt1, pt2). This function should take two points as input, and return the parameters of a line that fit these points. The line should be ax + by + c = 0, where sqrt(aa + bb) =
  1. Test this function using the pairs of points: i) (1,1) (2,1) ii) (1,1) (1,2); iii) (1,1) (3,2). Turn in your code, and show calls to the routine and responses for these inputs. 5 points b. Write a function of the form: d = line_dist(L, p). L represents a line (perhaps as a vector of [a,b,c]). p represents a point. d is the distance from the point to the line. Test your code with i) The line formed by the points: (0,1) (2,1) and the point (5,2). ii) The line formed by the points (1,1) and (3,2) and the point (7,4). Turn in your code and show calls to the routine and responses for these inputs. 5 points c. Compute the correct answers to the problems in (b) by hand. Show your work and the results. 5 points d. Write a function of the form: k = num_samples(n, m, p). If there are n points in an image, and m of them come from a single line, then if we randomly sample k pairs of points we should have a probability greater than p of picking a pair of points that come from the line. k should be the smallest integer for which this is true. Test this with n = 20, m = 8, p = .9. Turn in your code, and show calls to the routine and responses for these inputs. 10 points e. Write a function of the form: pts_cor = verify(p1, p2, pts, eps). p1 and p are points that will be used to form a line. pts is a list of different pts. pts_cor should contain a list of all points in pts whose distance to the line formed by p1 and p2 is less than eps. Test this routine with p1 = (1,1), p = (2,2), pts = [(3,4), (5,7), (3,8)], eps = 2. Turn in your code, and show calls to the routine and responses for these inputs. 10 points

f. Write a function to generate test data, of the form: pts = test(n). This should generate points in the square [0,50], [0, 50]. The first 8 points should come from the horizontal line y = 25, with unit variance Gaussian noise added to them (use randn). n noise points should come from a uniform random distribution across the whole image (use the function rand). Test this by running it with n = 30 and plotting the results. Plot points from the line in one color, and noise points in a different color. Turn in the plot and code. 10 points. g. Write the function [L, pts, c] = ransac(n). Generate n + 8 points using test, from 1f. Sample enough random pairs of points so there is probability greater than .95 that two will come from the line, using num_samples from 1d. For each pair of points, use verify from 1e) to find all points that are near the line, using eps = 2. Select the line that is close to the largest number of points. Return this line (L), the list of points (pts), and the number of these that actually came from the line (c, ie, the number that were among the first 8 returned by test). Run your code for n = [0, 10, 20, 50, 100, 200]. Plot c versus n for these results. Turn in your code and the plot. 25 points.

  1. Pencil and Paper Exercises for EM 15 points total a) Consider two Gaussian distributions with means of 80 and 160, and standard deviations of 40 for each. Compute the weights that the Expectation Step of EM will compute for data with the values: 80, 90, 100, 110. 5 points

b) Consider points at 80 90 100 110 120 130 140 with weights of: 0.78 0.61 0.40 0.21 0.10 0.04 0. (these are w1, the weights relative to the first distribution. w2 = 1-w1). Compute the new weighted means of the two Gaussian distributions. (Part of Maximization step). 5 points.

c) Compute the weighted standard deviation of the Gaussian distributions, assuming they have the same standard deviation. 5 points.

Hints on 2. If unsure about these steps, consult the Matlab code from the lecture, or a standard text on probability, such as the one by Drake, or the Yair Weiss handout.

  1. Pencil and Paper Exercises for Hough Transform 15 points Recall (Forsyth and Ponce p. 330) that we can write the equation for a line as: xcos(θ) + ysin(θ) + r = 0 with r >= 0, 0<= θ < 2π. Draw a 10 x 10 grid, which divides θ into 10 equally spaced ranges, and divides r into equally spaced ranges from 0 to 10. That is, the square in the lower left of your grid represents θ between 0 and (2 π /10), and r between 0 and 1.

a) We use p1 and p2 to hypothesize a line (which is identical to L in this case, since p1 and p2 are noise-free). Find the expected number of points in p3 … pk that will lie within 2 of L. 5 points b) Consider the incorrect, vertical line V at x = 25. Suppose there are n noise points drawn from a uniform distribution in the image. Compute the probability distribution on the number of points that will lie within 2 of V. Hint: it may become useful to approximate this distribution with a Gaussian. 10 points c) Compute the probability that the number of incorrect noise points that lie within 2 of V will be greater than the expected number of correct points from p1 … pk that lie within 2 of L. The answer will be a function of k and n. 5 points d) Now, put all this together to estimate the probability that RANSAC will produce the right answer. Suppose that there are k points from a line, and n noise points from a uniform distribution. For k = 10, and n = 10, 30, 50 compute the number of random pairs of points we must sample to ensure at least a 95% probability that one pair comes from the line. Use the simplified assumptions of (a) to estimate the expected number of points that will be matched to that line. Then, simplify by assuming that all incorrect lines match noise points with the distribution you computed in (c). What is the probability that one of the incorrect lines will match more points than the expected number of points that the correct line will match? 25 points.

  1. Optional Challenge problem. Note, I think this problem is pretty hard. I’m not sure I see how to solve it. Feel free to try to solve a simpler problem of your choosing for partial credit. 20 points.

Consider three collinear points, p1 = (0,0), p2=(10,0), p3=(20,0). Suppose each point is perturbed by independent, identically distributed 2D Gaussian noise with sigma 1. Call the noise vectors n1, n2, n3, so that the perturbed points are: q1 = p1+n1; q2 = p2+n2; q3 = p3+n3. Let L be the line passing through q1 and q2. Let d be the distance from L to q3. Compute the probability distribution of d.

This document was created with Win2PDF available at http://www.daneprairie.com. The unregistered version of Win2PDF is for evaluation or non-commercial use only.