Quantify the similarity between two shapes/curves
Project description
SHAPE SIMILARITY
:bulb: About
The package allows you to check the similarity between two shapes/curves, using Frechet distance together with Procrustes analysis.
Internally, shape_similarity
works by first normalizing the curves using Procrustes analysis and then calculating Fréchet distance between the curves.
:page_facing_up: Content
-
Frechet Distance
- In mathematics, the Fréchet distance is a measure of similarity between curves that takes into account the location and ordering of the points along the curves. Imagine a person traversing a finite curved path while walking their dog on a leash, with the dog traversing a separate finite curved path. Each can vary their speed to keep slack in the leash, but neither can move backwards. The Fréchet distance between the two curves is the length of the shortest leash sufficient for both to traverse their separate paths from start to finish. Note that the definition is symmetric with respect to the two curves—the Fréchet distance would be the same if the dog were walking its owner.
-
Procrustes Analysis
- In statistics, Procrustes analysis is a form of statistical shape analysis used to analyse the distribution of a set of shapes. To compare the shapes of two or more objects, the objects must be first optimally "superimposed". Procrustes superimposition (PS) is performed by optimally translating, rotating and uniformly scaling the objects. In other words, both the placement in space and the size of the objects are freely adjusted. The aim is to obtain a similar placement and size, by minimizing a measure of shape difference called the Procrustes distance between the objects.
:rocket: Technologies
:package: Installation
- Install with pip
$ pip3 install shapesimilarity
- Install from source
$ git clone https://github.com/nelsonwenner/shape-similarity.git
$ pip3 install ./shape-similarity
:information_source: Example useage
from shapesimilarity import shape_similarity
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(1, -1, num=200)
y1 = 2*x**2 + 1
y2 = 2*x**2 + 2
shape1 = np.column_stack((x, y1))
shape2 = np.column_stack((x, y2))
similarity = shape_similarity(shape1, shape2)
plt.plot(shape1[:,0], shape1[:,1], linewidth=2.0)
plt.plot(shape2[:,0], shape2[:,1], linewidth=2.0)
plt.title(f'Shape similarity is: {similarity}', fontsize=14, fontweight='bold')
plt.show()
- You can further customize the precision of the shape_similarity function by changing the rotation (default 10). Increasing it will increase accuracy. You can also disable rotation correction completely (default True).
# disable rotation correction entirely shape_similarity(shape1, shape2, checkRotation=False) # higher accuracy, but slower shape_similarity(shape1, shape2, rotation=30)
:chart_with_downwards_trend: Results
:pushpin: Referencies
Made with :hearts: by Nelson Wenner :wave: Get in touch!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
shapesimilarity-0.0.1.tar.gz
(5.3 kB
view details)
Built Distribution
File details
Details for the file shapesimilarity-0.0.1.tar.gz
.
File metadata
- Download URL: shapesimilarity-0.0.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2168c6d129c5b216e02ddad795e508834613dd3fdd518e06ed9555bcd6007be |
|
MD5 | 85a24e53583b1c7cb05e4f1c8df68fff |
|
BLAKE2b-256 | 75ff7e0a8b5ced9b5fac83c124cfab971df46993995b324a2aba20fbfacca8a0 |
File details
Details for the file shapesimilarity-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: shapesimilarity-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9d324bf0b097dbc5a5458612a2ddb574dc623b2317f83ae97ad68bb0824d56c |
|
MD5 | e8a6a4e7a878ab3d190ba877c458cfc3 |
|
BLAKE2b-256 | acf2374d9003ff7ff9fb6f825f68e0898d601d3c7ba4713673ae500fed823903 |