'**SUMMARY**
Fit edge in a binary/gray image using an initial guess and the least squares method.
The functions returns a single line
**PARAMETERS**
* *guess* - A tuples of the form ((x0,y0),(x1,y1)) which is an approximate guess
* *window* - A window around the guess to search.
* *threshold* - the threshold above which we count a pixel as a line
* *measurements* -the number of line projections to use for fitting the line
TODO: Constrict a line to black to white or white to black
Right vs. Left orientation.
**RETURNS**
A a line object
**EXAMPLE**'

def fitEdge(self, guess, window=10, threshold=128, measurements=5, darktolight=True, lighttodark=True, departurethreshold=1):

    searchLines = FeatureSet()
    fitPoints = FeatureSet()
    x1 = guess[0][0]
    x2 = guess[1][0]
    y1 = guess[0][1]
    y2 = guess[1][1]
    dx = (float((x2 - x1)) / (measurements - 1))
    dy = (float((y2 - y1)) / (measurements - 1))
    s = np.zeros((measurements, 2))
    lpstartx = np.zeros(measurements)
    lpstarty = np.zeros(measurements)
    lpendx = np.zeros(measurements)
    lpendy = np.zeros(measurements)
    linefitpts = np.zeros((measurements, 2))
    if (x1 == x2):
        m = 0
        mo = 0
        b = x1
        for i in xrange(0, measurements):
            s[i][0] = x1
            s[i][1] = (y1 + (i * dy))
            lpstartx[i] = (s[i][0] + window)
            lpstarty[i] = s[i][1]
            lpendx[i] = (s[i][0] - window)
            lpendy[i] = s[i][1]
            Cur_line = Line(self, ((lpstartx[i], lpstarty[i]), (lpendx[i], lpendy[i])))
            ((lpstartx[i], lpstarty[i]), (lpendx[i], lpendy[i])) = Cur_line.cropToImageEdges().end_points
            searchLines.append(Cur_line)
            tmp = self.getThresholdCrossing((int(lpstartx[i]), int(lpstarty[i])), (int(lpendx[i]), int(lpendy[i])), threshold=threshold, lighttodark=lighttodark, darktolight=darktolight, departurethreshold=departurethreshold)
            fitPoints.append(Circle(self, tmp[0], tmp[1], 3))
            linefitpts[i] = tmp
    else:
        m = (float((y2 - y1)) / (x2 - x1))
        b = (y1 - (m * x1))
        mo = ((-1) / m)
        for i in xrange(0, measurements):
            s[i][0] = (x1 + (i * dx))
            s[i][1] = (y1 + (i * dy))
            fx = ((math.sqrt(math.pow(window, 2)) / (1 + mo)) / 2)
            fy = (fx * mo)
            lpstartx[i] = (s[i][0] + fx)
            lpstarty[i] = (s[i][1] + fy)
            lpendx[i] = (s[i][0] - fx)
            lpendy[i] = (s[i][1] - fy)
            Cur_line = Line(self, ((lpstartx[i], lpstarty[i]), (lpendx[i], lpendy[i])))
            ((lpstartx[i], lpstarty[i]), (lpendx[i], lpendy[i])) = Cur_line.cropToImageEdges().end_points
            searchLines.append(Cur_line)
            tmp = self.getThresholdCrossing((int(lpstartx[i]), int(lpstarty[i])), (int(lpendx[i]), int(lpendy[i])), threshold=threshold, lighttodark=lighttodark, darktolight=darktolight, departurethreshold=departurethreshold)
            fitPoints.append((tmp[0], tmp[1]))
            linefitpts[i] = tmp
    badpts = []
    for j in range(len(linefitpts)):
        if ((linefitpts[(j, 0)] == (-1)) or (linefitpts[(j, 1)] == (-1))):
            badpts.append(j)
    for pt in badpts:
        linefitpts = np.delete(linefitpts, pt, axis=0)
    x = linefitpts[:, 0]
    y = linefitpts[:, 1]
    ymin = np.min(y)
    ymax = np.max(y)
    xmax = np.max(x)
    xmin = np.min(x)
    if ((xmax - xmin) > (ymax - ymin)):
        A = np.vstack([x, np.ones(len(x))]).T
        (m, c) = nla.lstsq(A, y)[0]
        y0 = int(((m * xmin) + c))
        y1 = int(((m * xmax) + c))
        finalLine = Line(self, ((xmin, y0), (xmax, y1)))
    else:
        A = np.vstack([y, np.ones(len(y))]).T
        (m, c) = nla.lstsq(A, x)[0]
        x0 = int(((ymin * m) + c))
        x1 = int(((ymax * m) + c))
        finalLine = Line(self, ((x0, ymin), (x1, ymax)))
    return (finalLine, searchLines, fitPoints)
