skimage2.measure.LineModelND#
- class skimage2.measure.LineModelND(origin, direction)[source]#
Bases:
_BaseModelTotal least squares estimator for N-dimensional lines.
In contrast to ordinary least squares line estimation, this estimator minimizes the orthogonal distances of points to the estimated line.
Lines are defined by a point (origin) and a unit vector (direction) according to the following vector equation:
X = origin + lambda * direction
- Parameters:
- originarray-like, shape (N,)
Coordinates of line origin in N dimensions.
- directionarray-like, shape (N,)
Vector giving line direction.
- Raises:
- ValueError
If length of
originanddirectiondiffer.
Examples
>>> x = np.linspace(1, 2, 25) >>> y = 1.5 * x + 3 >>> lm = LineModelND.from_estimate(np.stack([x, y], axis=-1)) >>> lm.origin array([1.5 , 5.25]) >>> lm.direction array([0.5547 , 0.83205]) >>> res = lm.residuals(np.stack([x, y], axis=-1)) >>> np.abs(np.round(res, 9)) array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) >>> np.round(lm.predict_y(x[:5]), 3) array([4.5 , 4.562, 4.625, 4.688, 4.75 ]) >>> np.round(lm.predict_x(y[:5]), 3) array([1. , 1.042, 1.083, 1.125, 1.167])
- estimate(data)[source]#
Estimate line model from data.
Deprecated since version 0.26:
estimateis deprecated since version 0.26 and will be removed in version 2.2. Please useLineModelND.from_estimateclass constructor instead.This minimizes the sum of shortest (orthogonal) distances from the given data points to the estimated line.
- Parameters:
- data(N, dim) array
N points in a space of dimensionality
dim >= 2.
- Returns:
- successbool
True, if model estimation succeeds.
- classmethod from_estimate(data)[source]#
Estimate line model from data.
This minimizes the sum of shortest (orthogonal) distances from the given data points to the estimated line.
- Parameters:
- data(N, dim) array
N points in a space of dimensionality dim >= 2.
- Returns:
- modelSelf or
FailedEstimation An instance of the line model if the estimation succeeded. Otherwise, we return a special
FailedEstimationobject to signal a failed estimation. Testing the truth value of the failed estimation object will returnFalse. E.g.model = LineModelND.from_estimate(...) if not model: raise RuntimeError(f"Failed estimation: {model}")
- modelSelf or
- property params#
Return model attributes as
origin, directiontuple.
- predict(x, axis=0, params=<DEPRECATED>)[source]#
Predict intersection of line model with orthogonal hyperplane.
- Parameters:
- xndarray of shape (n, 1)
Coordinates along an axis.
- axisint
Axis orthogonal to the hyperplane intersecting the line.
- Returns:
- datandarray of shape (n, m)
Predicted coordinates.
- Other Parameters:
- params
DEPRECATED, optional Optional custom parameter set in the form (
origin,direction).Deprecated since version 0.26.
- params
- Raises:
- ValueError
If the line is parallel to the given axis.
- predict_x(y, params=<DEPRECATED>)[source]#
Predict x-coordinates for 2D lines using the estimated model.
Alias for:
predict(y, axis=1)[:, 0]
- Parameters:
- yarray
y-coordinates.
- Returns:
- xarray
Predicted x-coordinates.
- Other Parameters:
- params
DEPRECATED, optional Optional custom parameter set in the form (
origin,direction).Deprecated since version 0.26.
- params
- predict_y(x, params=<DEPRECATED>)[source]#
Predict y-coordinates for 2D lines using the estimated model.
Alias for:
predict(x, axis=0)[:, 1]
- Parameters:
- xarray
x-coordinates.
- Returns:
- yarray
Predicted y-coordinates.
- Other Parameters:
- params
DEPRECATED, optional Optional custom parameter set in the form (
origin,direction).Deprecated since version 0.26.
- params
- residuals(data, params=<DEPRECATED>)[source]#
Determine residuals of data to model.
For each point, the shortest (orthogonal) distance to the line is returned. It is obtained by projecting the data onto the line.
- Parameters:
- data(N, dim) array
N points in a space of dimension dim.
- Returns:
- residuals(N,) array
Residual for each data point.
- Other Parameters:
- params
DEPRECATED, optional Optional custom parameter set in the form (
origin,direction).Deprecated since version 0.26.
- params