Skip to main content

SHAPE SIMILARITY

Workflow Codecov

: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

  1. Install with pip
$ python -m pip install shapesimilarity
  1. Install from source code
$ git clone https://github.com/nelsonwenner/shape-similarity.git

$ python -m pip install .
  1. Run the tests
$ python -m pip install pytest

$ python -m pytest

: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

plot1 plot2

:pushpin: Referencies


Made with :hearts: by Nelson Wenner :wave: Get in touch!

Metadata

Release files for shapesimilarity 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shapesimilarity 1.0.0
File Size Uploaded Provenance Actions
shapesimilarity-1.0.0.tar.gz 5.4 kB Without provenance Details for shapesimilarity-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shapesimilarity 1.0.0
File Interpreter ABI Platform Actions
shapesimilarity-1.0.0-py3-none-any.whl Python 3 none any Details for shapesimilarity-1.0.0-py3-none-any.whl

Total release size: 12.0 kB

Release files / shapesimilarity-1.0.0.tar.gz

Download URL shapesimilarity-1.0.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d83cc610219bbdd353b9d1f3df9768f6aa499742d29cbe67335ee4e781dbb563
BLAKE2b-256 checksum
How to use checksums
486a8c127ab1ddedbc6b5af2cd072dbfe95460d2785d76c113006d5bbfa861b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release files / shapesimilarity-1.0.0-py3-none-any.whl

Download URL shapesimilarity-1.0.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28f70c1142a2c05a45e2e2e365f687574b3cadbaf1160942e2b1f75e147b52f6
BLAKE2b-256 checksum
How to use checksums
28b6a2008a04bd485d460d2db40bcd48f64ff354a0f27aa6dffb7dafaab51bbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Security for shapesimilarity 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page