https://github.com/raphaelreme/tps

Implementation of ThinPlateSpline

https://github.com/raphaelreme/tps

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.5%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Implementation of ThinPlateSpline

Basic Info
  • Host: GitHub
  • Owner: raphaelreme
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 407 KB
Statistics
  • Stars: 29
  • Watchers: 1
  • Forks: 4
  • Open Issues: 0
  • Releases: 0
Created over 4 years ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

Thin Plate Spline (TPS)

Lint and Test

Python (NumPy & SciPy) implementation of the generalized Polyharmonic Spline interpolation (also known as Thin Plate Spline in 2D). It learns a smooth elastic mapping between two Euclidean spaces with support for:

  • Arbitrary input and output dimensions
  • Arbitrary spline order k
  • Optional regularization

Useful for interpolation, deformation fields, and smooth non-linear regression.

For a faster implementation in PyTorch, see torch-tps.

🚀 Install

Pip

bash $ pip install thin-plate-spline

Getting started

```python import numpy as np from tps import ThinPlateSpline

Control points

Xtrain = np.random.normal(0, 1, (800, 3)) # 800 points in R^3 Ytrain = np.random.normal(0, 1, (800, 2)) # Values for each point (800 values in R^2)

New source points to interpolate

X_test = np.random.normal(0, 1, (300 0, 3))

Initialize spline model (Regularization is controled with alpha parameter)

tps = ThinPlateSpline(alpha=0.5)

Fit spline from control points

tps.fit(Xtrain, Ytrain)

Interpolate new points

Ytest = tps.transform(Xtest) ```

Examples

See the example/ folder for scripts showing:

  • Interpolation in 1D, 2D, 3D
  • Arbitrary input and output dimensions
  • Image warping with elastic deformation

Image Warping

Example of increasing/decreasing/randomly deforming a dog's face using sparse control points.

Original Increased Decreased Random

Code: example/image_warping.py

🧠 Theory Summary

The model solves the regularized interpolation problem:

$$ minf \sum{i=1}^n (yi - f(xi))^2 + \int |\nabla^{\text{order}} f|_2^2 dx $$

With solution:

$$ f(x) = P(x) + \sum{i=1}^n wi G(|x - xi|2) $$

Where:

  • $G(r)$: radial basis function (RBF) (depends on order and the input dimension d)
  • $P(x)$: a polynomial of degree order - 1

Default kernel (TPS): - $G(r) = r^2 \log(r)$

General kernel: - $G(r) = r^{(2 \text{order} - d)} \text{ if d is odd}$ - $G(r) = r^{(2\text{order} - d)} \log(r) \text{ otherwise}$

🔧 API

ThinPlateSpline(alpha=0.0, order=2, enforce_tps_kernel=False)

Creates a general polyharmonic spline interpolator (Default to TPS in 2D and natural cubic splines in 1D).

  • alpha (float): Regularization strength (default 0.0)
  • order (int): Spline order (default is 2 for TPS)
  • enforcetpskernel (bool): Force TPS kernel r^2 log r, even when mathematically suboptimal

.fit(X, Y)

Fits the model to control point pairs.

  • X: (n, d) input coordinates
  • Y: (n, v) target coordinates

Returns: self

.transform(X)

Applies the learned mapping to new input points.

  • X: (n', d) points

Returns: (n', v) interpolated values

Development

bash git clone https://github.com/raphaelreme/tps.git cd tps pip install -e .

License

MIT License

Owner

  • Login: raphaelreme
  • Kind: user

GitHub Events

Total
  • Watch event: 8
  • Push event: 8
  • Create event: 1
Last Year
  • Watch event: 8
  • Push event: 8
  • Create event: 1

Committers

Last synced: almost 2 years ago

All Time
  • Total Commits: 16
  • Total Committers: 3
  • Avg Commits per committer: 5.333
  • Development Distribution Score (DDS): 0.25
Past Year
  • Commits: 6
  • Committers: 2
  • Avg Commits per committer: 3.0
  • Development Distribution Score (DDS): 0.167
Top Committers
Name Email Commits
Raphael Reme r****e@p****m 12
Raphael Reme r****e@t****r 3
Dženan Zukić d****c@k****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 4
  • Total pull requests: 1
  • Average time to close issues: 2 months
  • Average time to close pull requests: about 4 hours
  • Total issue authors: 3
  • Total pull request authors: 1
  • Average comments per issue: 4.5
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: 25 days
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 6.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • frehburg (2)
  • JoSchmaltz (1)
  • Koushouu (1)
Pull Request Authors
  • dzenanz (2)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 647 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 7
  • Total maintainers: 1
pypi.org: thin-plate-spline

Thin Plate Spline and Polyharmonic Spline implementation with numpy/scipy

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 647 Last month
Rankings
Dependent packages count: 10.1%
Downloads: 15.0%
Average: 17.9%
Stargazers count: 20.4%
Dependent repos count: 21.5%
Forks count: 22.6%
Maintainers (1)
Last synced: 11 months ago

Dependencies

requirements-dev.txt pypi
  • black * development
  • build * development
  • matplotlib * development
  • mypy * development
  • pylint * development
  • tqdm * development
  • twine * development
.github/workflows/deploy.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • pypa/gh-action-pypi-publish 27b31702a0e7fc50959f5ad993c78deac1bdfc29 composite
.github/workflows/tests.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
pyproject.toml pypi
setup.py pypi