Skip to main content

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.

Example transformation

Mathematically speaking, nudged is an optimal least squares estimator for affine transformation matrices with uniform scaling, rotation, and translation and without reflection or shearing. The estimation has time complexity of O(n) that consists of 6n+22 multiplications and 11n+19 additions, where n is the cardinality (size) of the point sets. In other words, nudged solves an affine 2D to 2D point set registration problem in linear time.

Install

$ pip install nudged

Usage

You have lists of points for the domain and range of 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]

API

nudged.estimate(dom, ran)

Parameters

  • dom: domain, list of [x,y] points

  • ran: range, list of [x,y] points

The dom and ran should have equal length. Different lengths are allowed but additional points in the longer list are ignored in the estimation.

Return a new nudged.Transform(…) instance.

nudged.version

Contains the module version string equal to the version in setup.py.

nudged.Transform(s, r, tx, ty)

An instance returned by the nudged.estimate(…).

In addition to the methods below, it has attributes s, r, tx, ty that define the augmented transformation matrix:

|s  -r  tx|
|r   s  ty|
|0   0   1|

nudged.Transform#transform(points)

Return an 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()

Return an 3x3 augmented transformation matrix in the following list format:

[[s,-r, tx],
 [r, s, ty],
 [0, 0,  1]]

nudged.Transform#get_rotation()

Return rotation in radians.

nudged.Transform#get_scale()

Return scaling multiplier, e.g. 0.333 for a threefold shrink.

nudged.Transform#get_translation()

Return [tx, ty] where tx and ty denotes movement along x-axis and y-axis accordingly.

For developers

Follow instructions to install pyenv <http://sqa.stackexchange.com/a/15257/14918>`_ and then either run quick tests:

$ python2.7 setup.py test

or comprehensive tests for multiple Python versions in tox.ini:

$ eval "$(pyenv init -)"
$ pyenv rehash
$ tox

Versioning

Semantic Versioning 2.0.0

License

MIT License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nudged-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nudged-0.2.0-py2.py3-none-any.whl (7.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file nudged-0.2.0.tar.gz.

File metadata

  • Download URL: nudged-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for nudged-0.2.0.tar.gz
Algorithm Hash digest
SHA256 09a42b62276bb7e22945a39a186051ce34a872c3d31fbf21d8f3ece47bf4cf8b
MD5 133fe0af771590c5e39586b9966278f2
BLAKE2b-256 4a6c4f9052d31975dd99f66ca4d1bb2b29e24bbe128bfc0481bfd8eea190386e

See more details on using hashes here.

File details

Details for the file nudged-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for nudged-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a681fde12c306be66ebc32a12dcc57c13f9dc71a359b93b2209b1f5babec79a3
MD5 e3f770609f8b2d6049661412f2463725
BLAKE2b-256 8fea8a89e5d29d294ff3b194791566b9865ab833671f63dd9492f29162467bf7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page