Bases: skimage.measure.fit.BaseModel
Total least squares estimator for 2D circles.
The functional model of the circle is:
r**2 = (x - xc)**2 + (y - yc)**2
This estimator minimizes the squared distances from all points to the circle:
min{ sum((r - sqrt((x_i - xc)**2 + (y_i - yc)**2))**2) }
The _params attribute contains the parameters in the following order:
xc, yc, r
A minimum number of 3 points is required to solve for the parameters.
Estimate circle model from data using total least squares.
| Parameters : | data : (N, 2) array
|
|---|
Predict x- and y-coordinates using the estimated model.
| Parameters : | t : array
params : (3, ) array, optional
|
|---|---|
| Returns : | xy : (..., 2) array
|
Determine residuals of data to model.
For each point the shortest distance to the circle is returned.
| Parameters : | data : (N, 2) array
|
|---|---|
| Returns : | residuals : (N, ) array
|
Bases: skimage.measure.fit.BaseModel
Total least squares estimator for 2D ellipses.
The functional model of the ellipse is:
xt = xc + a*cos(theta)*cos(t) - b*sin(theta)*sin(t)
yt = yc + a*sin(theta)*cos(t) + b*cos(theta)*sin(t)
d = sqrt((x - xt)**2 + (y - yt)**2)
where (xt, yt) is the closest point on the ellipse to (x, y). Thus d is the shortest distance from the point to the ellipse.
This estimator minimizes the squared distances from all points to the ellipse:
min{ sum(d_i**2) } = min{ sum((x_i - xt)**2 + (y_i - yt)**2) }
Thus you have 2 * N equations (x_i, y_i) for N + 5 unknowns (t_i, xc, yc, a, b, theta), which gives you an effective redundancy of N - 5.
The _params attribute contains the parameters in the following order:
xc, yc, a, b, theta
A minimum number of 5 points is required to solve for the parameters.
Estimate circle model from data using total least squares.
| Parameters : | data : (N, 2) array
|
|---|
Predict x- and y-coordinates using the estimated model.
| Parameters : | t : array
params : (5, ) array, optional
|
|---|---|
| Returns : | xy : (..., 2) array
|
Determine residuals of data to model.
For each point the shortest distance to the ellipse is returned.
| Parameters : | data : (N, 2) array
|
|---|---|
| Returns : | residuals : (N, ) array
|
Bases: skimage.measure.fit.BaseModel
Total least squares estimator for 2D lines.
Lines are parameterized using polar coordinates as functional model:
dist = x * cos(theta) + y * sin(theta)
This parameterization is able to model vertical lines in contrast to the standard line model y = a*x + b.
This estimator minimizes the squared distances from all points to the line:
min{ sum((dist - x_i * cos(theta) + y_i * sin(theta))**2) }
The _params attribute contains the parameters in the following order:
dist, theta
A minimum number of 2 points is required to solve for the parameters.
Estimate line model from data using total least squares.
| Parameters : | data : (N, 2) array
|
|---|
Predict x-coordinates using the estimated model.
| Parameters : | y : array
params : (2, ) array, optional
|
|---|---|
| Returns : | x : array
|
Predict y-coordinates using the estimated model.
| Parameters : | x : array
params : (2, ) array, optional
|
|---|---|
| Returns : | y : array
|
Determine residuals of data to model.
For each point the shortest distance to the line is returned.
| Parameters : | data : (N, 2) array
|
|---|---|
| Returns : | residuals : (N, ) array
|
| skimage.measure.approximate_polygon(coords, ...) | Approximate a polygonal chain with the specified tolerance. |
| skimage.measure.find_contours(array, level) | Find iso-valued contours in a 2D array for a given level value. |
| skimage.measure.perimeter(image[, neighbourhood]) | Calculate total perimeter of all objects in binary image. |
| skimage.measure.ransac(data, model_class, ...) | Fit a model to data with the RANSAC (random sample consensus) algorithm. |
| skimage.measure.regionprops(label_image[, ...]) | Measure properties of labelled image regions. |
| skimage.measure.structural_similarity(X, Y) | Compute the mean structural similarity index between two images. |
| skimage.measure.subdivide_polygon(coords[, ...]) | Subdivision of polygonal curves using B-Splines. |
Approximate a polygonal chain with the specified tolerance.
It is based on the Douglas-Peucker algorithm.
Note that the approximated polygon is always within the convex hull of the original polygon.
| Parameters : | coords : (N, 2) array
tolerance : float
|
|---|---|
| Returns : | coords : (M, 2) array
|
References
| [R121] | http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm |
Find iso-valued contours in a 2D array for a given level value.
Uses the “marching squares” method to compute a the iso-valued contours of the input 2D array for a particular level value. Array values are linearly interpolated to provide better precision for the output contours.
| Parameters : | array : 2D ndarray of double
level : float
fully_connected : str, {‘low’, ‘high’}
positive_orientation : either ‘low’ or ‘high’
|
|---|---|
| Returns : | contours : list of (n,2)-ndarrays
|
Notes
The marching squares algorithm is a special case of the marching cubes algorithm [R122]. A simple explanation is available here:
http://www.essi.fr/~lingrand/MarchingCubes/algo.html
There is a single ambiguous case in the marching squares algorithm: when a given 2 x 2-element square has two high-valued and two low-valued elements, each pair diagonally adjacent. (Where high- and low-valued is with respect to the contour value sought.) In this case, either the high-valued elements can be ‘connected together’ via a thin isthmus that separates the low-valued elements, or vice-versa. When elements are connected together across a diagonal, they are considered ‘fully connected’ (also known as ‘face+vertex-connected’ or ‘8-connected’). Only high-valued or low-valued elements can be fully-connected, the other set will be considered as ‘face-connected’ or ‘4-connected’. By default, low-valued elements are considered fully-connected; this can be altered with the ‘fully_connected’ parameter.
Output contours are not guaranteed to be closed: contours which intersect the array edge will be left open. All other contours will be closed. (The closed-ness of a contours can be tested by checking whether the beginning point is the same as the end point.)
Contours are oriented. By default, array values lower than the contour value are to the left of the contour and values greater than the contour value are to the right. This means that contours will wind counter-clockwise (i.e. in ‘positive orientation’) around islands of low-valued pixels. This behavior can be altered with the ‘positive_orientation’ parameter.
The order of the contours in the output list is determined by the position of the smallest x,y (in lexicographical order) coordinate in the contour. This is a side-effect of how the input array is traversed, but can be relied upon.
Warning
Array coordinates/values are assumed to refer to the center of the array element. Take a simple example input: [0, 1]. The interpolated position of 0.5 in this array is midway between the 0-element (at x=0) and the 1-element (at x=1), and thus would fall at x=0.5.
This means that to find reasonable contours, it is best to find contours midway between the expected “light” and “dark” values. In particular, given a binarized array, do not choose to find contours at the low or high value of the array. This will often yield degenerate contours, especially around structures that are a single array element wide. Instead choose a middle value, as above.
References
| [R122] | (1, 2) Lorensen, William and Harvey E. Cline. Marching Cubes: A High Resolution 3D Surface Construction Algorithm. Computer Graphics (SIGGRAPH 87 Proceedings) 21(4) July 1987, p. 163-170). |
Examples
>>> a = np.zeros((3, 3))
>>> a[0, 0] = 1
>>> a
array([[ 1., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
>>> find_contours(a, 0.5)
[array([[ 0. , 0.5],
[ 0.5, 0. ]])]
Calculate total perimeter of all objects in binary image.
| Parameters : | image : array
neighbourhood : 4 or 8, optional
|
|---|---|
| Returns : | perimeter : float
|
References
| [R123] | K. Benkrid, D. Crookes. Design and FPGA Implementation of a Perimeter Estimator. The Queen’s University of Belfast. http://www.cs.qub.ac.uk/~d.crookes/webpubs/papers/perimeter.doc |
Fit a model to data with the RANSAC (random sample consensus) algorithm.
RANSAC is an iterative algorithm for the robust estimation of parameters from a subset of inliers from the complete data set. Each iteration performs the following tasks:
These steps are performed either a maximum number of times or until one of the special stop criteria are met. The final model is estimated using all inlier samples of the previously determined best model.
| Parameters : | data : [list, tuple of] (N, D) array
model_class : object
min_samples : int
residual_threshold : float
is_data_valid : function, optional
is_model_valid : function, optional
max_trials : int, optional
stop_sample_num : int, optional
stop_residuals_sum : float, optional
|
|---|---|
| Returns : | model : object
inliers : (N, ) array
|
References
| [R124] | “RANSAC”, Wikipedia, http://en.wikipedia.org/wiki/RANSAC |
Examples
Generate ellipse data without tilt and add noise:
>>> t = np.linspace(0, 2 * np.pi, 50)
>>> a = 5
>>> b = 10
>>> xc = 20
>>> yc = 30
>>> x = xc + a * np.cos(t)
>>> y = yc + b * np.sin(t)
>>> data = np.column_stack([x, y])
>>> np.random.seed(seed=1234)
>>> data += np.random.normal(size=data.shape)
Add some faulty data:
>>> data[0] = (100, 100)
>>> data[1] = (110, 120)
>>> data[2] = (120, 130)
>>> data[3] = (140, 130)
Estimate ellipse model using all available data:
>>> model = EllipseModel()
>>> model.estimate(data)
>>> model._params
array([ 4.85808595e+02, 4.51492793e+02, 1.15018491e+03,
5.52428289e+00, 7.32420126e-01])
Estimate ellipse model using RANSAC:
>>> ransac_model, inliers = ransac(data, EllipseModel, 5, 3, max_trials=50)
>>> # ransac_model._params, inliers
Should give the correct result estimated without the faulty data:
[ 20.12762373, 29.73563061, 4.81499637, 10.4743584, 0.05217117] [ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
Robustly estimate geometric transformation:
>>> from skimage.transform import SimilarityTransform
>>> src = 100 * np.random.random((50, 2))
>>> model0 = SimilarityTransform(scale=0.5, rotation=1,
... translation=(10, 20))
>>> dst = model0(src)
>>> dst[0] = (10000, 10000)
>>> dst[1] = (-100, 100)
>>> dst[2] = (50, 50)
>>> model, inliers = ransac((src, dst), SimilarityTransform, 2, 10)
>>> inliers
array([ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])
Measure properties of labelled image regions.
| Parameters : | label_image : (N, M) ndarray
properties : {‘all’, list}
intensity_image : (N, M) ndarray, optional
|
|---|---|
| Returns : | properties : list of dicts
|
References
| [R125] | Wilhelm Burger, Mark Burge. Principles of Digital Image Processing: Core Algorithms. Springer-Verlag, London, 2009. |
| [R126] | B. Jähne. Digital Image Processing. Springer-Verlag, Berlin-Heidelberg, 6. edition, 2005. |
| [R127] | T. H. Reiss. Recognizing Planar Objects Using Invariant Image Features, from Lecture notes in computer science, p. 676. Springer, Berlin, 1993. |
| [R128] | http://en.wikipedia.org/wiki/Image_moment |
Examples
>>> from skimage.data import coins
>>> from skimage.morphology import label
>>> img = coins() > 110
>>> label_img = label(img)
>>> props = regionprops(label_img)
>>> props[0]['Centroid'] # centroid of first labelled object
Compute the mean structural similarity index between two images.
| Parameters : | X, Y : (N,N) ndarray
win_size : int
gradient : bool
dynamic_range : int
|
|---|---|
| Returns : | s : float
grad : (N * N,) ndarray
|
References
| [R129] | Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing, 13, 600-612. |
Subdivision of polygonal curves using B-Splines.
Note that the resulting curve is always within the convex hull of the original polygon. Circular polygons stay closed after subdivision.
| Parameters : | coords : (N, 2) array
degree : {1, 2, 3, 4, 5, 6, 7}, optional
preserve_ends : bool, optional
|
|---|---|
| Returns : | coords : (M, 2) array
|
References
| [R130] | http://mrl.nyu.edu/publications/subdiv-course2000/coursenotes00.pdf |