better LineModel estimation #2427

Borda opened this Issue Jan 3, 2017 · 0 comments


None yet

2 participants

Borda commented Jan 3, 2017 edited


I had a look at the line model estimation an the representation by angle and shift does not look so good for me, I would rather use common Least Square Minimization.

Way to reproduce

[If reporting a bug, please include the following important information:]

  • Code example
import numpy as np
import matplotlib.pylab as plt
from skimage.measure import LineModel

x = np.linspace(1, 2, 100)
y = 1.5 * x + 0.5
plt.plot(x, y, 'g', label='true')

y += (np.random.rand(len(y)) - 0.5) * 1.5
plt.plot(x, y, 'bx', label='noise')

lm = LineModel()
lm.estimate(np.array([x, y]).T)
y2 = lm.predict_y(x)
plt.plot(x, y2, 'r', label='LineModel')

x_space = np.array([x, np.ones(x.shape)]).T
# X = A\B is the solution to the equation AX = B computed
# by Gaussian elimination: inv(A) * B
est = np.linalg.pinv(x_space).dot(y)
y3 = est[0] * x + est[1]
plt.plot(x, y3, 'm', label='LeastSqaure')

  • Relevant images figure_1
@sciunto sciunto added the enhancement label Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment