Package: nudged
A Python lib to estimate scale, rotation, and translation between two sets of 2D points. Applicable for example in cases where one wants to move objects by multiple fingers or where a large number of points from an eye tracker device are wanted to be corrected based on a few calibration points. In general, you can apply nudged in any situation where you want to move a number of points based on a few sample points.Mathematically speaking, nudged is an optimal least squares estimator foraffine transformation matriceswith uniform scaling, rotation, and translation and without reflection or shearing. The estimation has time complexity of O(n) that consists of6n+22multiplications and11n+19additions, wherenis the cardinality (size) of the point sets. In other words, nudged solves an affine 2D to 2D point set registration problem in linear time.Available alsoin JavaScript.Install$ pip install nudgedUsageYou have lists of points for thedomainandrangeof the tranformation function to be estimated:dom = [[0,0], [2,0], [ 1,2]]
ran  = [[1,1], [1,3], [-1,2]]Compute optimal tranformation based on the points:trans = nudged.estimate(dom, ran);Apply the transformation to other points:trans.transform([2,2])
# [-1,3]To explore the estimated transformation, you can:trans.get_matrix()
# [[0,-1, 1],
#  [1, 0, 1],
#  [0, 0, 1]]

trans.get_rotation()
# 1.5707... = π / 2   (radians)

trans.get_scale()
# 1.0

trans.get_translation()
# [1, 1]APInudged.estimate(domain, range)Parametersdomain: list of [x,y] pointsrange: list of [x,y] pointsThedomainandrangeshould have equal length. Different lengths are allowed but additional points in the longer list are ignored.Returna newnudged.Transform(…)instance.nudged.estimate_error(transform, domain, range)Compute mean squared distance between the point pairs of the domain after the given transformation and the range. If the transform was estimated with the given domain and range, then the result is the mean squared error (MSE) of the estimation.Parameterstransform: anudged.Transforminstancedomain: list of [x,y] pointsrange: list of [x,y] pointsReturna float, the mean squared distance between the range and transformed domain point pairs.Usage example:dom = [[0, 0], [1, 1], [2, 2]]
ran = [[0,-1], [1, 2], [2,-1]]
t = nudged.estimate(dom, ran)
mse = nudged.estimate_error(t, dom, ran)
# mse == 2.0nudged.versionContains the module version string equal to the version insetup.py.nudged.Transform(s, r, tx, ty)An instance returned by thenudged.estimate(…).In addition to the methods below, it has attributess,r,tx,tythat define theaugmented transformation matrix:|s  -r  tx|
|r   s  ty|
|0   0   1|nudged.Transform#transform(points)Returnan list of transformed points or single point if only a point was given. For example:trans.transform([1,1])           # [2,2]
trans.transform([[1,1]])         # [[2,2]]
trans.transform([[1,1], [2,3]])  # [[2,2], [3,4]]nudged.Transform#get_matrix()Returnan 3x3 augmented transformation matrix in the following list format:[[s,-r, tx],
 [r, s, ty],
 [0, 0,  1]]nudged.Transform#get_rotation()Returnrotation in radians.nudged.Transform#get_scale()Returnscaling multiplier, e.g.0.333for a threefold shrink.nudged.Transform#get_translation()Return[tx, ty]wheretxandtydenotes movement along x-axis and y-axis accordingly.For developersFollowinstructions to install pyenv<http://sqa.stackexchange.com/a/15257/14918>`_ and then either run quick tests:$ python2.7 setup.py testor comprehensive tests for multiple Python versions intox.ini:$ eval "$(pyenv init -)"
$ pyenv rehash
$ toxVersioningSemantic Versioning 2.0.0LicenseMIT License