# better LineModel estimation #2427

Open
opened this Issue Jan 3, 2017 · 0 comments

None yet

### 2 participants

Contributor
commented Jan 3, 2017 edited

## Description

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')

plt.legend(loc=0)
plt.show()
``````
• Relevant images
added the enhancement label Jan 4, 2017
referenced this issue Jan 7, 2017
Open